yoon-gu commited on
Commit
039d478
β€’
1 Parent(s): ef80d5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -1,23 +1,21 @@
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)
@@ -31,21 +29,24 @@ with gr.Blocks() as demo:
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
-
 
 
 
 
1
  import gradio as gr
2
+ import pyjosa
3
  from pyjosa.josa import Josa
4
  import random
5
  import json
6
 
7
  with open('pokemon.json', 'r') as f:
8
  pokemons = json.load(f)
9
+
10
  QUESTION_TEMPLATE = {"question": "λ‹€μŒ 포켓λͺ¬μ˜ 이름은 λ­˜κΉŒμš”?![]({img_url})", "answer": "{name}"}
11
  with gr.Blocks() as demo:
12
  quiz_start = gr.State(value=False)
13
  answer = gr.State(value="")
14
  chatbot = gr.Chatbot(bubble_full_width=False)
15
+ msg = gr.Textbox(value="ν€΄μ¦ˆ μ‹œμž‘")
16
  clear = gr.ClearButton([msg, chatbot])
17
+
18
+
19
  def respond(message, chat_history):
20
  if not quiz_start.value:
21
  chosen = random.choice(pokemons)
 
29
  else:
30
  bot_message = "ν€΄μ¦ˆλ₯Ό μ‹œμž‘ν•˜κ³  μ‹ΆμœΌμ‹œλ©΄, **ν€΄μ¦ˆ μ‹œμž‘**이라고 λ§μ”€ν•΄μ£Όμ„Έμš”."
31
  else:
 
32
  if answer.value == message:
33
  chosen = random.choice(pokemons)
34
  name = chosen['name']
35
  image_path = chosen['image_path']
36
  answer.value = QUESTION_TEMPLATE['answer'].format(name=name)
37
  img_url = f"https://huggingface.co/spaces/yoon-gu/pokemon/resolve/main/{image_path}"
38
+ bot_message = "πŸŽ‰μ •λ‹΅μž…λ‹ˆλ‹€! λ‹€μŒ λ¬Έμ œμž…λ‹ˆλ‹€." + QUESTION_TEMPLATE["question"].format(img_url=img_url)
39
  else:
40
+ try:
41
+ trial = Josa.get_full_string(message, "λŠ”")
42
+ except pyjosa.exceptions.NotHangleException:
43
+ trial = f"{message}!?"
44
+ bot_message = f"***{trial}*** μ •λ‹΅μΌκΉŒμš”? 🧐 λ‹€μ‹œ ν•œλ²ˆ μƒκ°ν•΄λ³΄μ„Έμš”."
45
+
46
  chat_history.append((message, bot_message))
47
  return "", chat_history
48
+
49
  msg.submit(respond, [msg, chatbot], [msg, chatbot])
50
 
51
+ demo.queue(concurrency_count=3)
52
+ demo.launch()