Spaces:
Sleeping
Sleeping
lingyit1108
commited on
Commit
·
a2e1faa
1
Parent(s):
451dca4
added all scripts
Browse files- .gitignore +0 -0
- app.py +69 -0
- bin/clean.sh +5 -0
- requirements.txt +74 -0
.gitignore
ADDED
File without changes
|
app.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from akinator.async_aki import Akinator
|
4 |
+
import akinator
|
5 |
+
|
6 |
+
aki = Akinator()
|
7 |
+
game_type = "en"
|
8 |
+
count = 0
|
9 |
+
to_verify = False
|
10 |
+
|
11 |
+
def clear_state():
|
12 |
+
global count, to_verify
|
13 |
+
count = 0
|
14 |
+
to_verify = False
|
15 |
+
|
16 |
+
def change_game_type(value):
|
17 |
+
global game_type
|
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 |
+
q = f"{count}. " + q
|
33 |
+
except akinator.CantGoBackAnyFurther:
|
34 |
+
pass
|
35 |
+
elif aki.progression <= 80:
|
36 |
+
q = await aki.answer(message)
|
37 |
+
q = f"{count}. " + q
|
38 |
+
elif to_verify and message == "yes":
|
39 |
+
q = "Yay!!"
|
40 |
+
clear_state()
|
41 |
+
elif to_verify and message == "yes":
|
42 |
+
q = "Oof.."
|
43 |
+
clear_state()
|
44 |
+
else:
|
45 |
+
await aki.win()
|
46 |
+
q = f"It's {aki.first_guess['name']} ({aki.first_guess['description']})! Was I correct?\n{aki.first_guess['absolute_picture_path']}\n\t"
|
47 |
+
q = f"{count}. " + q
|
48 |
+
|
49 |
+
return q
|
50 |
+
|
51 |
+
clear_button = gr.Button("Clear")
|
52 |
+
drop_down_ls = gr.Dropdown(choices=["en", "en_animals", "en_objects"], label="Game Mode")
|
53 |
+
|
54 |
+
chat = gr.ChatInterface(
|
55 |
+
fn=fetch_response,
|
56 |
+
textbox=gr.Textbox(placeholder="Ask me a yes or no question", container=False, scale=7),
|
57 |
+
examples=[["start"], ["yes"], ["no"], ["i don't know"], ["probably"], ["probably not"], ["back"]],
|
58 |
+
clear_btn=clear_button,
|
59 |
+
additional_inputs=[drop_down_ls]
|
60 |
+
)
|
61 |
+
|
62 |
+
with gr.Blocks(fill_height=True) as demo:
|
63 |
+
chat.render()
|
64 |
+
clear_button.click(fn=clear_state)
|
65 |
+
drop_down_ls.input(fn=change_game_type, inputs=[drop_down_ls])
|
66 |
+
|
67 |
+
if __name__ == "__main__":
|
68 |
+
|
69 |
+
demo.launch()
|
bin/clean.sh
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
find . -name __pycache__ | xargs rm -rf
|
4 |
+
find . -name .pytest_cache | xargs rm -rf
|
5 |
+
find . -name .ipynb_checkpoints | xargs rm -rf
|
requirements.txt
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
aiofiles==23.2.1
|
2 |
+
aiohttp==3.9.3
|
3 |
+
aiosignal==1.3.1
|
4 |
+
akinator==1.1.1
|
5 |
+
altair==5.2.0
|
6 |
+
annotated-types==0.6.0
|
7 |
+
anyio==4.3.0
|
8 |
+
async-timeout==4.0.3
|
9 |
+
attrs==23.2.0
|
10 |
+
certifi==2024.2.2
|
11 |
+
charset-normalizer==3.3.2
|
12 |
+
click==8.1.7
|
13 |
+
colorama==0.4.6
|
14 |
+
contourpy==1.2.0
|
15 |
+
cycler==0.12.1
|
16 |
+
exceptiongroup==1.2.0
|
17 |
+
fastapi==0.109.2
|
18 |
+
ffmpy==0.3.2
|
19 |
+
filelock==3.13.1
|
20 |
+
fonttools==4.49.0
|
21 |
+
frozenlist==1.4.1
|
22 |
+
fsspec==2024.2.0
|
23 |
+
gradio==4.19.1
|
24 |
+
gradio_client==0.10.0
|
25 |
+
h11==0.14.0
|
26 |
+
httpcore==1.0.3
|
27 |
+
httpx==0.26.0
|
28 |
+
huggingface-hub==0.20.3
|
29 |
+
idna==3.6
|
30 |
+
importlib-resources==6.1.1
|
31 |
+
Jinja2==3.1.3
|
32 |
+
jsonschema==4.21.1
|
33 |
+
jsonschema-specifications==2023.12.1
|
34 |
+
kiwisolver==1.4.5
|
35 |
+
markdown-it-py==3.0.0
|
36 |
+
MarkupSafe==2.1.5
|
37 |
+
matplotlib==3.8.3
|
38 |
+
mdurl==0.1.2
|
39 |
+
multidict==6.0.5
|
40 |
+
numpy==1.26.4
|
41 |
+
orjson==3.9.14
|
42 |
+
packaging==23.2
|
43 |
+
pandas==2.2.0
|
44 |
+
pillow==10.2.0
|
45 |
+
pydantic==2.6.1
|
46 |
+
pydantic_core==2.16.2
|
47 |
+
pydub==0.25.1
|
48 |
+
Pygments==2.17.2
|
49 |
+
pyparsing==3.1.1
|
50 |
+
python-dateutil==2.8.2
|
51 |
+
python-multipart==0.0.9
|
52 |
+
pytz==2024.1
|
53 |
+
PyYAML==6.0.1
|
54 |
+
referencing==0.33.0
|
55 |
+
requests==2.31.0
|
56 |
+
rich==13.7.0
|
57 |
+
rpds-py==0.18.0
|
58 |
+
ruff==0.2.2
|
59 |
+
semantic-version==2.10.0
|
60 |
+
shellingham==1.5.4
|
61 |
+
six==1.16.0
|
62 |
+
sniffio==1.3.0
|
63 |
+
starlette==0.36.3
|
64 |
+
tomlkit==0.12.0
|
65 |
+
toolz==0.12.1
|
66 |
+
tqdm==4.66.2
|
67 |
+
typer==0.9.0
|
68 |
+
typing_extensions==4.9.0
|
69 |
+
tzdata==2024.1
|
70 |
+
urllib3==2.2.1
|
71 |
+
uvicorn==0.27.1
|
72 |
+
websockets==11.0.3
|
73 |
+
yarl==1.9.4
|
74 |
+
zipp==3.17.0
|