import gradio as gr import requests # ✅ Correct Rasa backend URL including REST webhook path RASA_BACKEND = "https://web-production-37bcd.up.railway.app/webhooks/rest/webhook" def chat_with_rasa(message, chat_history): payload = { "sender": "user", # or any unique ID per session "message": message } try: response = requests.post(RASA_BACKEND, json=payload, timeout=10) response.raise_for_status() bot_responses = response.json() except Exception as e: return chat_history + [(message, f"Error: {e}")], "" # Extract text responses from Rasa for bot in bot_responses: if "text" in bot: chat_history.append((message, bot["text"])) else: chat_history.append((message, "🤖 Sorry, I didn't understand that.")) return chat_history, "" # Gradio interface with gr.Blocks() as demo: chatbot = gr.Chatbot() msg = gr.Textbox(show_label=False, placeholder="Type your message here...") state = gr.State([]) msg.submit(chat_with_rasa, inputs=[msg, state], outputs=[chatbot, msg]) msg.submit(lambda: "", None, msg) # clear input demo.launch()