import gradio as gr from transformers import pipeline # Multilingual emotion detection মডেল লোড emotion_classifier = pipeline( "text-classification", model="Toshifumi/bert-base-multilingual-cased-finetuned-emotion", return_all_scores=False ) def detect_emotion(text): try: result = emotion_classifier(text)[0] label = result["label"] # লেবেলগুলোকে সুন্দর বাংলা বা ইংরেজি নামে ম্যাপ করতে চাইলে নিচের ম্যাপ ইউজ করো label_map = { "anger": "Angry", "joy": "Happy", "sadness": "Sad", "fear": "Fear", "love": "Love", "surprise": "Surprised", "neutral": "Neutral" } return label_map.get(label.lower(), label) except Exception: return "Unknown" # Gradio UI সেটআপ interface = gr.Interface( fn=detect_emotion, inputs=gr.Textbox(lines=4, placeholder="বাংলা বা English-এ লিখুন এখানে...", label="আপনার টেক্সট"), outputs=gr.Textbox(label="Emotion Detected"), title="Bilingual Emotion Detector", description="বাংলা ও ইংরেজি টেক্সট থেকে আবেগ শনাক্ত করে একটি প্রশিক্ষিত মডেল।" ) interface.launch()