Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the model
|
5 |
+
model_name = "cirimus/modernbert-base-go-emotions"
|
6 |
+
classifier = pipeline("text-classification", model=model_name, top_k=None)
|
7 |
+
|
8 |
+
def classify_text(text):
|
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=gr.Textbox(lines=2, placeholder="Enter text to analyze emotions..."),
|
16 |
+
outputs=gr.Label(num_top_classes=5),
|
17 |
+
title="Emotion Classifier",
|
18 |
+
description="Enter a sentence to see its associated emotions and confidence scores.",
|
19 |
+
)
|
20 |
+
|
21 |
+
# Launch the app
|
22 |
+
interface.launch()
|