Spaces:
Sleeping
Sleeping
File size: 857 Bytes
f4249b8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
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() |