Spaces:
Sleeping
Sleeping
lingyit1108
commited on
Commit
•
1c5149a
1
Parent(s):
8e50102
to have verification scene to kick in
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ aki = Akinator()
|
|
7 |
game_type = "en"
|
8 |
count = 0
|
9 |
to_verify = False
|
|
|
10 |
|
11 |
def clear_state():
|
12 |
global count, to_verify
|
@@ -18,39 +19,47 @@ def change_game_type(value):
|
|
18 |
game_type = value
|
19 |
|
20 |
async def fetch_response(message, history, value):
|
21 |
-
global count, to_verify, game_type
|
22 |
-
count += 1
|
23 |
if message == "start":
|
24 |
q = await aki.start_game(
|
25 |
language=game_type,
|
26 |
child_mode=True
|
27 |
)
|
|
|
|
|
|
|
28 |
q = f"{count}. " + q
|
29 |
-
elif (aki.progression <= 80) and (message == "back"):
|
30 |
try:
|
31 |
-
q = await aki.back()
|
32 |
count -= 1
|
|
|
33 |
q = f"{count}. " + q
|
34 |
except akinator.CantGoBackAnyFurther:
|
35 |
pass
|
36 |
-
elif aki.progression <= 80:
|
|
|
37 |
q = await aki.answer(message)
|
38 |
q = f"{count}. " + q
|
39 |
-
elif to_verify and message == "yes":
|
40 |
q = "Yay!!"
|
41 |
-
|
42 |
-
elif to_verify and message == "
|
43 |
q = "Oof.."
|
44 |
-
|
45 |
-
|
46 |
await aki.win()
|
|
|
47 |
q = f"It's {aki.first_guess['name']} ({aki.first_guess['description']})! Was I correct?\n{aki.first_guess['absolute_picture_path']}\n\t"
|
48 |
q = f"{count}. " + q
|
49 |
-
|
|
|
|
|
50 |
return q
|
51 |
|
52 |
clear_button = gr.Button("Clear")
|
53 |
-
drop_down_ls = gr.Dropdown(choices=["en", "en_animals", "en_objects"],
|
|
|
|
|
54 |
|
55 |
chat = gr.ChatInterface(
|
56 |
fn=fetch_response,
|
|
|
7 |
game_type = "en"
|
8 |
count = 0
|
9 |
to_verify = False
|
10 |
+
game_ended = False
|
11 |
|
12 |
def clear_state():
|
13 |
global count, to_verify
|
|
|
19 |
game_type = value
|
20 |
|
21 |
async def fetch_response(message, history, value):
|
22 |
+
global count, to_verify, game_type, game_ended
|
|
|
23 |
if message == "start":
|
24 |
q = await aki.start_game(
|
25 |
language=game_type,
|
26 |
child_mode=True
|
27 |
)
|
28 |
+
clear_state()
|
29 |
+
count += 1
|
30 |
+
game_ended = False
|
31 |
q = f"{count}. " + q
|
32 |
+
elif (aki.progression <= 80) and (message == "back") and (not game_ended):
|
33 |
try:
|
|
|
34 |
count -= 1
|
35 |
+
q = await aki.back()
|
36 |
q = f"{count}. " + q
|
37 |
except akinator.CantGoBackAnyFurther:
|
38 |
pass
|
39 |
+
elif (aki.progression <= 80) and (not game_ended):
|
40 |
+
count += 1
|
41 |
q = await aki.answer(message)
|
42 |
q = f"{count}. " + q
|
43 |
+
elif to_verify and message == "yes" and (not game_ended):
|
44 |
q = "Yay!!"
|
45 |
+
game_ended = True
|
46 |
+
elif to_verify and message == "no" and (not game_ended):
|
47 |
q = "Oof.."
|
48 |
+
game_ended = True
|
49 |
+
elif (not game_ended):
|
50 |
await aki.win()
|
51 |
+
count += 1
|
52 |
q = f"It's {aki.first_guess['name']} ({aki.first_guess['description']})! Was I correct?\n{aki.first_guess['absolute_picture_path']}\n\t"
|
53 |
q = f"{count}. " + q
|
54 |
+
to_verify = True
|
55 |
+
elif game_ended:
|
56 |
+
q = "The game has ended. To replay, enter `start` again."
|
57 |
return q
|
58 |
|
59 |
clear_button = gr.Button("Clear")
|
60 |
+
drop_down_ls = gr.Dropdown(choices=["en", "en_animals", "en_objects"],
|
61 |
+
value="en",
|
62 |
+
label="Game Mode")
|
63 |
|
64 |
chat = gr.ChatInterface(
|
65 |
fn=fetch_response,
|