devanshu1121 commited on
Commit
71074e8
·
verified ·
1 Parent(s): 505dd15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -38
app.py CHANGED
@@ -1,38 +1,37 @@
1
- import streamlit as st
2
- import requests
3
-
4
- # URL of the deployed API
5
- API_URL = "http://localhost:8000/get_news_and_sentiment"
6
-
7
- # Streamlit Interface
8
- st.title("News Summarization and Sentiment Analysis")
9
-
10
- company_name = st.text_input("Enter the Company Name", "")
11
-
12
- if st.button('Get News and Analysis'):
13
- if company_name:
14
- response = requests.post(API_URL, json={"company_name": company_name})
15
- result = response.json()
16
-
17
- st.subheader(f"Company: {result['Company']}")
18
-
19
- for article in result['Articles']:
20
- st.write(f"### {article['Title']}")
21
- st.write(f"**Summary**: {article['Summary']}")
22
- st.write(f"**Sentiment**: {article['Sentiment']}")
23
- st.write(f"[Read full article]({article['Link']})")
24
-
25
- st.subheader("Comparative Sentiment Analysis")
26
- st.write(f"Sentiment Distribution: {result['Comparative Sentiment Score']}")
27
- st.write("Coverage Differences:")
28
- for diff in result['Coverage Differences']:
29
- st.write(f"- {diff['Comparison']} - {diff['Impact']}")
30
-
31
- st.subheader("Final Sentiment Analysis")
32
- st.write(result['Final Sentiment'])
33
-
34
- st.subheader("Audio Summary")
35
- audio_file = result['Audio']
36
- st.audio(audio_file)
37
- else:
38
- st.warning("Please enter a company name.")
 
1
+ import streamlit as st
2
+ import requests
3
+
4
+ # API URL for the Hugging Face Space
5
+ API_URL = "https://company-news-analyzer.hf.space/get_news_and_sentiment"
6
+
7
+ # Streamlit UI
8
+ st.title("Company News Analyzer")
9
+
10
+ company_name = st.text_input("Enter company name:")
11
+
12
+ if st.button("Analyze"):
13
+ if company_name:
14
+ # Send a POST request to the FastAPI backend
15
+ response = requests.post(API_URL, json={"company_name": company_name})
16
+
17
+ if response.status_code == 200:
18
+ data = response.json()
19
+
20
+ # Display results
21
+ st.write(f"Company: {data['Company']}")
22
+ st.write("Articles:")
23
+ for article in data['Articles']:
24
+ st.write(f"Title: {article['Title']}")
25
+ st.write(f"Summary: {article['Summary']}")
26
+ st.write(f"Sentiment: {article['Sentiment']}")
27
+
28
+ # Display comparative sentiment analysis
29
+ st.write("Comparative Sentiment Analysis:")
30
+ st.write(data['Comparative Sentiment Score'])
31
+
32
+ # Play the audio file
33
+ st.audio(data['Audio'], format='audio/mp3')
34
+ else:
35
+ st.error("Failed to fetch data. Please try again.")
36
+ else:
37
+ st.error("Please enter a company name.")