File size: 2,138 Bytes
f0d39f8 | 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 | import streamlit as st
import feedparser
from transformers import pipeline
st.set_page_config(page_title="๐ฎ๐ณ BharatPulse", layout="wide")
# Load summarizer
@st.cache_resource
def load_summarizer():
return pipeline("summarization", model="facebook/bart-large-cnn")
summarizer = load_summarizer()
# News source
NEWS_FEEDS = {
"NDTV": "https://feeds.feedburner.com/ndtvnews-top-stories",
"India Today": "https://www.indiatoday.in/rss/home",
"The Hindu": "https://www.thehindu.com/news/national/feeder/default.rss"
}
# Title
st.title("๐ฎ๐ณ BharatPulse")
st.subheader("Live News Feeds & Public Sentiment Collector (MVP)")
# News source selection
source = st.selectbox("๐ฐ Choose News Source", list(NEWS_FEEDS.keys()))
feed = feedparser.parse(NEWS_FEEDS[source])
st.markdown("### ๐๏ธ Latest News Headlines from India")
for entry in feed.entries[:5]:
st.write(f"**๐๏ธ {entry.title}**")
st.write(entry.published)
st.markdown(f"[Read more]({entry.link})", unsafe_allow_html=True)
if st.button(f"๐ Summarize: {entry.title}"):
with st.spinner("Summarizing..."):
summary = summarizer(entry.summary[:1024], max_length=100, min_length=30, do_sample=False)[0]['summary_text']
st.success(summary)
st.markdown("---")
# Public Sentiment Collector
st.markdown("## ๐ฃ Share Your Voice โ Public Sentiment Collector")
with st.form("sentiment_form"):
name = st.text_input("Your Name (Optional)", "")
region = st.text_input("Your Region / State")
language = st.text_input("Language")
topic = st.text_input("Topic")
sentiment = st.radio("Sentiment", ["Positive", "Negative", "Neutral"])
message = st.text_area("Your Message (in your local language or English)")
submitted = st.form_submit_button("Submit")
if submitted:
st.success("โ
Thank you for sharing your opinion!")
st.markdown(f"**Name:** {name or 'Anonymous'}")
st.markdown(f"**Region:** {region}, **Language:** {language}, **Topic:** {topic}")
st.markdown(f"**Sentiment:** {sentiment}")
st.markdown(f"**Message:** {message}")
|