Spaces:
Build error
Build error
Commit
·
f330e98
1
Parent(s):
152e4dc
Upload 2 files
Browse files- app.py +24 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
classifier = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base", return_all_scores=True)
|
| 6 |
+
|
| 7 |
+
def fn_emotion(text):
|
| 8 |
+
results = classifier(text, padding='max_length', max_length=512)
|
| 9 |
+
return {label['label']: [label['score']] for label in results[0]}
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
with gr.Blocks(title="Emotion",css="footer {visibility: hidden}") as demo:
|
| 14 |
+
with gr.Row():
|
| 15 |
+
with gr.Column():
|
| 16 |
+
gr.Markdown("## Sentence Emotion")
|
| 17 |
+
with gr.Row():
|
| 18 |
+
with gr.Column():
|
| 19 |
+
inputs = gr.TextArea(label="sentence",value=" I am so excited to go on vacation!",interactive=True)
|
| 20 |
+
btn = gr.Button(value="RUN")
|
| 21 |
+
with gr.Column():
|
| 22 |
+
output = gr.Label(label="output")
|
| 23 |
+
btn.click(fn=fn_emotion,inputs=[inputs],outputs=[output])
|
| 24 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==3.32.0
|
| 2 |
+
transformers==4.28.1
|