Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,22 +12,41 @@ question = {
|
|
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 |
-
|
21 |
else:
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
-
|
|
|
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 |
|
16 |
+
def actor_game(text, emotion, play_again):
|
17 |
pred_emotion = pipe(text)
|
18 |
if pred_emotion[0]['label'] == emotion:
|
19 |
+
result = "YOU WON"
|
20 |
else:
|
21 |
+
result = "YOU LOSE"
|
22 |
+
if play_again.lower() == "yes":
|
23 |
+
task = random.choice(list(question.items()))
|
24 |
+
return result, emotion, pred_emotion[0]['label'], task[1], task[0]
|
25 |
+
else:
|
26 |
+
return result, emotion, pred_emotion[0]['label'], "Game Over", ""
|
27 |
|
28 |
+
def initialize_interface():
|
29 |
+
task = random.choice(list(question.items()))
|
30 |
+
iface = gr.Interface(
|
31 |
+
fn=actor_game,
|
32 |
+
inputs=[
|
33 |
+
gr.Textbox(label=task[1], lines=3),
|
34 |
+
gr.Textbox(label="Expected", value=task[0], visible=False),
|
35 |
+
gr.Radio(["Yes", "No"], label="Do you want to play again?")
|
36 |
+
],
|
37 |
+
outputs=[
|
38 |
+
gr.Textbox(label="Result"),
|
39 |
+
gr.Textbox(label="Expected"),
|
40 |
+
gr.Textbox(label="Your emotion"),
|
41 |
+
gr.Textbox(label="Next scenario"),
|
42 |
+
gr.Textbox(label="Next emotion", visible=False)
|
43 |
+
],
|
44 |
+
title="Be an Actor",
|
45 |
+
description="Type your dialog",
|
46 |
+
allow_flagging="never"
|
47 |
+
)
|
48 |
+
response = iface.launch()
|
49 |
+
if response[2] == "yes": # Check if user wants to play again
|
50 |
+
initialize_interface() # Restart the game
|
51 |
|
52 |
+
initialize_interface()
|