bharath_pulse / bharatpulse.py
charantejapolavarapu's picture
Upload bharatpulse.py
f0d39f8 verified
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}")