Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,15 +2,10 @@
|
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
-
|
| 6 |
-
# Load the model — update this to your Hub repo ID after pushing
|
| 7 |
-
# ---------------------------------------------------------------------------
|
| 8 |
-
MODEL_ID = "dk409/emotion-roberta" for Hub
|
| 9 |
classifier = pipeline("text-classification", model=MODEL_ID, top_k=None)
|
| 10 |
|
| 11 |
-
# ---------------------------------------------------------------------------
|
| 12 |
# Prediction function
|
| 13 |
-
# ---------------------------------------------------------------------------
|
| 14 |
def classify_emotion(text):
|
| 15 |
"""
|
| 16 |
Run the classifier and return a dict of {label: score} for Gradio's Label component.
|
|
@@ -22,9 +17,8 @@ def classify_emotion(text):
|
|
| 22 |
results = classifier(text)[0] # list of {"label": ..., "score": ...}
|
| 23 |
return {r["label"]: r["score"] for r in results}
|
| 24 |
|
| 25 |
-
|
| 26 |
# Gradio interface
|
| 27 |
-
# ---------------------------------------------------------------------------
|
| 28 |
examples = [
|
| 29 |
"I'm so happy to see you after all these years!",
|
| 30 |
"This is absolutely terrifying, I can't watch.",
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
+
MODEL_ID = "dk409/emotion-roberta"
|
|
|
|
|
|
|
|
|
|
| 6 |
classifier = pipeline("text-classification", model=MODEL_ID, top_k=None)
|
| 7 |
|
|
|
|
| 8 |
# Prediction function
|
|
|
|
| 9 |
def classify_emotion(text):
|
| 10 |
"""
|
| 11 |
Run the classifier and return a dict of {label: score} for Gradio's Label component.
|
|
|
|
| 17 |
results = classifier(text)[0] # list of {"label": ..., "score": ...}
|
| 18 |
return {r["label"]: r["score"] for r in results}
|
| 19 |
|
| 20 |
+
|
| 21 |
# Gradio interface
|
|
|
|
| 22 |
examples = [
|
| 23 |
"I'm so happy to see you after all these years!",
|
| 24 |
"This is absolutely terrifying, I can't watch.",
|