File size: 4,564 Bytes
53dd0ab
 
 
 
 
 
aea053c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53dd0ab
 
 
aea053c
 
53dd0ab
 
 
 
aea053c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53dd0ab
 
aea053c
 
53dd0ab
 
 
 
 
 
 
 
aea053c
53dd0ab
 
 
 
 
 
aea053c
 
 
 
 
 
53dd0ab
 
 
 
 
 
 
 
 
 
aea053c
 
 
 
 
 
53dd0ab
 
 
 
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import streamlit as st
import requests

BASE_URL = "https://jatin7237-news-app.hf.space"  # Replace with your API's public URL
st.title("Company Sentiment Analysis")

company_name = st.text_input(
    "Enter the company name:", 
    placeholder="Example: Microsoft, Apple, Tesla"
)

def display_articles(articles):
    for i, article in enumerate(articles, start=1):
        st.markdown(f"#### **Article {i}**")
        st.write(f"- **Title:** {article['Title']}")
        st.write(f"- **Summary:** {article['Summary']}")
        st.write(f"- **Sentiment:** {article['Sentiment']}")
        st.write(f"- **Score:** {article['Score']:.2f}")
        st.write(f"- **Topics:** {', '.join(article['Topics'])}")
        st.markdown("---")

def display_sentiment_distribution(sentiment_distribution):
    st.subheader("Sentiment Distribution")
    sentiment_data = {
        "Sentiment": list(sentiment_distribution.keys()),
        "Count": list(sentiment_distribution.values())
    }
    st.table(sentiment_data)

def display_coverage_differences(coverage_differences):
    st.subheader("Coverage Differences")
    for diff in coverage_differences:
        st.markdown(f"- **Comparison:** {diff['Comparison']}")
        st.markdown(f"  - **Impact:** {diff['Impact']}")
    st.markdown("---")

def display_topic_overlap(topic_overlap):
    st.subheader("Topic Overlap")
    st.write(f"- **Common Topics:** {', '.join(topic_overlap['Common Topics'])}")
    st.write("- **Unique Topics by Article:**")
    for article, topics in topic_overlap["Unique Topics"].items():
        st.write(f"  - **{article}:** {', '.join(topics)}")
    st.markdown("---")

if st.button("Generate Summary"):
    if company_name:
        try:
            summary_url = f"{BASE_URL}/generateSummary?company_name={company_name}"
            response = requests.post(summary_url)
            
            if response.status_code == 200:
                data = response.json()
                
                # Company Name
                st.markdown(f"### **Company: {data.get('Company', 'Unknown')}**")

                # Articles
                st.markdown("### **Articles:**")
                display_articles(data.get("Articles", []))

                # Comparative Sentiment Score
                st.markdown("### **Comparative Sentiment Score**")
                sentiment_distribution = data.get("Comparative Sentiment Score", {}).get("Sentiment Distribution", {})
                display_sentiment_distribution(sentiment_distribution)

                coverage_differences = data.get("Comparative Sentiment Score", {}).get("Coverage Differences", [])
                display_coverage_differences(coverage_differences)

                topic_overlap = data.get("Comparative Sentiment Score", {}).get("Topic Overlap", {})
                display_topic_overlap(topic_overlap)

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

                # Hindi Summary
                st.markdown("### **Hindi Summary**")
                st.write(data.get("Hindi Summary", "No Hindi summary available."))

            else:
                st.error(f"Error: {response.status_code}, {response.text}")

        except Exception as e:
            st.error(f"An error occurred: {e}")
    else:
        st.warning("⚠️ Please enter a company name.")

if st.button("Download JSON File"):
    json_url = f"{BASE_URL}/downloadJson"
    try:
        response = requests.get(json_url)
        if response.status_code == 200:
            st.download_button(
                label="Download JSON File",
                data=response.content,
                file_name="final_summary.json",
                mime="application/json",
            )
        else:
            st.error(f"Error: {response.status_code}, {response.text}")
    except Exception as e:
        st.error(f"An error occurred: {e}")

if st.button("Download Hindi Audio"):
    audio_url = f"{BASE_URL}/downloadHindiAudio"
    try:
        response = requests.get(audio_url)
        if response.status_code == 200:
            st.download_button(
                label="Download Hindi Audio",
                data=response.content,
                file_name="hindi_summary.mp3",
                mime="audio/mp3",
            )
        else:
            st.error(f"Error: {response.status_code}, {response.text}")
    except Exception as e:
        st.error(f"An error occurred: {e}")