muhnatha commited on
Commit
cb21aac
·
verified ·
1 Parent(s): 3940560

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -13
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
- return "YOU WON",emotion,pred_emotion[0]['label']
21
  else:
22
- return "YOU LOSE",emotion,pred_emotion[0]['label']
 
 
 
 
 
23
 
24
- iface = gr.Interface(
25
- fn=actor_game,
26
- inputs=[gr.Textbox(label=task[1]),
27
- gr.Textbox(task[0],visible=False)],
28
- outputs=[gr.Textbox(label="Result"),gr.Textbox(label="Expected"),gr.Textbox(label="your emotion")],
29
- title="Be an Actor",
30
- description="Type your dialog",
31
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
- iface.launch()
 
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()