charantejapolavarapu commited on
Commit
f0d39f8
ยท
verified ยท
1 Parent(s): 58cb40d

Upload bharatpulse.py

Browse files
Files changed (1) hide show
  1. bharatpulse.py +56 -0
bharatpulse.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import feedparser
3
+ from transformers import pipeline
4
+
5
+ st.set_page_config(page_title="๐Ÿ‡ฎ๐Ÿ‡ณ BharatPulse", layout="wide")
6
+
7
+ # Load summarizer
8
+ @st.cache_resource
9
+ def load_summarizer():
10
+ return pipeline("summarization", model="facebook/bart-large-cnn")
11
+
12
+ summarizer = load_summarizer()
13
+
14
+ # News source
15
+ NEWS_FEEDS = {
16
+ "NDTV": "https://feeds.feedburner.com/ndtvnews-top-stories",
17
+ "India Today": "https://www.indiatoday.in/rss/home",
18
+ "The Hindu": "https://www.thehindu.com/news/national/feeder/default.rss"
19
+ }
20
+
21
+ # Title
22
+ st.title("๐Ÿ‡ฎ๐Ÿ‡ณ BharatPulse")
23
+ st.subheader("Live News Feeds & Public Sentiment Collector (MVP)")
24
+
25
+ # News source selection
26
+ source = st.selectbox("๐Ÿ“ฐ Choose News Source", list(NEWS_FEEDS.keys()))
27
+ feed = feedparser.parse(NEWS_FEEDS[source])
28
+
29
+ st.markdown("### ๐Ÿ—ž๏ธ Latest News Headlines from India")
30
+ for entry in feed.entries[:5]:
31
+ st.write(f"**๐Ÿ—ž๏ธ {entry.title}**")
32
+ st.write(entry.published)
33
+ st.markdown(f"[Read more]({entry.link})", unsafe_allow_html=True)
34
+ if st.button(f"๐Ÿ” Summarize: {entry.title}"):
35
+ with st.spinner("Summarizing..."):
36
+ summary = summarizer(entry.summary[:1024], max_length=100, min_length=30, do_sample=False)[0]['summary_text']
37
+ st.success(summary)
38
+ st.markdown("---")
39
+
40
+ # Public Sentiment Collector
41
+ st.markdown("## ๐Ÿ“ฃ Share Your Voice โ€“ Public Sentiment Collector")
42
+ with st.form("sentiment_form"):
43
+ name = st.text_input("Your Name (Optional)", "")
44
+ region = st.text_input("Your Region / State")
45
+ language = st.text_input("Language")
46
+ topic = st.text_input("Topic")
47
+ sentiment = st.radio("Sentiment", ["Positive", "Negative", "Neutral"])
48
+ message = st.text_area("Your Message (in your local language or English)")
49
+ submitted = st.form_submit_button("Submit")
50
+
51
+ if submitted:
52
+ st.success("โœ… Thank you for sharing your opinion!")
53
+ st.markdown(f"**Name:** {name or 'Anonymous'}")
54
+ st.markdown(f"**Region:** {region}, **Language:** {language}, **Topic:** {topic}")
55
+ st.markdown(f"**Sentiment:** {sentiment}")
56
+ st.markdown(f"**Message:** {message}")