Spaces:
Runtime error
Runtime error
| from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer | |
| from textblob import TextBlob | |
| class SentimentAnalysisAgent: | |
| def __init__(self): | |
| self.analyzer = SentimentIntensityAnalyzer() | |
| def analyze(self, news_item): | |
| text = news_item.get("headline","") + " " + news_item.get("summary","") | |
| vs = self.analyzer.polarity_scores(text) | |
| blob = TextBlob(text) | |
| final_score = 0.7*vs['compound'] + 0.3*blob.sentiment.polarity | |
| news_item['sentiment'] = final_score | |
| return news_item | |
| def batch_analyze(self, articles): | |
| return [self.analyze(a) for a in articles] | |