Spaces:
Build error
Build error
| import gradio as gr | |
| import requests | |
| WEBHOOK_URL = "https://n8n.smartid.or.id/webhook/chatbot" | |
| def chatbot_fn(message, history): | |
| try: | |
| response = requests.post( | |
| WEBHOOK_URL, | |
| json={"message": message}, | |
| timeout=10 | |
| ) | |
| if response.status_code == 200: | |
| reply = response.json().get("output", "").strip() | |
| if not reply: | |
| reply = "Maaf, tidak ada balasan dari server." | |
| else: | |
| reply = f"[Error {response.status_code}]" | |
| except Exception as e: | |
| reply = f"[Exception] {str(e)}" | |
| return reply | |
| chatbot = gr.ChatInterface( | |
| fn=chatbot_fn, | |
| chatbot=gr.Chatbot(height=500, type="messages"), | |
| textbox=gr.Textbox(placeholder="Tulis pertanyaan Anda..."), | |
| submit_btn="Kirim" | |
| ) |