Update app.py
Browse files
app.py
CHANGED
|
@@ -401,53 +401,53 @@ company_name = st.text_input("Enter Company Name", "Tesla")
|
|
| 401 |
model_provider = st.selectbox("Model Provider", options=["Ollama", "Groq"])
|
| 402 |
|
| 403 |
if st.button("Fetch Sentiment Data"):
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
if "sources" not in web_results:
|
| 407 |
-
return {"error": "No sources found."}
|
| 408 |
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
|
|
|
|
|
|
|
|
|
| 413 |
|
| 414 |
-
|
| 415 |
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
|
| 428 |
-
|
| 429 |
-
|
| 430 |
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
|
| 440 |
-
|
| 441 |
-
|
| 442 |
|
| 443 |
-
|
| 444 |
-
|
| 445 |
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
|
| 451 |
except requests.exceptions.RequestException as e:
|
| 452 |
st.error(f"Error fetching data: {e}")
|
| 453 |
-
|
|
|
|
| 401 |
model_provider = st.selectbox("Model Provider", options=["Ollama", "Groq"])
|
| 402 |
|
| 403 |
if st.button("Fetch Sentiment Data"):
|
| 404 |
+
try:
|
| 405 |
+
web_results = fetch_from_web(company_name)
|
|
|
|
|
|
|
| 406 |
|
| 407 |
+
if "sources" not in web_results:
|
| 408 |
+
st.error("No sources found.")
|
| 409 |
+
else:
|
| 410 |
+
sentiment_output = [
|
| 411 |
+
analyze_sentiment(article, model_provider)
|
| 412 |
+
for article in web_results["sources"][:5]
|
| 413 |
+
]
|
| 414 |
|
| 415 |
+
comparative_sentiment = generate_comparative_sentiment(sentiment_output)
|
| 416 |
|
| 417 |
+
positive_summary, negative_summary, neutral_summary = get_summaries_by_sentiment(
|
| 418 |
+
sentiment_output
|
| 419 |
+
)
|
| 420 |
|
| 421 |
+
final_report = generate_final_report(
|
| 422 |
+
positive_summary,
|
| 423 |
+
negative_summary,
|
| 424 |
+
neutral_summary,
|
| 425 |
+
comparative_sentiment,
|
| 426 |
+
model_provider,
|
| 427 |
+
)
|
| 428 |
|
| 429 |
+
hindi_translation = translate(final_report, model_provider)
|
| 430 |
+
audio_path = text_to_speech(hindi_translation)
|
| 431 |
|
| 432 |
+
output_dict = {
|
| 433 |
+
"company_name": company_name,
|
| 434 |
+
"articles": sentiment_output,
|
| 435 |
+
"comparative_sentiment": comparative_sentiment,
|
| 436 |
+
"final_report": final_report,
|
| 437 |
+
"hindi_translation": hindi_translation,
|
| 438 |
+
"audio_url": audio_path,
|
| 439 |
+
}
|
| 440 |
|
| 441 |
+
st.subheader("Company Name")
|
| 442 |
+
st.write(output_dict.get("company_name"))
|
| 443 |
|
| 444 |
+
st.subheader("Final Report")
|
| 445 |
+
st.write(output_dict.get("final_report"))
|
| 446 |
|
| 447 |
+
st.subheader("π Audio Output")
|
| 448 |
+
audio_file = "output.mp3"
|
| 449 |
+
if audio_file:
|
| 450 |
+
st.audio(audio_file)
|
| 451 |
|
| 452 |
except requests.exceptions.RequestException as e:
|
| 453 |
st.error(f"Error fetching data: {e}")
|
|
|