|
|
|
import gradio as gr |
|
from transformers import AutoTokenizer, AutoModelForSequenceClassification |
|
|
|
|
|
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() |
|
|