Spaces:
Runtime error
Runtime error
from transformers import pipeline | |
class SentimentAnalyzer: | |
def __init__(self) -> None: | |
self.analyzer = pipeline("sentiment-analysis", model = "distilbert-base-uncased-finetuned-sst-2-english") | |
def score_sentiment(self, sentence: str) -> float: | |
return self.analyzer(sentence)[0] | |
def get_sentiment(self, sentence: str) -> str: | |
sentiment_score = self.score_sentiment(sentence) | |
return sentiment_score['label'] | |
if __name__ == "__main__": | |
sentence = "This place is good" | |
sentiment_analyzer = SentimentAnalyzer() | |
print(sentiment_analyzer.get_sentiment(sentence)) | |