Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
@@ -44,10 +44,29 @@ def analyze_company_data(company_name: str) -> Dict[str, Any]:
|
|
44 |
summary = text_summarizer.summarize(article['content'])
|
45 |
article['summary'] = summary
|
46 |
|
47 |
-
# Analyze sentiment
|
48 |
sentiment = sentiment_analyzer.analyze(article['content'])
|
49 |
article['sentiment'] = sentiment
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
# Track sentiment by source
|
52 |
source = article['source']
|
53 |
if source not in sentiment_scores:
|
|
|
44 |
summary = text_summarizer.summarize(article['content'])
|
45 |
article['summary'] = summary
|
46 |
|
47 |
+
# Analyze overall sentiment
|
48 |
sentiment = sentiment_analyzer.analyze(article['content'])
|
49 |
article['sentiment'] = sentiment
|
50 |
|
51 |
+
# Analyze fine-grained sentiment
|
52 |
+
try:
|
53 |
+
# Financial sentiment
|
54 |
+
if 'financial' in sentiment_analyzer.fine_grained_models:
|
55 |
+
financial_sentiment = sentiment_analyzer.fine_grained_models['financial'](article['content'])[0]
|
56 |
+
article['financial_sentiment'] = financial_sentiment['label']
|
57 |
+
|
58 |
+
# Emotional sentiment
|
59 |
+
if 'emotion' in sentiment_analyzer.fine_grained_models:
|
60 |
+
emotional_sentiment = sentiment_analyzer.fine_grained_models['emotion'](article['content'])[0]
|
61 |
+
article['emotional_sentiment'] = emotional_sentiment['label']
|
62 |
+
|
63 |
+
# ESG sentiment
|
64 |
+
if 'esg' in sentiment_analyzer.fine_grained_models:
|
65 |
+
esg_sentiment = sentiment_analyzer.fine_grained_models['esg'](article['content'])[0]
|
66 |
+
article['esg_sentiment'] = esg_sentiment['label']
|
67 |
+
except Exception as e:
|
68 |
+
print(f"Error in fine-grained sentiment analysis: {str(e)}")
|
69 |
+
|
70 |
# Track sentiment by source
|
71 |
source = article['source']
|
72 |
if source not in sentiment_scores:
|