File size: 2,739 Bytes
53ecad3
 
 
 
 
 
2638d51
081441c
03c2b26
 
3afe2e2
03c2b26
a43d82f
688c6c4
03c2b26
53ecad3
9a4c200
4239df3
 
03c2b26
 
 
 
 
 
 
9f122bf
53ecad3
 
 
 
 
 
a9d8f21
53ecad3
 
a9d8f21
53ecad3
 
 
 
 
 
 
 
 
 
 
 
 
 
a9d8f21
e5f068b
a9d8f21
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
51
52
53
54
55
56
57
58
59
60
61
62
import requests
import feedparser
import gradio as gr

# Define the RSS feed URLs
news_sources = {
    "ABP News": "https://www.abplive.com/home/feed",
    "BBC India": "https://feeds.bbci.co.uk/news/world/asia/india/rss.xml",
    "Business Line": "https://www.thehindubusinessline.com/feeder/default.rss",
    "Deccan Chronicle": "https://www.deccanchronicle.com/google_feeds.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="Latest LIVE News from Peer Sites",
        description="Select a news source from the dropdown to view its latest headlines with clickable links."
    )
    return interface

# Deploy Gradio app
if __name__ == "__main__":
    app = create_interface()
    app.launch()