File size: 1,880 Bytes
443a737
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from api import analyze_news
import base64
import nest_asyncio

nest_asyncio.apply()

st.title("Company News Sentiment Analyzer")

company = st.text_input("Enter Company Name", placeholder="Example: Tesla")
source = st.selectbox("Select the source you want news from:", ("NewsOrg", "Yahoo News"))

if st.button("Fetch News & Analyze"):
    if not company or not source:
        st.error("Please enter a company name and select the source")
    else:
        with st.spinner("Fetching from API..."):
            data = analyze_news(company=company, source=source)
            if data:
                st.subheader(f"Sentiment Analysis for {data['Company']}")

                # Comparative Sentiment Score
                st.write("### Comparative Sentiment Score")
                sentiment_dist = data.get("Comparitive Sentiment Score", {})
                st.json(sentiment_dist)

                # Final Sentiment Analysis
                st.write("### Final Sentiment Analysis")
                st.success(data.get("Final Sentiment Analysis", "No analysis available"))

                # Audio Player for Hindi TTS
                if "Audio" in data:
                    st.write("### Listen to Hindi Summary")
                    audio_bytes = base64.b64decode(data["Audio"])
                    st.audio(audio_bytes, format="audio/mp3")

                # Articles Display
                st.write("### Articles:")
                for idx, article in enumerate(data["Articles"]):
                    st.write(f"**{idx+1}. Title:** {article['Title']}")
                    st.write(f"**Sentiment:** {article['Sentiment']}")
                    st.write(f"**Summary:** {article['Summary']}")
                    st.markdown("---")
            else:
                st.error("Failed to fetch data from API.")