File size: 769 Bytes
321e2dc
292d77d
321e2dc
292d77d
321e2dc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# app.py
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSequenceClassification

# Load the model from Hugging Face Model Hub
model_name = "SamLowe/roberta-base-go_emotions"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)

def predict_emotion(text):
    inputs = tokenizer(text, return_tensors="pt")
    outputs = model(**inputs)
    logits = outputs.logits
    predicted_class = logits.argmax().item()

    return {"emotion_label": predicted_class}

iface = gr.Interface(
    fn=predict_emotion,
    inputs=gr.Textbox(),
    outputs="label",
    live=True,
    title="Emotion Prediction",
    description="Enter a sentence for emotion prediction.",
)

iface.launch()