File size: 2,906 Bytes
bf4ee4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
70
71
72
73
74
75
76
77
78
79
80
81
"""Streamlit frontend for the News Summarization application."""

import streamlit as st
import pandas as pd
import json
import os
import plotly.express as px
import altair as alt
from utils import analyze_company_data  # Import the analysis function directly

st.set_page_config(
    page_title="News Summarization App",
    page_icon="πŸ“°",
    layout="wide"
)

def process_company(company_name):
    """Process company data directly."""
    try:
        # Call the analysis function directly from utils
        data = analyze_company_data(company_name)
        
        # Generate audio if needed
        if 'summary' in data:
            from gtts import gTTS
            tts = gTTS(text=data['summary'], lang='en')
            audio_path = os.path.join('audio_output', f'{company_name}_summary.mp3')
            os.makedirs('audio_output', exist_ok=True)
            tts.save(audio_path)
            data['audio_path'] = audio_path
            
        return data
    except Exception as e:
        st.error(f"Error processing company: {str(e)}")
        return {"articles": [], "comparative_sentiment_score": {}, "final_sentiment_analysis": "", "audio_path": None}

def main():
    st.title("πŸ“° News Summarization and Analysis")
    
    # Sidebar
    st.sidebar.header("Settings")
    
    # Company name input
    company_name = st.text_input("Enter Company Name", "")
    
    if company_name:
        with st.spinner("Analyzing company news..."):
            data = process_company(company_name)
            
            # Display results
            if data["articles"]:
                st.subheader("πŸ“Š Analysis Results")
                
                # Display sentiment analysis
                if data["final_sentiment_analysis"]:
                    st.write("Sentiment Analysis:", data["final_sentiment_analysis"])
                
                # Display articles
                st.subheader("πŸ“° Recent Articles")
                for article in data["articles"]:
                    with st.expander(article["title"]):
                        st.write(article["summary"])
                        st.write("Source:", article["source"])
                        st.write("Sentiment:", article["sentiment"])
                
                # Display audio if available
                if data.get("audio_path"):
                    st.audio(data["audio_path"])
                
                # Display visualizations
                if data.get("comparative_sentiment_score"):
                    st.subheader("πŸ“ˆ Sentiment Distribution")
                    sentiment_df = pd.DataFrame(data["comparative_sentiment_score"])
                    fig = px.bar(sentiment_df, title="Sentiment Analysis by Source")
                    st.plotly_chart(fig)
            else:
                st.warning("No articles found for this company.")

if __name__ == "__main__":
    main()