Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -31,13 +31,33 @@ def process_company(company_name):
|
|
31 |
# Call the analysis function directly from utils
|
32 |
data = analyze_company_data(company_name)
|
33 |
|
34 |
-
# Generate Hindi audio
|
35 |
-
if
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
-
|
41 |
except Exception as e:
|
42 |
st.error(f"Error processing company: {str(e)}")
|
43 |
return {"articles": [], "comparative_sentiment_score": {}, "final_sentiment_analysis": "", "audio_path": None}
|
@@ -62,7 +82,7 @@ def main():
|
|
62 |
with st.spinner("Analyzing news articles..."):
|
63 |
try:
|
64 |
# Process company data
|
65 |
-
data =
|
66 |
|
67 |
if not data["articles"]:
|
68 |
st.error("No articles found for analysis.")
|
@@ -309,48 +329,77 @@ def main():
|
|
309 |
except Exception as e:
|
310 |
st.error(f"Error creating indices visualization: {str(e)}")
|
311 |
|
312 |
-
# Display Final Analysis
|
313 |
-
st.header("
|
314 |
-
|
|
|
|
|
315 |
st.write(data["final_sentiment_analysis"])
|
|
|
|
|
|
|
|
|
|
|
316 |
|
317 |
-
#
|
318 |
-
|
319 |
-
indices = analysis["sentiment_indices"]
|
320 |
-
if indices and any(isinstance(v, (int, float)) for v in indices.values()):
|
321 |
-
st.sidebar.markdown("### Sentiment Indices")
|
322 |
-
for idx_name, idx_value in indices.items():
|
323 |
-
if isinstance(idx_value, (int, float)):
|
324 |
-
formatted_name = " ".join(word.capitalize() for word in idx_name.replace("_", " ").split())
|
325 |
-
st.sidebar.metric(formatted_name, f"{idx_value:.2f}")
|
326 |
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
|
348 |
-
#
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
354 |
|
355 |
# Total Articles
|
356 |
if "total_articles" in analysis:
|
|
|
31 |
# Call the analysis function directly from utils
|
32 |
data = analyze_company_data(company_name)
|
33 |
|
34 |
+
# Generate Hindi audio from final analysis
|
35 |
+
if data.get("final_sentiment_analysis"):
|
36 |
+
# Get the translator
|
37 |
+
translator = get_translator()
|
38 |
+
if translator:
|
39 |
+
try:
|
40 |
+
# Translate final analysis to Hindi
|
41 |
+
translated_analysis = translator.translate(
|
42 |
+
data["final_sentiment_analysis"],
|
43 |
+
dest='hi'
|
44 |
+
).text
|
45 |
+
|
46 |
+
# Generate Hindi audio
|
47 |
+
tts_converter = TextToSpeechConverter()
|
48 |
+
audio_path = tts_converter.generate_audio(
|
49 |
+
translated_analysis,
|
50 |
+
f'{company_name}_summary'
|
51 |
+
)
|
52 |
+
data['audio_path'] = audio_path
|
53 |
+
except Exception as e:
|
54 |
+
print(f"Error generating Hindi audio: {str(e)}")
|
55 |
+
data['audio_path'] = None
|
56 |
+
else:
|
57 |
+
print("Translator not available")
|
58 |
+
data['audio_path'] = None
|
59 |
|
60 |
+
return data
|
61 |
except Exception as e:
|
62 |
st.error(f"Error processing company: {str(e)}")
|
63 |
return {"articles": [], "comparative_sentiment_score": {}, "final_sentiment_analysis": "", "audio_path": None}
|
|
|
82 |
with st.spinner("Analyzing news articles..."):
|
83 |
try:
|
84 |
# Process company data
|
85 |
+
data = process_company(company)
|
86 |
|
87 |
if not data["articles"]:
|
88 |
st.error("No articles found for analysis.")
|
|
|
329 |
except Exception as e:
|
330 |
st.error(f"Error creating indices visualization: {str(e)}")
|
331 |
|
332 |
+
# Display Final Analysis
|
333 |
+
st.header("π Final Analysis")
|
334 |
+
|
335 |
+
# Display overall sentiment analysis
|
336 |
+
if data.get("final_sentiment_analysis"):
|
337 |
st.write(data["final_sentiment_analysis"])
|
338 |
+
|
339 |
+
# Display ensemble model details
|
340 |
+
if data.get("ensemble_info"):
|
341 |
+
st.subheader("Ensemble Model Details")
|
342 |
+
ensemble_info = data["ensemble_info"]
|
343 |
|
344 |
+
# Create columns for model details
|
345 |
+
model_cols = st.columns(3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
|
347 |
+
with model_cols[0]:
|
348 |
+
st.markdown("**Primary Model:**")
|
349 |
+
if "models" in ensemble_info and "transformer" in ensemble_info["models"]:
|
350 |
+
model = ensemble_info["models"]["transformer"]
|
351 |
+
st.write(f"Sentiment: {model['sentiment']}")
|
352 |
+
st.write(f"Score: {model['score']:.3f}")
|
353 |
+
|
354 |
+
with model_cols[1]:
|
355 |
+
st.markdown("**TextBlob Analysis:**")
|
356 |
+
if "models" in ensemble_info and "textblob" in ensemble_info["models"]:
|
357 |
+
model = ensemble_info["models"]["textblob"]
|
358 |
+
st.write(f"Sentiment: {model['sentiment']}")
|
359 |
+
st.write(f"Score: {model['score']:.3f}")
|
360 |
+
|
361 |
+
with model_cols[2]:
|
362 |
+
st.markdown("**VADER Analysis:**")
|
363 |
+
if "models" in ensemble_info and "vader" in ensemble_info["models"]:
|
364 |
+
model = ensemble_info["models"]["vader"]
|
365 |
+
st.write(f"Sentiment: {model['sentiment']}")
|
366 |
+
st.write(f"Score: {model['score']:.3f}")
|
367 |
|
368 |
+
# Display ensemble agreement if available
|
369 |
+
if "model_agreement" in ensemble_info:
|
370 |
+
st.markdown(f"**Model Agreement:** {ensemble_info['model_agreement']:.3f}")
|
371 |
+
|
372 |
+
# Display Hindi audio player
|
373 |
+
st.subheader("π Listen to Analysis (Hindi)")
|
374 |
+
if data.get("audio_path") and os.path.exists(data["audio_path"]):
|
375 |
+
st.audio(data["audio_path"])
|
376 |
+
else:
|
377 |
+
st.info("Generating Hindi audio summary...")
|
378 |
+
with st.spinner("Please wait while we generate the Hindi audio summary..."):
|
379 |
+
# Try to generate audio again
|
380 |
+
translator = get_translator()
|
381 |
+
if translator and data.get("final_sentiment_analysis"):
|
382 |
+
try:
|
383 |
+
# Translate final analysis to Hindi
|
384 |
+
translated_analysis = translator.translate(
|
385 |
+
data["final_sentiment_analysis"],
|
386 |
+
dest='hi'
|
387 |
+
).text
|
388 |
+
|
389 |
+
# Generate Hindi audio
|
390 |
+
tts_converter = TextToSpeechConverter()
|
391 |
+
audio_path = tts_converter.generate_audio(
|
392 |
+
translated_analysis,
|
393 |
+
f'{company}_summary'
|
394 |
+
)
|
395 |
+
if audio_path and os.path.exists(audio_path):
|
396 |
+
st.audio(audio_path)
|
397 |
+
else:
|
398 |
+
st.error("Hindi audio summary not available")
|
399 |
+
except Exception as e:
|
400 |
+
st.error(f"Error generating Hindi audio: {str(e)}")
|
401 |
+
else:
|
402 |
+
st.error("Hindi audio summary not available")
|
403 |
|
404 |
# Total Articles
|
405 |
if "total_articles" in analysis:
|