from transformers import pipeline

class SindhiSentiment:
    def __init__(self):
        # Using a model that handles Arabic/Urdu scripts much better
        self.classifier = pipeline("text-classification", model="lxyuan/distilbert-base-multilingual-cased-sentiments-student")
        
    def analyze(self, text):
        try:
            res = self.classifier(text)[0]
            # Map the standard outputs to clean strings
            label = res["label"].capitalize()
            confidence = round(res['score'] * 100, 2)
            return {"label": label, "confidence": f"{confidence}%"}
        except Exception as e:
            return {"label": "Neutral", "confidence": "0.0%"}
