File size: 1,086 Bytes
d16b710
 
 
8b0a5a0
d4b2ef5
d16b710
 
d4b2ef5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8b0a5a0
1696bd5
8b0a5a0
09b2c1d
1696bd5
 
 
b6d78e4
d4b2ef5
1696bd5
 
d16b710
1696bd5
b6d78e4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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)