Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from utils import fetch_news, analyze_sentiment, summarize_text, generate_hindi_tts
|
| 3 |
+
|
| 4 |
+
st.title("News Summarization and Sentiment Analysis")
|
| 5 |
+
|
| 6 |
+
# Input company name
|
| 7 |
+
company_name = st.text_input("Enter Company Name (e.g., Tesla)", "Tesla")
|
| 8 |
+
|
| 9 |
+
if st.button("Analyze"):
|
| 10 |
+
# Fetch news
|
| 11 |
+
articles = fetch_news(company_name)
|
| 12 |
+
|
| 13 |
+
if articles:
|
| 14 |
+
st.write(f"Found {len(articles)} articles for {company_name}")
|
| 15 |
+
report = {"Company": company_name, "Articles": [], "Comparative Sentiment Score": {"Sentiment Distribution": {"Positive": 0, "Negative": 0, "Neutral": 0}}}
|
| 16 |
+
|
| 17 |
+
# Process each article
|
| 18 |
+
for article in articles[:10]: # Limit to 10 articles
|
| 19 |
+
summary = summarize_text(article['content'])
|
| 20 |
+
sentiment = analyze_sentiment(article['content'])
|
| 21 |
+
topics = ["Business"] # Placeholder
|
| 22 |
+
|
| 23 |
+
report["Articles"].append({
|
| 24 |
+
"Title": article['title'],
|
| 25 |
+
"Summary": summary,
|
| 26 |
+
"Sentiment": sentiment,
|
| 27 |
+
"Topics": topics
|
| 28 |
+
})
|
| 29 |
+
report["Comparative Sentiment Score"]["Sentiment Distribution"][sentiment] += 1
|
| 30 |
+
|
| 31 |
+
# Comparative Analysis (simplified)
|
| 32 |
+
comparative = f"Positive articles focus on growth, while negative ones highlight challenges."
|
| 33 |
+
report["Comparative Analysis"] = comparative
|
| 34 |
+
|
| 35 |
+
# Display report
|
| 36 |
+
st.json(report)
|
| 37 |
+
|
| 38 |
+
# Generate and play Hindi TTS
|
| 39 |
+
hindi_summary = f"{company_name} की खबरों का सारांश: सकारात्मक {report['Comparative Sentiment Score']['Sentiment Distribution']['Positive']}, नकारात्मक {report['Comparative Sentiment Score']['Sentiment Distribution']['Negative']}।"
|
| 40 |
+
audio_file = generate_hindi_tts(hindi_summary)
|
| 41 |
+
st.audio(audio_file, format="audio/wav")
|
| 42 |
+
|
| 43 |
+
else:
|
| 44 |
+
st.error("No articles found!")
|