lingyit1108 commited on
Commit
ed2bcfc
1 Parent(s): 1c5149a

tidy up placeholder messaage

Browse files
Files changed (2) hide show
  1. app.py +6 -1
  2. archive/app_backup.py +107 -0
app.py CHANGED
@@ -63,7 +63,12 @@ drop_down_ls = gr.Dropdown(choices=["en", "en_animals", "en_objects"],
63
 
64
  chat = gr.ChatInterface(
65
  fn=fetch_response,
66
- textbox=gr.Textbox(placeholder="Ask me a yes or no question", container=False, scale=7),
 
 
 
 
 
67
  examples=[["start"], ["yes"], ["no"], ["i don't know"], ["probably"], ["probably not"], ["back"]],
68
  clear_btn=clear_button,
69
  additional_inputs=[drop_down_ls]
 
63
 
64
  chat = gr.ChatInterface(
65
  fn=fetch_response,
66
+ textbox=gr.Textbox(
67
+ placeholder=(
68
+ "Send `start` to start the game and answer me genuinely, "
69
+ "I will guess what is in your mind :)"
70
+ ),
71
+ container=False, scale=7),
72
  examples=[["start"], ["yes"], ["no"], ["i don't know"], ["probably"], ["probably not"], ["back"]],
73
  clear_btn=clear_button,
74
  additional_inputs=[drop_down_ls]
archive/app_backup.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from akinator.async_aki import Akinator
4
+ import akinator
5
+ import time
6
+
7
+ aki = Akinator()
8
+
9
+ ### gradio state variables
10
+ 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
+
16
+ def clear_state():
17
+ print("clear_state")
18
+ return 0, False
19
+
20
+ def change_game_type(drop_down_value):
21
+ return drop_down_value
22
+
23
+ def orchestrate_game_state(message, count, to_verify, game_ended):
24
+ time.sleep(1)
25
+ if message == "start":
26
+ count += 1
27
+ game_ended = False
28
+ elif (aki.progression <= 80) and (message == "back") and (not game_ended):
29
+ count -= 1
30
+ elif (aki.progression <= 80) and (not game_ended):
31
+ count += 1
32
+ elif to_verify and (message in ["yes", "no"]) and (not game_ended):
33
+ game_ended = True
34
+ elif (not game_ended):
35
+ count += 1
36
+ to_verify = True
37
+
38
+ print("orchestrate_game_state", message, count, to_verify, game_ended)
39
+ return count, to_verify, game_ended
40
+
41
+ async def fetch_response(message, history, drop_down_value, count, to_verify, game_type, game_ended):
42
+
43
+ print("fetch_response", message, drop_down_value, count, to_verify, game_type, game_ended)
44
+ if message == "start":
45
+ q = await aki.start_game(
46
+ language=game_type,
47
+ child_mode=True
48
+ )
49
+ q = f"{count}. " + q
50
+ elif (aki.progression <= 80) and (message == "back") and (not game_ended):
51
+ try:
52
+ q = await aki.back()
53
+ q = f"{count}. " + q
54
+ except akinator.CantGoBackAnyFurther:
55
+ pass
56
+ elif (aki.progression <= 80) and (not game_ended):
57
+ q = await aki.answer(message)
58
+ q = f"{count}. " + q
59
+ elif to_verify and message == "yes" and (not game_ended):
60
+ q = "Yay!!"
61
+ elif to_verify and message == "no" and (not game_ended):
62
+ q = "Oof.."
63
+ elif (not game_ended):
64
+ await aki.win()
65
+ q = f"It's {aki.first_guess['name']} ({aki.first_guess['description']})! Was I correct?\n{aki.first_guess['absolute_picture_path']}\n\t"
66
+ q = f"{count}. " + q
67
+ elif game_ended:
68
+ q = "The game has ended. To replay, enter `start` again."
69
+ return q
70
+
71
+ clear_button = gr.Button("Clear")
72
+ submit_button = gr.Button("Submit")
73
+ input_textbox = gr.Textbox(
74
+ placeholder=(
75
+ "To play, click [start] and submit. If you answer me genuinely, "
76
+ "and I will guess what is in your mind :)"
77
+ ),
78
+ interactive=False,
79
+ container=False,
80
+ scale=2
81
+ )
82
+ drop_down_ls = gr.Dropdown(choices=["en", "en_animals", "en_objects"],
83
+ value="en",
84
+ label="Game Mode")
85
+
86
+ chat = gr.ChatInterface(
87
+ fn=fetch_response,
88
+ textbox=input_textbox,
89
+ examples=[["start"], ["yes"], ["no"], ["i don't know"], ["probably"], ["probably not"], ["back"]],
90
+ clear_btn=clear_button,
91
+ submit_btn=submit_button,
92
+ additional_inputs=[drop_down_ls, count, to_verify, game_type, game_ended]
93
+ )
94
+
95
+ with gr.Blocks(fill_height=True) as demo:
96
+ clear_button.click(fn=clear_state, inputs=None, outputs=[count, to_verify])
97
+ drop_down_ls.input(fn=change_game_type, inputs=[drop_down_ls], outputs=[game_type])
98
+ submit_button.click(fn=orchestrate_game_state,
99
+ inputs=[input_textbox, count, to_verify, game_ended],
100
+ outputs=[count, to_verify, game_ended],
101
+ trigger_mode="always_last")
102
+
103
+ chat.render()
104
+
105
+ if __name__ == "__main__":
106
+
107
+ demo.launch()