Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
| 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 |
-
|
| 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)
|
|
|