Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,33 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
with gr.Blocks() as demo:
|
| 4 |
with gr.Row():
|
| 5 |
-
with gr.Column(scale=1):
|
| 6 |
gr.Markdown("## Sidebar")
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
with gr.Column(scale=4): # Chat area column (wide)
|
| 11 |
chatbot = gr.Chatbot()
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
|
|
|
|
|
|
|
|
|
|
| 16 |
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
def respond(message, chat_history):
|
| 4 |
+
bot_reply = "You said: " + message # Replace with your chatbot logic
|
| 5 |
+
chat_history = chat_history or []
|
| 6 |
+
chat_history.append(("You", message))
|
| 7 |
+
chat_history.append(("Bot", bot_reply))
|
| 8 |
+
return "", chat_history
|
| 9 |
+
|
| 10 |
+
def say_hello(chat_history):
|
| 11 |
+
chat_history = chat_history or []
|
| 12 |
+
chat_history.append(("Bot", "Hello! How can I help?"))
|
| 13 |
+
return chat_history
|
| 14 |
+
|
| 15 |
+
def clear():
|
| 16 |
+
return []
|
| 17 |
+
|
| 18 |
with gr.Blocks() as demo:
|
| 19 |
with gr.Row():
|
| 20 |
+
with gr.Column(scale=1):
|
| 21 |
gr.Markdown("## Sidebar")
|
| 22 |
+
hello_btn = gr.Button("Say Hello")
|
| 23 |
+
clear_btn = gr.Button("Clear Chat")
|
| 24 |
+
with gr.Column(scale=4):
|
|
|
|
| 25 |
chatbot = gr.Chatbot()
|
| 26 |
+
msg = gr.Textbox(placeholder="Type a message")
|
| 27 |
+
send = gr.Button("Send")
|
|
|
|
| 28 |
|
| 29 |
+
send.click(respond, inputs=[msg, chatbot], outputs=[msg, chatbot])
|
| 30 |
+
hello_btn.click(say_hello, inputs=chatbot, outputs=chatbot)
|
| 31 |
+
clear_btn.click(clear, outputs=chatbot)
|
| 32 |
|
| 33 |
+
demo.launch()
|