Spaces:
Runtime error
Runtime error
Add a checkbox for resetting conversation memory
Browse files
app.py
CHANGED
|
@@ -36,5 +36,25 @@ alfred = CodeAgent(
|
|
| 36 |
planning_interval=3 # Enable planning every 3 steps
|
| 37 |
)
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
if __name__ == "__main__":
|
| 40 |
-
|
|
|
|
| 36 |
planning_interval=3 # Enable planning every 3 steps
|
| 37 |
)
|
| 38 |
|
| 39 |
+
# ── Gradio UI with memory-toggle --------------------------------------
|
| 40 |
+
def chat(query, reset, history):
|
| 41 |
+
"""
|
| 42 |
+
• `query` : user’s latest message
|
| 43 |
+
• `reset` : True → wipe conversation memory before answering
|
| 44 |
+
• `history`: running list of (user, assistant) tuples for the Chatbot
|
| 45 |
+
"""
|
| 46 |
+
answer = alfred.run(query, reset_memory=reset)
|
| 47 |
+
history = history + [(query, answer)]
|
| 48 |
+
return "", history # clear textbox, update chat window
|
| 49 |
+
|
| 50 |
+
with gr.Blocks(css="footer {visibility:hidden;}") as demo:
|
| 51 |
+
gr.Markdown("### 🤖 Alfred – a memory-enabled CodeAgent")
|
| 52 |
+
chatbot = gr.Chatbot(height=400)
|
| 53 |
+
with gr.Row():
|
| 54 |
+
txt = gr.Textbox(placeholder="Ask Alfred anything…", scale=5)
|
| 55 |
+
reset_box = gr.Checkbox(label="Reset memory before this message", value=False)
|
| 56 |
+
txt.submit(chat, [txt, reset_box, chatbot], [txt, chatbot]) \
|
| 57 |
+
.then(lambda: False, None, reset_box) # (optional) un-tick after send
|
| 58 |
+
|
| 59 |
if __name__ == "__main__":
|
| 60 |
+
demo.launch()
|