lingyit1108 commited on
Commit
e3f3029
·
1 Parent(s): 77b9516

modify app.py file to accommodate 1 step ahead issue from orchestrator function

Browse files
Files changed (1) hide show
  1. app.py +62 -46
app.py CHANGED
@@ -11,6 +11,7 @@ count = gr.State(value=1)
11
  to_verify = gr.State(value=False)
12
  game_type = gr.State(value="en")
13
  game_ended = gr.State(value=False)
 
14
 
15
  def clear_state():
16
  print("clear_state")
@@ -19,53 +20,67 @@ def clear_state():
19
  def change_game_type(drop_down_value):
20
  return drop_down_value
21
 
22
- def orchestrate_game_state(message, count, to_verify, game_ended):
 
23
  time.sleep(1.5)
24
- if message == "start":
25
- count += 1
26
- game_ended = False
27
- elif (aki.progression <= 80) and (message == "back") and (not game_ended):
28
- count -= 1
29
- elif (aki.progression <= 80) and (not game_ended):
30
- count += 1
31
- elif to_verify and (message in ["yes", "no"]) and (not game_ended):
32
- game_ended = True
33
- elif (not game_ended):
34
- count += 1
35
- to_verify = True
 
 
 
 
 
 
 
 
36
 
37
- print("orchestrate_game_state", message, count, to_verify, game_ended)
38
- return count, to_verify, game_ended
39
 
40
- async def fetch_response(message, history, drop_down_value, count, to_verify, game_type, game_ended):
41
 
42
- print("fetch_response", message, drop_down_value, count, to_verify, game_type, game_ended)
43
- if message == "start":
44
- q = await aki.start_game(
45
- language=game_type,
46
- child_mode=True
47
- )
48
- q = f"{count}. " + q
49
- elif (aki.progression <= 80) and (message == "back") and (not game_ended):
50
- try:
51
- q = await aki.back()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  q = f"{count}. " + q
53
- except akinator.CantGoBackAnyFurther:
54
- pass
55
- elif (aki.progression <= 80) and (not game_ended):
56
- q = await aki.answer(message)
57
- q = f"{count}. " + q
58
- elif to_verify and message == "yes" and (not game_ended):
59
- q = "Yay!!"
60
- elif to_verify and message == "no" and (not game_ended):
61
- q = "Oof.."
62
- elif (not game_ended):
63
- await aki.win()
64
- q = f"It's {aki.first_guess['name']} ({aki.first_guess['description']})! Was I correct?\n{aki.first_guess['absolute_picture_path']}\n\t"
65
- q = f"{count}. " + q
66
- elif game_ended:
67
- q = "The game has ended. To replay, enter `start` again."
68
- return q
69
 
70
  retry_button = gr.Button("Retry", interactive=False)
71
  undo_button = gr.Button("Undo", interactive=False)
@@ -73,7 +88,8 @@ clear_button = gr.Button("Clear")
73
  submit_button = gr.Button("Submit")
