privateuserh's picture
Update app.py
2562201 verified
raw
history blame
4.14 kB
import requests
import feedparser
import gradio as gr
# Define the RSS feed URLs
news_sources = {
"SM+": "https://fetchrss.com/rss/67bca52dda01b8237d0cd46367bca4e995760c5c55080de2.rss",
"Ad Visit •Assetmart• on Telegram": "http://bit.ly/4hTmAG",
"ABP News": "https://www.abplive.com/home/feed",
"Business Line": "https://www.thehindubusinessline.com/feeder/default.rss",
"Climate Change ✴️ Breaking News": "https://www.google.com/search?q=climate+change+news+worldwide&client=ms-android-verizon-us-rvc3&sca_esv=e28d900fdc0c3e2f&sxsrf=AHTn8zqjZTf3pF1dHJtmRPhA1sZDhtstvw%3A1740433635959&ei=4-i8Z_SgOoHQkPIPj6vtgAI&oq=Climate+Change+News&gs_lp=EhNtb2JpbGUtZ3dzLXdpei1zZXJwIhNDbGltYXRlIENoYW5nZSBOZXdzKgIIBDIQEAAYgAQYsQMYgwEYFBiHAjIFEAAYgAQyBRAAGIAEMgUQABiABDIFEAAYgAQyBRAAGIAEMgUQABiABDIFEAAYgARIi2BQ9gpY0zpwAXgCkAECmAGjAaABkRmqAQQwLjI1uAEByAEA-AEBmAIVoALfFKgCD8ICBBAAGEfCAgcQIxgnGOoCwgIEECMYJ8ICChAjGIAEGCcYigXCAg4QLhiABBixAxjRAxjHAcICDhAAGIAEGLEDGIMBGIoFwgIIEAAYgAQYsQPCAhEQLhiABBixAxjRAxiDARjHAcICCxAuGIAEGLEDGIMBwgIKEAAYgAQYQxiKBcICEBAuGIAEGNEDGEMYxwEYigXCAgUQLhiABMICDRAAGIAEGLEDGEMYigXCAgoQABiABBgUGIcCwgINEC4YgAQYsQMYQxiKBcICFhAuGIAEGLEDGNEDGEMYgwEYxwEYigXCAg4QLhiABBixAxiDARiKBcICEBAAGIAEGLEDGEMYyQMYigXCAgsQABiABBixAxiDAcICCBAuGIAEGLEDwgILEAAYgAQYkgMYigXCAg4QLhiABBixAxjHARivAcICExAuGIAEGLEDGBQYhwIYxwEYrwHCAggQABiABBjJA5gDEPEF13R2NyqW95iIBgGQBgiSBwQyLjE5oAep0wE&sclient=mobile-gws-wiz-serp",
"Deccan Chronicle": "https://www.deccanchronicle.com/google_feeds.xml",
"Ad ebay 🛍️ Shop deals SS/25": "http://fetchrss.com/rss/67bca52dda01b8237d0cd46367bce3f0b8382c6fdd0fc575.xml",
"Surfing 🌊 Google News": "http://fetchrss.com/rss/67bca52dda01b8237d0cd46367bce863c789cad48e0a7922.xml",
"Gujarati- Gujarat Samachar": "https://www.gujaratsamachar.com/rss/top-stories",
"Hindustan Times": "https://www.hindustantimes.com/feeds/rss/latest/rssfeed.xml",
"India Today": "https://www.indiatoday.in/rss/home",
"Indian Express": "https://indianexpress.com/section/india/feed",
"Live Mint": "https://www.livemint.com/rss/news",
"Money Control": "https://www.moneycontrol.com/rss/latestnews.xml",
"Manorama - English": "https://www.onmanorama.com/kerala.feeds.onmrss.xml",
"NDTV": "https://feeds.feedburner.com/NDTV-LatestNews",
"News 18": "https://www.news18.com/commonfeeds/v1/eng/rss/india.xml",
"Telangana Today": "https://telanganatoday.com/feed",
"The Federal": "https://thefederal.com/feeds.xml",
"The Federal Andhra": "https://andhrapradesh.thefederal.com/feeds.xml",
"The Federal Desh": "https://desh.thefederal.com/feeds.xml",
"The Federal Karnataka": "https://karnataka.thefederal.com/feeds.xml",
"The Federal Telangana": "https://telangana.thefederal.com/feeds.xml",
"The Hindu": "https://www.thehindu.com/feeder/default.rss",
"Times of India": "https://timesofindia.indiatimes.com/rssfeedmostrecent.cms"
}
# Function to fetch and parse RSS feeds
def fetch_news(source):
try:
feed = feedparser.parse(requests.get(source).content)
news_items = [
f"<a href='{entry.link}' target='_blank'>{entry.title}</a>"
for entry in feed.entries[:10] # Fetch top 10 headlines
]
return "<br><br>".join(news_items) if news_items else "No news available."
except Exception as e:
return f"Error fetching news: {str(e)}"
# Gradio interface function
def display_news(selected_source):
source_url = news_sources[selected_source]
headlines = fetch_news(source_url)
return headlines
# Create Gradio interface
def create_interface():
interface = gr.Interface(
fn=display_news,
inputs=gr.Dropdown(choices=list(news_sources.keys()), label="Select News Source"),
outputs=gr.HTML(label="Top Headlines"),
title="LIVE News / feeds",
description="Select a news source from the dropdown to view its latest headlines with clickable links. SM+ may receive earnings/commissions from affiliate links"
)
return interface
# Deploy Gradio app
if __name__ == "__main__":
app = create_interface()
app.launch()