NLP_genAI_final / agents /sentimentanalyzer.py
irebmann's picture
Initial upload: local files to Hugging Face repo
135f6a8
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]