Update app.py
Browse files
app.py
CHANGED
|
@@ -48,23 +48,20 @@ def respond(user_message, history):
|
|
| 48 |
with gr.Blocks() as demo:
|
| 49 |
gr.Markdown("## 🤖 AI-Guided Math PD Chatbot")
|
| 50 |
|
| 51 |
-
chatbot = gr.Chatbot(height=500)
|
| 52 |
-
state_history = gr.State([])
|
| 53 |
|
| 54 |
user_input = gr.Textbox(placeholder="Type your message here...", label="Your Input")
|
| 55 |
|
| 56 |
-
# ✅ Button for first-time users to start the chat
|
| 57 |
-
def start_chat():
|
| 58 |
-
return [(INITIAL_PROMPT, "")]
|
| 59 |
-
|
| 60 |
-
start_button = gr.Button("Start Chat")
|
| 61 |
-
start_button.click(start_chat, outputs=[chatbot, state_history])
|
| 62 |
-
|
| 63 |
# ✅ Handling user input and response logic
|
| 64 |
user_input.submit(
|
| 65 |
respond,
|
| 66 |
inputs=[user_input, state_history],
|
| 67 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
)
|
| 69 |
|
| 70 |
if __name__ == "__main__":
|
|
|
|
| 48 |
with gr.Blocks() as demo:
|
| 49 |
gr.Markdown("## 🤖 AI-Guided Math PD Chatbot")
|
| 50 |
|
| 51 |
+
chatbot = gr.Chatbot(value=[(INITIAL_PROMPT, "")], height=500)
|
| 52 |
+
state_history = gr.State([(INITIAL_PROMPT, "")])
|
| 53 |
|
| 54 |
user_input = gr.Textbox(placeholder="Type your message here...", label="Your Input")
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
# ✅ Handling user input and response logic
|
| 57 |
user_input.submit(
|
| 58 |
respond,
|
| 59 |
inputs=[user_input, state_history],
|
| 60 |
+
outputs=[user_input, chatbot]
|
| 61 |
+
).then(
|
| 62 |
+
fn=lambda _, h: h,
|
| 63 |
+
inputs=[user_input, chatbot],
|
| 64 |
+
outputs=[state_history]
|
| 65 |
)
|
| 66 |
|
| 67 |
if __name__ == "__main__":
|