Upload 2 files
Browse files- app.py +51 -0
- pokemon.json +0 -0
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.system("pip install gradio --upgrade")
|
3 |
+
|
4 |
+
import gradio as gr
|
5 |
+
from pyjosa.josa import Josa
|
6 |
+
import random
|
7 |
+
import json
|
8 |
+
|
9 |
+
with open('pokemon.json', 'r') as f:
|
10 |
+
pokemons = json.load(f)
|
11 |
+
|
12 |
+
QUESTION_TEMPLATE = {"question": "๋ค์ ํฌ์ผ๋ชฌ์ ์ด๋ฆ์ ๋ญ๊น์?![]({img_url})", "answer": "{name}"}
|
13 |
+
with gr.Blocks() as demo:
|
14 |
+
quiz_start = gr.State(value=False)
|
15 |
+
answer = gr.State(value="")
|
16 |
+
chatbot = gr.Chatbot(bubble_full_width=False)
|
17 |
+
msg = gr.Textbox()
|
18 |
+
clear = gr.ClearButton([msg, chatbot])
|
19 |
+
|
20 |
+
|
21 |
+
def respond(message, chat_history):
|
22 |
+
if not quiz_start.value:
|
23 |
+
chosen = random.choice(pokemons)
|
24 |
+
name = chosen['name']
|
25 |
+
image_path = chosen['image_path']
|
26 |
+
answer.value = QUESTION_TEMPLATE['answer'].format(name=name)
|
27 |
+
img_url = f"https://huggingface.co/spaces/yoon-gu/pokemon/resolve/main/{image_path}"
|
28 |
+
if "ํด์ฆ ์์" == message:
|
29 |
+
bot_message = "ํด์ฆ๋ฅผ ์์ํฉ๋๋ค.\n" + QUESTION_TEMPLATE["question"].format(img_url=img_url)
|
30 |
+
quiz_start.value = True
|
31 |
+
else:
|
32 |
+
bot_message = "ํด์ฆ๋ฅผ ์์ํ๊ณ ์ถ์ผ์๋ฉด, **ํด์ฆ ์์**์ด๋ผ๊ณ ๋ง์ํด์ฃผ์ธ์."
|
33 |
+
else:
|
34 |
+
trial = Josa.get_full_string(message, "๋")
|
35 |
+
if answer.value == message:
|
36 |
+
chosen = random.choice(pokemons)
|
37 |
+
name = chosen['name']
|
38 |
+
image_path = chosen['image_path']
|
39 |
+
answer.value = QUESTION_TEMPLATE['answer'].format(name=name)
|
40 |
+
img_url = f"https://huggingface.co/spaces/yoon-gu/pokemon/resolve/main/{image_path}"
|
41 |
+
bot_message = "์ ๋ต์
๋๋ค! ๋ค์ ๋ฌธ์ ์
๋๋ค." + QUESTION_TEMPLATE["question"].format(img_url=img_url)
|
42 |
+
else:
|
43 |
+
bot_message = f"{trial} ์ ๋ต์ผ๊น์? ๋ค์ ํ๋ฒ ์๊ฐํด๋ณด์ธ์."
|
44 |
+
|
45 |
+
chat_history.append((message, bot_message))
|
46 |
+
return "", chat_history
|
47 |
+
|
48 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
49 |
+
|
50 |
+
demo.launch()
|
51 |
+
|
pokemon.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|