MedCall-AI / vocca_ai /sentiment.py
Yuvrajxms09's picture
Moved vocca_ai to root for Hugging Face deployment
20d97e8
raw
history blame
732 Bytes
from transformers import pipeline
# Load a better 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" # Replace "Negative" with a more medically appropriate term
return "Neutral"
# Example Usage
if __name__ == "__main__":
sample_text = "I've been feeling really weak and dizzy for the past few days."
print(f"Sentiment: {analyze_sentiment(sample_text)}")