Spaces:
Running
Running
File size: 1,196 Bytes
db0f499 8ed0852 db0f499 4dfc57d 8ed0852 db0f499 8ed0852 db0f499 c4b34d7 8ed0852 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 29 30 31 32 33 34 35 36 37 38 |
import gradio as gr
from transformers import pipeline
# Define model names
models = {
"ModernBERT Base (Go-Emotions)": "cirimus/modernbert-base-go-emotions",
"ModernBERT Large (Go-Emotions)": "cirimus/modernbert-large-go-emotions"
}
# Function to load the selected model and classify text
def classify_text(model_name, text):
classifier = pipeline("text-classification", model=models[model_name], top_k=None)
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.Dropdown(
list(models.keys()),
label="Select Model",
value="ModernBERT Base (Go-Emotions)"
),
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="🎭 ModernBERT Emotion Classifier",
description="Select a model and enter a sentence to see its associated emotions and confidence scores.",
)
# Launch the app
interface.launch()
|