Divyansh Kushwaha commited on
Commit
8ba7699
·
1 Parent(s): 657a977

Streamlit app updated

Browse files
Files changed (1) hide show
  1. app.py +19 -14
app.py CHANGED
@@ -1,14 +1,16 @@
1
  import streamlit as st
2
  import requests
3
 
4
- BASE_URL = "http://localhost:8000"
5
  st.title("Company Sentiment Analysis")
6
 
 
7
  company_name = st.text_input(
8
  "Enter the company name:",
9
  placeholder="Example: Microsoft, Apple, Tesla"
10
  )
11
 
 
12
  def display_articles(articles):
13
  for i, article in enumerate(articles, start=1):
14
  st.markdown(f"##### **Article {i}: {article['Title']}**")
@@ -16,6 +18,7 @@ def display_articles(articles):
16
  st.write(f"- **Sentiment:** {article['Sentiment']} | **Score:** {article['Score']:.2f}")
17
  st.write(f"- **Topics:** {', '.join(article['Topics'])}")
18
 
 
19
  def display_sentiment_distribution(sentiment_distribution):
20
  st.markdown("#### **Sentiment Distribution:**")
21
  sentiment_data = {
@@ -24,12 +27,14 @@ def display_sentiment_distribution(sentiment_distribution):
24
  }
25
  st.table(sentiment_data)
26
 
 
27
  def display_coverage_differences(coverage_differences):
28
  if coverage_differences:
29
  st.markdown("#### **Coverage Differences:**")
30
  for diff in coverage_differences:
31
  st.write(f"- **{diff['Comparison']}:** {diff['Impact']}")
32
 
 
33
  def display_topic_overlap(topic_overlap):
34
  st.markdown("#### **Topic Overlap:**")
35
  st.write(f"- **Common Topics:** {', '.join(topic_overlap['Common Topics'])}")
@@ -37,6 +42,7 @@ def display_topic_overlap(topic_overlap):
37
  for article, topics in topic_overlap["Unique Topics"].items():
38
  st.write(f" - **{article}:** {', '.join(topics)}")
39
 
 
40
  if st.button("Generate Summary"):
41
  if company_name:
42
  try:
@@ -45,29 +51,28 @@ if st.button("Generate Summary"):
45
 
46
  if response.status_code == 200:
47
  data = response.json()
48
-
49
  st.markdown(f"#### **Company: {data.get('Company', 'Unknown')}**")
50
-
51
- # Articles
52
  st.markdown("#### **Articles:**")
53
  display_articles(data.get("Articles", []))
54
-
55
- # Comparative Sentiment Score
56
  st.markdown("#### **Comparative Sentiment Score:**")
57
  sentiment_distribution = data.get("Comparative Sentiment Score", {}).get("Sentiment Distribution", {})
58
  display_sentiment_distribution(sentiment_distribution)
59
-
60
  coverage_differences = data.get("Comparative Sentiment Score", {}).get("Coverage Differences", [])
61
  display_coverage_differences(coverage_differences)
62
-
63
  topic_overlap = data.get("Comparative Sentiment Score", {}).get("Topic Overlap", {})
64
  display_topic_overlap(topic_overlap)
65
-
66
- # Final Sentiment Analysis
67
  st.markdown("#### **Final Sentiment Analysis:**")
68
  st.write(data.get("Final Sentiment Analysis", "No sentiment analysis available."))
69
-
70
- # Check session state and play audio
71
  st.markdown("#### **Hindi Summary Audio:**")
72
  st.write(data.get("Audio", "No Audio available"))
73
  audio_url = f"{BASE_URL}/downloadHindiAudio"
@@ -76,15 +81,14 @@ if st.button("Generate Summary"):
76
  st.audio(audio_response.content, format="audio/mp3")
77
  else:
78
  st.error("Failed to load audio.")
79
-
80
  else:
81
  st.error(f"Error: {response.status_code}, {response.text}")
82
-
83
  except Exception as e:
84
  st.error(f"An error occurred: {e}")
85
  else:
86
  st.warning("Please enter a company name !")
87
 
 
88
  if st.button("Download JSON File"):
89
  json_url = f"{BASE_URL}/downloadJson"
90
  try:
@@ -101,6 +105,7 @@ if st.button("Download JSON File"):
101
  except Exception as e:
102
  st.error(f"An error occurred: {e}")