74
  input_textbox = gr.Textbox(
75
  placeholder=(
76
- "To play, click [start] and submit. If you answer me genuinely, "
 
77
  "and I will guess what is in your mind :)"
78
  ),
79
  interactive=False,
@@ -92,15 +108,15 @@ chat = gr.ChatInterface(
92
  undo_btn=undo_button,
93
  clear_btn=clear_button,
94
  submit_btn=submit_button,
95
- additional_inputs=[drop_down_ls, count, to_verify, game_type, game_ended]
96
  )
97
 
98
  with gr.Blocks(fill_height=True) as demo:
99
  clear_button.click(fn=clear_state, inputs=None, outputs=[count, to_verify])
100
  drop_down_ls.input(fn=change_game_type, inputs=[drop_down_ls], outputs=[game_type])
101
  submit_button.click(fn=orchestrate_game_state,
102
- inputs=[input_textbox, count, to_verify, game_ended],
103
- outputs=[count, to_verify, game_ended],
104
  trigger_mode="always_last")
105
 
106
  chat.render()
 
11
  to_verify = gr.State(value=False)
12
  game_type = gr.State(value="en")
13
  game_ended = gr.State(value=False)
14
+ last_call = gr.State(value=False)
15
 
16
  def clear_state():
17
  print("clear_state")
 
20
  def change_game_type(drop_down_value):
21
  return drop_down_value
22
 
23
+ def orchestrate_game_state(message, count, to_verify, last_call, game_ended):
24
+
25
  time.sleep(1.5)
26
+ if aki.progression is not None or message == "start":
27
+ if message == "start":
28
+ count_add_one = count + 1
29
+ count = 2 if count > 2 else count_add_one
30
+ game_ended = False
31
+ elif (aki.progression <= 80) and (message == "back") and (not game_ended):
32
+ count -= 1
33
+ to_verify = False
34
+ elif (aki.progression <= 80) and (not game_ended):
35
+ count += 1
36
+ to_verify = False
37
+ elif to_verify and (message in ["yes", "no"]) and (not game_ended):
38
+ game_ended = True
39
+ elif (not game_ended) and not last_call:
40
+ count += 1
41
+ last_call = True
42
+ elif (not game_ended) and last_call:
43
+ count += 1
44
+ to_verify = True
45
+ last_call = False
46
 
47
+ print("orchestrate_game_state", aki.progression, message, count, to_verify, last_call, game_ended)
48
+ return count, to_verify, last_call, game_ended
49
 
50
+ async def fetch_response(message, history, drop_down_value, count, to_verify, last_call, game_type, game_ended):
51
 
52
+ print("fetch_response", message, drop_down_value, count, to_verify, last_call, game_type, game_ended)
53
+ if aki.progression is not None or message == "start":
54
+ if message == "start":
55
+ count = 1 if count > 1 else count
56
+ q = await aki.start_game(
57
+ language=game_type,
58
+ child_mode=True
59
+ )
60
+ q = f"{count}. " + q
61
+ elif (aki.progression <= 80) and (message == "back") and (not game_ended):
62
+ try:
63
+ q = await aki.back()
64
+ q = f"{count}. " + q
65
+ except akinator.CantGoBackAnyFurther:
66
+ pass
67
+ elif (aki.progression <= 80) and (not game_ended):
68
+ q = await aki.answer(message)
69
+ q = f"{count}. " + q
70
+ elif to_verify and message == "yes" and (not game_ended):
71
+ q = "Yay!!"
72
+ elif to_verify and message == "no" and (not game_ended):
73
+ q = "Oof.."
74
+ elif (not game_ended) and not last_call:
75
+ q = await aki.answer(message)
76
+ q = f"{count}. " + q
77
+ elif (not game_ended) and last_call:
78
+ await aki.win()
79
+ q = f"It's {aki.first_guess['name']} ({aki.first_guess['description']})! Was I correct?\n{aki.first_guess['absolute_picture_path']}\n\t"
80
  q = f"{count}. " + q
81
+ elif game_ended:
82
+ q = "The game has ended. To replay, enter `start` again."
83
+ return q
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
  retry_button = gr.Button("Retry", interactive=False)
86
  undo_button = gr.Button("Undo", interactive=False)
 
88
  submit_button = gr.Button("Submit")
89
  input_textbox = gr.Textbox(
90
  placeholder=(
91
+ "To play, click [start] and submit. "
92
+ "Thereafter, answer me genuinely 😉, "
93
  "and I will guess what is in your mind :)"
94
  ),
95
  interactive=False,
 
108
  undo_btn=undo_button,
109
  clear_btn=clear_button,
110
  submit_btn=submit_button,
111
+ additional_inputs=[drop_down_ls, count, to_verify, last_call, game_type, game_ended]
112
  )
113
 
114
  with gr.Blocks(fill_height=True) as demo:
115
  clear_button.click(fn=clear_state, inputs=None, outputs=[count, to_verify])
116
  drop_down_ls.input(fn=change_game_type, inputs=[drop_down_ls], outputs=[game_type])
117
  submit_button.click(fn=orchestrate_game_state,
118
+ inputs=[input_textbox, count, to_verify, last_call, game_ended],
119
+ outputs=[count, to_verify, last_call, game_ended],
120
  trigger_mode="always_last")
121
 
122
  chat.render()