MedCall-AI / vocca_ai /sentiment.py
Yuvrajspd09's picture
Update vocca_ai/sentiment.py
90faf8d verified
raw
history blame contribute delete
643 Bytes
from transformers import pipeline
# Loading a sentiment model
sentiment_model = pipeline("sentiment-analysis", model="cardiffnlp/twitter-xlm-roberta-base-sentiment")
def analyze_sentiment(text):
"""
Uses a specialized sentiment model better suited for medical text.
"""
result = sentiment_model(text)[0]["label"]
if result.lower() == "positive":
return "Positive"
elif result.lower() == "negative":
return "Concerned"
return "Neutral"
if __name__ == "__main__":
sample_text = "I've been feeling really weak for the past few days."
print(f"Sentiment: {analyze_sentiment(sample_text)}")