Spaces:
Sleeping
Sleeping
File size: 1,798 Bytes
53ecad3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import requests
import feedparser
import gradio as gr
# Define the RSS feed URLs
news_sources = {
"Times of India": "https://timesofindia.indiatimes.com/rssfeedmostrecent.cms",
"The Hindu": "https://www.thehindu.com/feeder/default.rss",
"Live Mint": "https://www.livemint.com/rss/news",
"Business Standard": "https://www.business-standard.com/rss/latest.rss",
"Indian Express": "https://indianexpress.com/print/front-page/feed/",
"Money Control": "https://www.moneycontrol.com/rss/latestnews.xml",
"Hindustan Times": "https://www.hindustantimes.com/feeds/rss/latest/rssfeed.xml",
"Business Line": "https://www.thehindubusinessline.com/feeder/default.rss"
}
# Function to fetch and parse RSS feeds
def fetch_news(source):
try:
feed = feedparser.parse(requests.get(source).content)
news_items = [
f"{entry.title}: {entry.link}"
for entry in feed.entries[:10] # Fetch top 10 headlines
]
return "\n\n".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.Textbox(label="Top Headlines"),
title="Top News from Peer Sites",
description="Select a news source from the dropdown to view its latest headlines."
)
return interface
# Deploy Gradio app
if __name__ == "__main__":
app = create_interface()
app.launch()
|