Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import AutoTokenizer, AutoModelForSequenceClassification | |
| import torch | |
| MODEL_NAME = "AnasAlokla/multilingual_go_emotions" | |
| tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME) | |
| model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME) | |
| labels = model.config.id2label | |
| def analyze(text): | |
| inputs = tokenizer(text, return_tensors="pt", truncation=True) | |
| outputs = model(**inputs) | |
| probs = torch.sigmoid(outputs.logits)[0] | |
| emotion_scores = {labels[i]: float(probs[i]) for i in range(len(labels))} | |
| sorted_emotions = dict(sorted(emotion_scores.items(), key=lambda x: x[1], reverse=True)) | |
| return sorted_emotions | |
| iface = gr.Interface(fn=analyze, inputs="text", outputs="json", title="GoEmotions Sentiment Analyzer", description="Enter any text and get scores for 28 emotions.") | |
| iface.launch() |