Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,71 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import requests
|
| 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 |
#
|
|
|
|
| 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 |
#
|