Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
import random
|
4 |
+
|
5 |
+
pipe = pipeline("text-classification", model="muhnatha/distilbert-base-uncased-game")
|
6 |
+
|
7 |
+
question = {
|
8 |
+
"sadness": "Be a student who just had a bad grade",
|
9 |
+
"joy": "Be a football player who just won the world cup",
|
10 |
+
"love": "Be a teenager who has a crush but she can only talk to her friend",
|
11 |
+
"anger": "Be a student who angry because he was bullied",
|
12 |
+
"fear": "Be a grandpa who tries to run away because there is an alien in his farm",
|
13 |
+
"surprise": "Be a child who just got a birthday surprise"
|
14 |
+
}
|
15 |
+
task = random.choice(list(question.items()))
|
16 |
+
|
17 |
+
def actor_game(text, emotion):
|
18 |
+
pred_emotion = pipe(text)
|
19 |
+
if pred_emotion[0]['label'] == emotion:
|
20 |
+
return "YOU WON"
|
21 |
+
else:
|
22 |
+
return "YOU LOSE"
|
23 |
+
|
24 |
+
iface = gr.Interface(
|
25 |
+
fn=actor_game,
|
26 |
+
inputs=[gr.Textbox(label="Your dialog"),
|
27 |
+
gr.Textbox(task[0],visible=False)],
|
28 |
+
outputs=[gr.Textbox(label=task[1])],
|
29 |
+
title="Be an Actor",
|
30 |
+
description="Type your dialog",
|
31 |
+
)
|
32 |
+
|
33 |
+
iface.launch()
|