Spaces:
Sleeping
Sleeping
| 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) |