File size: 784 Bytes
db0f499
 
 
 
 
 
 
 
 
 
 
 
 
 
f470f4e
 
 
 
 
db0f499
 
 
 
 
f470f4e
db0f499
 
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
import gradio as gr
from transformers import pipeline

# Load the model
model_name = "cirimus/modernbert-base-go-emotions"
classifier = pipeline("text-classification", model=model_name, top_k=None)

def classify_text(text):
    predictions = classifier(text)
    return {pred["label"]: pred["score"] for pred in predictions[0]}

# Create the Gradio interface
interface = gr.Interface(
    fn=classify_text,
    inputs=gr.Textbox(
        lines=2, 
        placeholder="Enter text to analyze emotions...", 
        value="I am thrilled to be a part of this amazing journey!"
    ),
    outputs=gr.Label(num_top_classes=5),
    title="Emotion Classifier",
    description="Enter a sentence to see its associated emotions and confidence scores.",
)


# Launch the app
interface.launch()