Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -346,6 +346,29 @@ with gr.Blocks(title="Backend-Focused LLaMA/Mistral CRUD Assistant", theme=gr.th
|
|
| 346 |
label="Your chats",
|
| 347 |
interactive=True
|
| 348 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
with gr.Row():
|
| 350 |
new_btn = gr.Button("➕ New Chat", variant="primary")
|
| 351 |
del_btn = gr.Button("🗑️ Delete", variant="stop")
|
|
|
|
| 346 |
label="Your chats",
|
| 347 |
interactive=True
|
| 348 |
)
|
| 349 |
+
# -----------------------
|
| 350 |
+
# Editable title input
|
| 351 |
+
# -----------------------
|
| 352 |
+
edit_title_box = gr.Textbox(label="✏️ Rename Chat", placeholder="Edit selected chat title...")
|
| 353 |
+
rename_btn = gr.Button("💾 Save Title")
|
| 354 |
+
|
| 355 |
+
def rename_session_cb(new_title, selected_label):
|
| 356 |
+
sid = label_to_id(selected_label)
|
| 357 |
+
if sid and new_title.strip():
|
| 358 |
+
conn = db()
|
| 359 |
+
cur = conn.cursor()
|
| 360 |
+
cur.execute("UPDATE sessions SET title=? WHERE id=?", (new_title.strip(), sid))
|
| 361 |
+
conn.commit()
|
| 362 |
+
conn.close()
|
| 363 |
+
|
| 364 |
+
# Refresh the session list and keep the same one selected
|
| 365 |
+
labels, _ = list_sessions()
|
| 366 |
+
new_selected = next((lbl for lbl in labels if lbl.startswith(f"{sid} ")), None)
|
| 367 |
+
return gr.update(choices=labels, value=new_selected)
|
| 368 |
+
|
| 369 |
+
# Connect button to callback
|
| 370 |
+
rename_btn.click(rename_session_cb, inputs=[edit_title_box, session_list], outputs=session_list)
|
| 371 |
+
|
| 372 |
with gr.Row():
|
| 373 |
new_btn = gr.Button("➕ New Chat", variant="primary")
|
| 374 |
del_btn = gr.Button("🗑️ Delete", variant="stop")
|