File size: 1,033 Bytes
fe58ea2
5d01d23
36983e1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
edc77f2
 
36983e1
edc77f2
36983e1
 
 
edc77f2
36983e1
 
ec6c4fb
36983e1
 
 
d13dbb5
36983e1
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
import gradio as gr

def respond(message, chat_history):
    bot_reply = "You said: " + message  # Replace with your chatbot logic
    chat_history = chat_history or []
    chat_history.append(("You", message))
    chat_history.append(("Bot", bot_reply))
    return "", chat_history

def say_hello(chat_history):
    chat_history = chat_history or []
    chat_history.append(("Bot", "Hello! How can I help?"))
    return chat_history

def clear():
    return []

with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column(scale=1):
            gr.Markdown("## Sidebar")
            hello_btn = gr.Button("Say Hello")
            clear_btn = gr.Button("Clear Chat")
        with gr.Column(scale=4):
            chatbot = gr.Chatbot()
            msg = gr.Textbox(placeholder="Type a message")
            send = gr.Button("Send")

    send.click(respond, inputs=[msg, chatbot], outputs=[msg, chatbot])
    hello_btn.click(say_hello, inputs=chatbot, outputs=chatbot)
    clear_btn.click(clear, outputs=chatbot)

demo.launch()