Update app.py
Browse files
app.py
CHANGED
|
@@ -55,12 +55,32 @@ def chat_handler(message, history):
|
|
| 55 |
return history
|
| 56 |
|
| 57 |
# UI wiring for the Chat tab
|
| 58 |
-
with gr.
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
# Callback for chat
|
| 66 |
def chat_handler(message, history):
|
|
|
|
| 55 |
return history
|
| 56 |
|
| 57 |
# UI wiring for the Chat tab
|
| 58 |
+
with gr.Blocks() as app:
|
| 59 |
+
|
| 60 |
+
with gr.Tab("Chat"):
|
| 61 |
+
chatbot = gr.Chatbot(type="messages")
|
| 62 |
+
chat_input = gr.Textbox(label="Ask anything...")
|
| 63 |
+
send_btn = gr.Button("Send")
|
| 64 |
+
clear_btn = gr.Button("Clear")
|
| 65 |
+
|
| 66 |
+
def chat_handler(message, history):
|
| 67 |
+
history = history or []
|
| 68 |
+
msg = (message or "").strip()
|
| 69 |
+
if not msg:
|
| 70 |
+
history.append({"role": "assistant", "content": "Please type a message."})
|
| 71 |
+
return history
|
| 72 |
+
|
| 73 |
+
# simple logic
|
| 74 |
+
reply = f"You said: {msg}"
|
| 75 |
+
history.append({"role": "user", "content": message})
|
| 76 |
+
history.append({"role": "assistant", "content": reply})
|
| 77 |
+
return history
|
| 78 |
+
|
| 79 |
+
# ✅ These must be inside the same `with gr.Tab()` block
|
| 80 |
+
send_btn.click(chat_handler, inputs=[chat_input, chatbot], outputs=chatbot)
|
| 81 |
+
chat_input.submit(chat_handler, inputs=[chat_input, chatbot], outputs=chatbot)
|
| 82 |
+
clear_btn.click(lambda: [], None, chatbot, queue=False)
|
| 83 |
+
|
| 84 |
|
| 85 |
# Callback for chat
|
| 86 |
def chat_handler(message, history):
|