first-space / app.py
hahongchul's picture
Update app.py
b6d78e4 verified
import gradio as gr
RESPONSES = {
"hello": "μ•ˆλ…•ν•˜μ„Έμš”! 무엇을 λ„μ™€λ“œλ¦΄κΉŒμš”?",
"가격": "가격 μ •λ³΄λŠ” 아직 μ€€λΉ„ μ€‘μ΄μ—μš”.",
}
def normalize_message(msg):
if msg is None:
return ""
if isinstance(msg, dict) and "content" in msg:
return str(msg["content"])
if isinstance(msg, (list, tuple)):
try:
last = msg[-1]
if isinstance(last, dict) and "content" in last:
return str(last["content"])
except Exception:
pass
return " ".join(map(str, msg))
return str(msg)
def echo(message, history):
text = normalize_message(message).strip()
low = text.lower()
for k, v in RESPONSES.items():
if k.lower() in low:
return v
return f"(에코) {text}"
demo = gr.ChatInterface(
fn=echo,
type="messages", # λ©”μ‹œμ§€ 포맷 λ§žμΆ”κΈ°
chatbot=gr.Chatbot(type="messages", height=420, show_copy_button=True),
autofocus=True,
)
if __name__ == "__main__":
demo.launch(server_name="0.0.0.0", server_port=7860)