Dmang69 commited on
Commit
a13940c
·
verified ·
1 Parent(s): 7829d42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -6
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.Tab("Chat"):
59
- # Chatbot using new 'messages' format
60
- chatbot = gr.Chatbot(label="Programming Assistant", type="messages")
61
- chat_input = gr.Textbox(label="Ask anything about programming...", placeholder="e.g. 'generate python: scraper'")
62
- send_btn = gr.Button("Send")
63
- clear_btn = gr.Button("Clear")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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):