sidmanale643 commited on
Commit
77d34d6
Β·
verified Β·
1 Parent(s): b4064c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -33
app.py CHANGED
@@ -1,34 +1,71 @@
1
- import streamlit as st
2
- import requests
3
-
4
- st.title("Company Sentiment Analyzer")
5
-
6
- company_name = st.text_input("Enter Company Name", "Tesla")
7
- model_provider = st.selectbox("Model Provider", options=["Ollama", "Groq"])
8
-
9
- if st.button("Fetch Sentiment Data"):
10
- api_url = (
11
- f"http://localhost:8000/home?"
12
- f"company_name={company_name}&model_provider={model_provider}"
13
- )
14
-
15
- try:
16
- response = requests.get(api_url)
17
- response.raise_for_status()
18
-
19
- data = response.json()
20
-
21
- st.subheader("Company Name")
22
- st.write(data.get("company_name"))
23
-
24
- st.subheader("Final Report")
25
- st.write(data.get("final_report"))
26
-
27
- st.subheader("πŸ”Š Audio Output")
28
- audio_file = "output.mp3"
29
- if audio_file:
30
- st.audio(audio_file)
31
-
32
- except requests.exceptions.RequestException as e:
33
- st.error(f"Error fetching data: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  #
 
1
+ import streamlit as st
2
+ import requests
3
+ from utils import (
4
+ fetch_from_web,
5
+ analyze_sentiment,
6
+ generate_comparative_sentiment,
7
+ generate_final_report,
8
+ get_summaries_by_sentiment,
9
+ translate,
10
+ text_to_speech,
11
+ )
12
+
13
+ st.title("Company Sentiment Analyzer")
14
+
15
+ company_name = st.text_input("Enter Company Name", "Tesla")
16
+ model_provider = st.selectbox("Model Provider", options=["Ollama", "Groq"])
17
+
18
+ if st.button("Fetch Sentiment Data"):
19
+ web_results = fetch_from_web(company_name)
20
+
21
+ if "sources" not in web_results:
22
+ return {"error": "No sources found."}
23
+
24
+ sentiment_output = [
25
+ analyze_sentiment(article, model_provider)
26
+ for article in web_results["sources"][:5]
27
+ ]
28
+
29
+ comparative_sentiment = generate_comparative_sentiment(sentiment_output)
30
+
31
+ positive_summary, negative_summary, neutral_summary = get_summaries_by_sentiment(
32
+ sentiment_output
33
+ )
34
+
35
+ final_report = generate_final_report(
36
+ positive_summary,
37
+ negative_summary,
38
+ neutral_summary,
39
+ comparative_sentiment,
40
+ model_provider,
41
+ )
42
+
43
+ hindi_translation = translate(final_report, model_provider)
44
+ audio_path = text_to_speech(hindi_translation)
45
+
46
+ output_dict = {
47
+ "company_name": company_name,
48
+ "articles": sentiment_output,
49
+ "comparative_sentiment": comparative_sentiment,
50
+ "final_report": final_report,
51
+ "hindi_translation": hindi_translation,
52
+ "audio_url": audio_path,
53
+ }
54
+
55
+ st.subheader("Company Name")
56
+ st.write(output_dict.get("company_name"))
57
+
58
+ st.subheader("Final Report")
59
+ st.write(output_dict.get("final_report"))
60
+
61
+ st.subheader("πŸ”Š Audio Output")
62
+ audio_file = "output.mp3"
63
+ if audio_file:
64
+ st.audio(audio_file)
65
+
66
+ except requests.exceptions.RequestException as e:
67
+ st.error(f"Error fetching data: {e}")
68
+
69
+
70
+
71
  #