103
 
 
104
  if st.button("Download Hindi Audio"):
105
  audio_url = f"{BASE_URL}/downloadHindiAudio"
106
  try:
 
1
  import streamlit as st
2
  import requests
3
 
4
+ BASE_URL = "http://localhost:8000" # Base URL for API requests
5
  st.title("Company Sentiment Analysis")
6
 
7
+ # Input field for company name
8
  company_name = st.text_input(
9
  "Enter the company name:",
10
  placeholder="Example: Microsoft, Apple, Tesla"
11
  )
12
 
13
+ # Function to display articles with sentiment analysis
14
  def display_articles(articles):
15
  for i, article in enumerate(articles, start=1):
16
  st.markdown(f"##### **Article {i}: {article['Title']}**")
 
18
  st.write(f"- **Sentiment:** {article['Sentiment']} | **Score:** {article['Score']:.2f}")
19
  st.write(f"- **Topics:** {', '.join(article['Topics'])}")
20
 
21
+ # Function to display sentiment distribution in table format
22
  def display_sentiment_distribution(sentiment_distribution):
23
  st.markdown("#### **Sentiment Distribution:**")
24
  sentiment_data = {
 
27
  }
28
  st.table(sentiment_data)
29
 
30
+ # Function to display coverage differences between articles
31
  def display_coverage_differences(coverage_differences):
32
  if coverage_differences:
33
  st.markdown("#### **Coverage Differences:**")
34
  for diff in coverage_differences:
35
  st.write(f"- **{diff['Comparison']}:** {diff['Impact']}")
36
 
37
+ # Function to display topic overlap analysis
38
  def display_topic_overlap(topic_overlap):
39
  st.markdown("#### **Topic Overlap:**")
40
  st.write(f"- **Common Topics:** {', '.join(topic_overlap['Common Topics'])}")
 
42
  for article, topics in topic_overlap["Unique Topics"].items():
43
  st.write(f" - **{article}:** {', '.join(topics)}")
44
 
45
+ # Button to generate summary based on company name
46
  if st.button("Generate Summary"):
47
  if company_name:
48
  try:
 
51
 
52
  if response.status_code == 200:
53
  data = response.json()
 
54
  st.markdown(f"#### **Company: {data.get('Company', 'Unknown')}**")
55
+
56
+ # Display articles with sentiment analysis
57
  st.markdown("#### **Articles:**")
58
  display_articles(data.get("Articles", []))
59
+
60
+ # Display sentiment analysis details
61
  st.markdown("#### **Comparative Sentiment Score:**")
62
  sentiment_distribution = data.get("Comparative Sentiment Score", {}).get("Sentiment Distribution", {})
63
  display_sentiment_distribution(sentiment_distribution)
64
+
65
  coverage_differences = data.get("Comparative Sentiment Score", {}).get("Coverage Differences", [])
66
  display_coverage_differences(coverage_differences)
67
+
68
  topic_overlap = data.get("Comparative Sentiment Score", {}).get("Topic Overlap", {})
69
  display_topic_overlap(topic_overlap)
70
+
71
+ # Display final sentiment analysis result
72
  st.markdown("#### **Final Sentiment Analysis:**")
73
  st.write(data.get("Final Sentiment Analysis", "No sentiment analysis available."))
74
+
75
+ # Display and play Hindi summary audio
76
  st.markdown("#### **Hindi Summary Audio:**")
77
  st.write(data.get("Audio", "No Audio available"))
78
  audio_url = f"{BASE_URL}/downloadHindiAudio"
 
81
  st.audio(audio_response.content, format="audio/mp3")
82
  else:
83
  st.error("Failed to load audio.")
 
84
  else:
85
  st.error(f"Error: {response.status_code}, {response.text}")
 
86
  except Exception as e:
87
  st.error(f"An error occurred: {e}")
88
  else:
89
  st.warning("Please enter a company name !")
90
 
91
+ # Button to download the final summary in JSON format
92
  if st.button("Download JSON File"):
93
  json_url = f"{BASE_URL}/downloadJson"
94
  try:
 
105
  except Exception as e:
106
  st.error(f"An error occurred: {e}")
107
 
108
+ # Button to download Hindi summary audio file
109
  if st.button("Download Hindi Audio"):
110
  audio_url = f"{BASE_URL}/downloadHindiAudio"
111
  try: