File size: 825 Bytes
0d9a014
59e8d1c
0d9a014
59e8d1c
0d9a014
59e8d1c
 
 
 
 
 
 
 
0d9a014
59e8d1c
 
 
 
 
0d9a014
 
59e8d1c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
import requests

RASA_URL = "http://localhost:5005/webhooks/rest/webhook"

def bot_response(user_message, chat_history):
    resp = requests.post(RASA_URL, json={
        "sender": "user",
        "message": user_message
    }).json()
    bot_reply = resp[0].get("text") if resp else "🤖 (no reply)"
    chat_history.append((user_message, bot_reply))
    return chat_history

with gr.Blocks(title="Rasa 2.8.3 + Gradio v4 Demo") as demo:
    chatbot = gr.Chatbot(label="Rasa Bot", height=400)
    user_input = gr.Textbox(placeholder="Type here...", show_label=False)
    user_input.submit(bot_response, inputs=[user_input, chatbot], outputs=chatbot)
    gr.Button("Clear").click(lambda: [], None, chatbot)

if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0", server_port=7860, share=False)