Spaces:
Sleeping
Sleeping
Update app.py
Browse filesadded support for the large version
app.py
CHANGED
|
@@ -1,27 +1,37 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
predictions = classifier(text)
|
| 10 |
return {pred["label"]: pred["score"] for pred in predictions[0]}
|
| 11 |
|
| 12 |
# Create the Gradio interface
|
| 13 |
interface = gr.Interface(
|
| 14 |
fn=classify_text,
|
| 15 |
-
inputs=
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
outputs=gr.Label(num_top_classes=5),
|
| 21 |
-
title="Emotion Classifier",
|
| 22 |
-
description="
|
| 23 |
)
|
| 24 |
|
| 25 |
-
|
| 26 |
# Launch the app
|
| 27 |
interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Define model names
|
| 5 |
+
models = {
|
| 6 |
+
"ModernBERT Base (Go-Emotions)": "cirimus/modernbert-base-go-emotions",
|
| 7 |
+
"ModernBERT Large (Go-Emotions)": "cirimus/modernbert-large-go-emotions"
|
| 8 |
+
}
|
| 9 |
|
| 10 |
+
# Function to load the selected model
|
| 11 |
+
def classify_text(text, model_name):
|
| 12 |
+
classifier = pipeline("text-classification", model=models[model_name], top_k=None)
|
| 13 |
predictions = classifier(text)
|
| 14 |
return {pred["label"]: pred["score"] for pred in predictions[0]}
|
| 15 |
|
| 16 |
# Create the Gradio interface
|
| 17 |
interface = gr.Interface(
|
| 18 |
fn=classify_text,
|
| 19 |
+
inputs=[
|
| 20 |
+
gr.Dropdown(
|
| 21 |
+
list(models.keys()),
|
| 22 |
+
label="Select Model",
|
| 23 |
+
value="ModernBERT Base (Go-Emotions)"
|
| 24 |
+
),
|
| 25 |
+
gr.Textbox(
|
| 26 |
+
lines=2,
|
| 27 |
+
placeholder="Enter text to analyze emotions...",
|
| 28 |
+
value="I am thrilled to be a part of this amazing journey!"
|
| 29 |
+
)
|
| 30 |
+
],
|
| 31 |
outputs=gr.Label(num_top_classes=5),
|
| 32 |
+
title="ModernBERT Emotion Classifier",
|
| 33 |
+
description="Select a model and enter a sentence to see its associated emotions and confidence scores.",
|
| 34 |
)
|
| 35 |
|
|
|
|
| 36 |
# Launch the app
|
| 37 |
interface.launch()
|