hahongchul commited on
Commit
09b2c1d
ยท
verified ยท
1 Parent(s): 744f001

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -15
app.py CHANGED
@@ -1,24 +1,16 @@
1
- import os
2
  import gradio as gr
3
 
4
- # --- ๊ฐ„๋‹จ ๊ทœ์น™ ์‚ฌ์ „ ---
5
  RESPONSES = {
6
  "hello": "์•ˆ๋…•ํ•˜์„ธ์š”! ๋ฌด์—‡์„ ๋„์™€๋“œ๋ฆด๊นŒ์š”?",
7
  "๊ฐ€๊ฒฉ": "๊ฐ€๊ฒฉ ์ •๋ณด๋Š” ์•„์ง ์ค€๋น„ ์ค‘์ด์—์š”.",
8
  }
9
 
10
  def normalize_message(msg):
11
- """
12
- Gradio/๋ฒ„์ „/ํƒ€์ž…์— ๋”ฐ๋ผ msg๊ฐ€ str, dict({'role','content'}), list์ผ ์ˆ˜ ์žˆ์Œ.
13
- ์–ด๋–ค ๊ฒฝ์šฐ๋„ ๋ฌธ์ž์—ด๋กœ ์•ˆ์ „ ๋ณ€ํ™˜.
14
- """
15
  if msg is None:
16
  return ""
17
  if isinstance(msg, dict) and "content" in msg:
18
  return str(msg["content"])
19
  if isinstance(msg, (list, tuple)):
20
- # messages ํƒ€์ž…์—์„œ ์‹ค์ˆ˜๋กœ ๋ฆฌ์ŠคํŠธ๋ฅผ ๋„˜๊ฒผ์„ ๊ฐ€๋Šฅ์„ฑ ๋Œ€๋น„
21
- # ๋งˆ์ง€๋ง‰ ํ•ญ๋ชฉ์˜ content๋ฅผ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜, ์ „์ฒด๋ฅผ ๋ฌธ์ž์—ดํ™”
22
  try:
23
  last = msg[-1]
24
  if isinstance(last, dict) and "content" in last:
@@ -28,20 +20,17 @@ def normalize_message(msg):
28
  return " ".join(map(str, msg))
29
  return str(msg)
30
 
31
- # ChatInterface๋Š” (message, history) ์ˆœ์„œ๋กœ ํ˜ธ์ถœ๋ฉ๋‹ˆ๋‹ค.
32
  def echo(message, history):
33
  text = normalize_message(message).strip()
34
  low = text.lower()
35
-
36
  for k, v in RESPONSES.items():
37
  if k.lower() in low:
38
  return v
39
-
40
- return f"(์—์ฝ”) {text if text else ''}"
41
 
42
  demo = gr.ChatInterface(
43
  fn=echo,
44
- # deprecated ๊ฒฝ๊ณ  ๋ฐฉ์ง€: messages ํƒ€์ž… ์‚ฌ์šฉ
45
  chatbot=gr.Chatbot(type="messages", height=420, show_copy_button=True),
46
  retry_btn="๋‹ค์‹œ ์ƒ์„ฑ",
47
  undo_btn="๋˜๋Œ๋ฆฌ๊ธฐ",
@@ -50,5 +39,4 @@ demo = gr.ChatInterface(
50
  )
51
 
52
  if __name__ == "__main__":
53
- # Spaces์—์„œ SSR์ด ์‹คํ—˜์ ์ด๋ผ ์ถฉ๋Œํ•  ๋•Œ๊ฐ€ ์žˆ์–ด ๋น„ํ™œ์„ฑํ™” ๊ถŒ์žฅ
54
- demo.launch(server_name="0.0.0.0", server_port=7860, ssr_mode=False)
 
 
1
  import gradio as gr
2
 
 
3
  RESPONSES = {
4
  "hello": "์•ˆ๋…•ํ•˜์„ธ์š”! ๋ฌด์—‡์„ ๋„์™€๋“œ๋ฆด๊นŒ์š”?",
5
  "๊ฐ€๊ฒฉ": "๊ฐ€๊ฒฉ ์ •๋ณด๋Š” ์•„์ง ์ค€๋น„ ์ค‘์ด์—์š”.",
6
  }
7
 
8
  def normalize_message(msg):
 
 
 
 
9
  if msg is None:
10
  return ""
11
  if isinstance(msg, dict) and "content" in msg:
12
  return str(msg["content"])
13
  if isinstance(msg, (list, tuple)):
 
 
14
  try:
15
  last = msg[-1]
16
  if isinstance(last, dict) and "content" in last:
 
20
  return " ".join(map(str, msg))
21
  return str(msg)
22
 
 
23
  def echo(message, history):
24
  text = normalize_message(message).strip()
25
  low = text.lower()
 
26
  for k, v in RESPONSES.items():
27
  if k.lower() in low:
28
  return v
29
+ return f"(์—์ฝ”) {text}"
 
30
 
31
  demo = gr.ChatInterface(
32
  fn=echo,
33
+ type="messages", # ์ตœ์‹  ํฌ๋งท
34
  chatbot=gr.Chatbot(type="messages", height=420, show_copy_button=True),
35
  retry_btn="๋‹ค์‹œ ์ƒ์„ฑ",
36
  undo_btn="๋˜๋Œ๋ฆฌ๊ธฐ",
 
39
  )
40
 
41
  if __name__ == "__main__":
42
+ demo.launch(server_name="0.0.0.0", server_port=7860)