Spaces:
Sleeping
Sleeping
File size: 2,735 Bytes
c6a6d99 14bf136 c6a6d99 14bf136 c6a6d99 |
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 63 64 65 66 67 68 69 |
import streamlit as st
from news import fetch_news
from utils import get_sentiment, extract_keywords, text_to_speech, comparison_impact, summarize_text
from deep_translator import GoogleTranslator
# Streamlit App Title
st.title("π’ News Sentiment & Keyword Analyzer with Hindi Speech & Comparison")
# User Input for Company Name
company_name = st.text_input("Enter Company Name:",placeholder="Google Tesla Apple etc")
if st.button("Fetch News & Analyze"):
st.write(f"Fetching latest news about **{company_name}**...")
# Fetch News Articles
news_data = fetch_news(company=company_name, limit=10)
if news_data:
sentiment_results = [] # Store Sentiment Results
summarized_text = "" # Combined summary for TTS
previous_article = None # Store the previous article for comparison
for article in news_data:
title = article["title"]
snippet = article["snippet"]
link = article["link"]
# Summarize title + snippet
summary = summarize_text(title + " " + snippet)
# Analyze Sentiment
sentiment = get_sentiment(summary)
# Extract Keywords
keywords = extract_keywords(summary)
keywords_display = ", ".join(keywords) if isinstance(keywords, list) else "No keywords extracted"
# Display Summarized Article with Sentiment and Keywords
st.subheader(title)
st.write(f"π° **Summary:** {summary}")
st.write(f"π [Read More]({link})")
st.write(f"π§ **Sentiment:** {sentiment}")
st.write(f"π **Keywords:** {keywords_display}")
# Compare with previous article
if previous_article:
comparison_result = comparison_impact(previous_article, summary)
st.write("π **Comparison Impact with Previous Article:**")
st.write(comparison_result["Impact Analysis"])
# Store current summary as previous for next iteration
previous_article = summary
sentiment_results.append((title, sentiment))
summarized_text += summary + " " # Append for TTS
# Translate Summary to Hindi
translated_summary = GoogleTranslator(source="en", target="hi").translate(summarized_text)
# Automatically Generate and Play Hindi Speech
st.write("π **Generating Hindi Audio...**")
text_to_speech(translated_summary)
# Display Audio Output
st.audio("output.wav", format="audio/wav")
else:
st.error("β No news articles found! Try another company.")
|