Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,22 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def detect_emotions(text):
|
| 8 |
results = classifier(text)[0]
|
| 9 |
-
|
| 10 |
-
return {r['label']: round(r['score'], 3) for r in sorted_results}
|
| 11 |
|
| 12 |
demo = gr.Interface(
|
| 13 |
fn=detect_emotions,
|
| 14 |
inputs=gr.Textbox(lines=4, placeholder="Enter a tweet or comment..."),
|
| 15 |
outputs="label",
|
| 16 |
title="Emotion Detection with BERT (GoEmotions)",
|
| 17 |
-
description="Detect joy, sadness, anger, and
|
| 18 |
)
|
| 19 |
|
| 20 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
classifier = pipeline(
|
| 5 |
+
"text-classification",
|
| 6 |
+
model="bhadresh-savani/bert-base-goemotions-ekman",
|
| 7 |
+
return_all_scores=True
|
| 8 |
+
)
|
| 9 |
|
| 10 |
def detect_emotions(text):
|
| 11 |
results = classifier(text)[0]
|
| 12 |
+
return {r['label']: round(r['score'], 3) for r in sorted(results, key=lambda x: x["score"], reverse=True)}
|
|
|
|
| 13 |
|
| 14 |
demo = gr.Interface(
|
| 15 |
fn=detect_emotions,
|
| 16 |
inputs=gr.Textbox(lines=4, placeholder="Enter a tweet or comment..."),
|
| 17 |
outputs="label",
|
| 18 |
title="Emotion Detection with BERT (GoEmotions)",
|
| 19 |
+
description="Detect joy, sadness, anger, and more using BERT trained on GoEmotions."
|
| 20 |
)
|
| 21 |
|
| 22 |
demo.launch()
|