Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| classifier = pipeline( | |
| "text-classification", | |
| model="bhadresh-savani/bert-base-go-emotion", | |
| return_all_scores=True | |
| ) | |
| def detect_emotions(text): | |
| results = classifier(text)[0] | |
| return {r['label']: round(r['score'], 3) for r in sorted(results, key=lambda x: x["score"], reverse=True)} | |
| demo = gr.Interface( | |
| fn=detect_emotions, | |
| inputs=gr.Textbox(lines=4, placeholder="Enter a tweet or comment..."), | |
| outputs="label", | |
| title="Emotion Detection with BERT (GoEmotions)", | |
| description="Detect joy, sadness, anger, and more using BERT trained on GoEmotions." | |
| ) | |
| demo.launch() | |