Spaces:
Sleeping
Sleeping
File size: 613 Bytes
47f370d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
from transformers import pipeline
class SentimentAnalysis:
def __init__(self):
# Initialize the sentiment analysis pipeline
self.pipe = pipeline("text-classification", model="tabularisai/multilingual-sentiment-analysis")
def classify(self, text: str):
# Use the pipeline to classify the input text
result_set = self.pipe(text)
result = result_set[0]
analysis = result["label"].lower()
result["value"] = "positive" if "positive" in analysis \
else "negative" if "negative" in analysis \
else "neutral"
return result
|