Spaces:
Sleeping
Sleeping
Commit
·
c960e90
1
Parent(s):
d94ce60
added script for multi-user
Browse files- .github/workflows/github-actions-checkfile.yml +16 -0
- .github/workflows/github-actions-huggingface.yml +20 -0
- .gitignore +0 -0
- README.md +1 -1
- app.py +110 -0
- archive/app_backup.py +84 -0
- bin/clean.sh +5 -0
- requirements.txt +74 -0
.github/workflows/github-actions-checkfile.yml
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Check file size
|
2 |
+
on: # or directly `on: [push]` to run the action on every push on any branch
|
3 |
+
pull_request:
|
4 |
+
branches: [main]
|
5 |
+
|
6 |
+
# to run this workflow manually from the Actions tab
|
7 |
+
workflow_dispatch:
|
8 |
+
|
9 |
+
jobs:
|
10 |
+
sync-to-hub:
|
11 |
+
runs-on: ubuntu-latest
|
12 |
+
steps:
|
13 |
+
- name: Check large files
|
14 |
+
uses: ActionsDesk/[email protected]
|
15 |
+
with:
|
16 |
+
filesizelimit: 10485760 # this is 10MB so we can sync to HF Spaces
|
.github/workflows/github-actions-huggingface.yml
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Sync to Hugging Face hub
|
2 |
+
on:
|
3 |
+
push:
|
4 |
+
branches: [main]
|
5 |
+
|
6 |
+
# to run this workflow manually from the Actions tab
|
7 |
+
workflow_dispatch:
|
8 |
+
|
9 |
+
jobs:
|
10 |
+
sync-to-hub:
|
11 |
+
runs-on: ubuntu-latest
|
12 |
+
steps:
|
13 |
+
- uses: actions/checkout@v3
|
14 |
+
with:
|
15 |
+
fetch-depth: 0
|
16 |
+
lfs: true
|
17 |
+
- name: Push to hub
|
18 |
+
env:
|
19 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
20 |
+
run: git push https://lingyit1108:[email protected]/spaces/lingyit1108/akinator_multi_user main
|
.gitignore
ADDED
File without changes
|
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
emoji: 💬
|
4 |
colorFrom: blue
|
5 |
colorTo: yellow
|
|
|
1 |
---
|
2 |
+
title: akinator_multi_user
|
3 |
emoji: 💬
|
4 |
colorFrom: blue
|
5 |
colorTo: yellow
|
app.py
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
def clear_state():
|
16 |
+
print("clear_state")
|
17 |
+
return 1, False
|
18 |
+
|
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)
|
72 |
+
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,
|
80 |
+
container=False,
|
81 |
+
scale=2
|
82 |
+
)
|
83 |
+
drop_down_ls = gr.Dropdown(choices=["en", "en_animals", "en_objects"],
|
84 |
+
value="en",
|
85 |
+
label="Game Mode")
|
86 |
+
|
87 |
+
chat = gr.ChatInterface(
|
88 |
+
fn=fetch_response,
|
89 |
+
textbox=input_textbox,
|
90 |
+
examples=[["start"], ["yes"], ["no"], ["i don't know"], ["probably"], ["probably not"], ["back"]],
|
91 |
+
retry_btn=retry_button,
|
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()
|
107 |
+
|
108 |
+
if __name__ == "__main__":
|
109 |
+
|
110 |
+
demo.launch()
|
archive/app_backup.py
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
game_ended = False
|
11 |
+
|
12 |
+
def clear_state():
|
13 |
+
global count, to_verify
|
14 |
+
count = 0
|
15 |
+
to_verify = False
|
16 |
+
|
17 |
+
def change_game_type(value):
|
18 |
+
global game_type
|
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,
|
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]
|
75 |
+
)
|
76 |
+
|
77 |
+
with gr.Blocks(fill_height=True) as demo:
|
78 |
+
chat.render()
|
79 |
+
clear_button.click(fn=clear_state)
|
80 |
+
drop_down_ls.input(fn=change_game_type, inputs=[drop_down_ls])
|
81 |
+
|
82 |
+
if __name__ == "__main__":
|
83 |
+
|
84 |
+
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
|