Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -334,7 +334,7 @@ def regenerate_cb(selected_label, system_message, max_tokens, temperature, top_p
|
|
| 334 |
|
| 335 |
except Exception as e:
|
| 336 |
display_msgs[-1]["content"] = f"⚠️ Error: {str(e)}"
|
| 337 |
-
yield display_msgs
|
| 338 |
|
| 339 |
# ---------------------------
|
| 340 |
# App UI
|
|
@@ -348,53 +348,21 @@ if not labels:
|
|
| 348 |
default_selected = labels[0] if labels else None
|
| 349 |
|
| 350 |
with gr.Blocks(title="Backend-Focused LLaMA/Mistral CRUD Assistant", theme=gr.themes.Soft()) as demo:
|
|
|
|
| 351 |
gr.HTML("""
|
| 352 |
<style>
|
| 353 |
-
/*
|
| 354 |
-
#session-
|
| 355 |
-
|
| 356 |
-
width: 36px !important;
|
| 357 |
-
height: 36px !important;
|
| 358 |
-
border-radius: 8px !important;
|
| 359 |
-
font-size: 18px !important;
|
| 360 |
-
padding: 0 !important;
|
| 361 |
-
margin: 2px !important;
|
| 362 |
-
background-color: #22c55e !important;
|
| 363 |
-
color: #fff !important;
|
| 364 |
-
border: none !important;
|
| 365 |
-
cursor: pointer;
|
| 366 |
-
}
|
| 367 |
-
|
| 368 |
-
/* Hover & focus effects */
|
| 369 |
-
#session-action-row button:hover,
|
| 370 |
-
#save-title-btn:hover {
|
| 371 |
-
background-color: #16a34a !important;
|
| 372 |
-
}
|
| 373 |
-
|
| 374 |
-
#session-action-row button:focus,
|
| 375 |
-
#save-title-btn:focus {
|
| 376 |
-
outline: 2px solid #166534 !important;
|
| 377 |
-
}
|
| 378 |
-
|
| 379 |
-
/* Compact form/sliders keep */
|
| 380 |
-
.compact-sliders .gr-form {
|
| 381 |
-
margin-bottom: 0.5rem !important;
|
| 382 |
-
}
|
| 383 |
-
.compact-sliders .gr-slider {
|
| 384 |
-
margin-bottom: 0.5rem !important;
|
| 385 |
-
}
|
| 386 |
-
.compact-sliders .gr-number {
|
| 387 |
-
margin-bottom: 0.5rem !important;
|
| 388 |
-
}
|
| 389 |
-
.system-message-compact .gr-form {
|
| 390 |
-
margin-bottom: 0.5rem !important;
|
| 391 |
}
|
|
|
|
|
|
|
|
|
|
| 392 |
.system-message-compact .gr-textarea {
|
| 393 |
min-height: 80px !important;
|
| 394 |
max-height: 120px !important;
|
| 395 |
}
|
| 396 |
</style>
|
| 397 |
-
|
| 398 |
""")
|
| 399 |
|
| 400 |
gr.Markdown("## 🗄️ LLaMA & Mistral Backend-Focused CRUD Automation — with Persistent History")
|
|
@@ -402,7 +370,7 @@ with gr.Blocks(title="Backend-Focused LLaMA/Mistral CRUD Assistant", theme=gr.th
|
|
| 402 |
with gr.Row(equal_height=True):
|
| 403 |
with gr.Column(scale=1, min_width=260):
|
| 404 |
gr.Markdown("### 📁 Sessions")
|
| 405 |
-
|
| 406 |
# Main session list
|
| 407 |
session_list = gr.Radio(
|
| 408 |
choices=labels,
|
|
@@ -410,23 +378,29 @@ with gr.Blocks(title="Backend-Focused LLaMA/Mistral CRUD Assistant", theme=gr.th
|
|
| 410 |
label="Your Chats",
|
| 411 |
interactive=True
|
| 412 |
)
|
| 413 |
-
|
| 414 |
-
# Row for actions
|
| 415 |
with gr.Row(elem_id="session-actions-row"):
|
| 416 |
new_btn = gr.Button("New Chat", elem_id="new-chat-btn")
|
| 417 |
rename_btn = gr.Button("Rename", elem_id="rename-chat-btn", visible=False)
|
| 418 |
-
|
| 419 |
del_btn = gr.Button("Delete", elem_id="delete-chat-btn", visible=False)
|
| 420 |
refresh_btn = gr.Button("Refresh", elem_id="refresh-btn", visible=False)
|
| 421 |
-
|
| 422 |
# Rename textbox (hidden until Rename is clicked)
|
| 423 |
edit_title_box = gr.Textbox(
|
| 424 |
label="Edit Chat Name",
|
| 425 |
placeholder="Type new chat name here…",
|
| 426 |
visible=False
|
| 427 |
)
|
| 428 |
-
|
| 429 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 430 |
def rename_session_cb(new_title, selected_label):
|
| 431 |
sid = label_to_id(selected_label)
|
| 432 |
if sid and new_title.strip():
|
|
@@ -435,18 +409,17 @@ with gr.Blocks(title="Backend-Focused LLaMA/Mistral CRUD Assistant", theme=gr.th
|
|
| 435 |
cur.execute("UPDATE sessions SET title=? WHERE id=?", (new_title.strip(), sid))
|
| 436 |
conn.commit()
|
| 437 |
conn.close()
|
| 438 |
-
|
| 439 |
-
# Refresh the session list and keep the same one selected
|
| 440 |
labels, _ = list_sessions()
|
| 441 |
new_selected = next((lbl for lbl in labels if lbl.startswith(f"{sid} ")), None)
|
|
|
|
| 442 |
return gr.update(choices=labels, value=new_selected), gr.update(value="")
|
| 443 |
-
|
| 444 |
-
|
| 445 |
rename_session_cb,
|
| 446 |
inputs=[edit_title_box, session_list],
|
| 447 |
outputs=[session_list, edit_title_box]
|
| 448 |
)
|
| 449 |
-
|
| 450 |
# -------- Model selection --------
|
| 451 |
gr.Markdown("### 🤖 Model Selection")
|
| 452 |
model_choice = gr.Dropdown(
|
|
@@ -455,7 +428,7 @@ with gr.Blocks(title="Backend-Focused LLaMA/Mistral CRUD Assistant", theme=gr.th
|
|
| 455 |
label="Choose a model",
|
| 456 |
interactive=True
|
| 457 |
)
|
| 458 |
-
|
| 459 |
# -------- Dataset selection --------
|
| 460 |
gr.Markdown("### 📚 Dataset Selection")
|
| 461 |
dataset_choice = gr.Dropdown(
|
|
@@ -464,7 +437,7 @@ with gr.Blocks(title="Backend-Focused LLaMA/Mistral CRUD Assistant", theme=gr.th
|
|
| 464 |
label="Select a dataset",
|
| 465 |
interactive=True
|
| 466 |
)
|
| 467 |
-
|
| 468 |
# -------- Generation settings --------
|
| 469 |
gr.Markdown("### ⚙️ Generation Settings")
|
| 470 |
with gr.Group(elem_classes="system-message-compact"):
|
|
@@ -473,12 +446,12 @@ with gr.Blocks(title="Backend-Focused LLaMA/Mistral CRUD Assistant", theme=gr.th
|
|
| 473 |
label="System message",
|
| 474 |
lines=3
|
| 475 |
)
|
| 476 |
-
|
| 477 |
with gr.Group(elem_classes="compact-sliders"):
|
| 478 |
max_tokens = gr.Slider(256, 4096, value=1200, step=16, label="Max tokens")
|
| 479 |
temperature = gr.Slider(0.0, 2.0, value=0.25, step=0.05, label="Temperature")
|
| 480 |
top_p = gr.Slider(0.1, 1.0, value=0.9, step=0.05, label="Top-p")
|
| 481 |
-
|
| 482 |
with gr.Column(scale=3):
|
| 483 |
chatbot = gr.Chatbot(label="Assistant", height=500, type="messages")
|
| 484 |
with gr.Row():
|
|
@@ -487,8 +460,6 @@ with gr.Blocks(title="Backend-Focused LLaMA/Mistral CRUD Assistant", theme=gr.th
|
|
| 487 |
send_btn = gr.Button("Send ▶️", variant="primary")
|
| 488 |
regen_btn = gr.Button("Regenerate 🔁", variant="secondary")
|
| 489 |
|
| 490 |
-
|
| 491 |
-
|
| 492 |
# Wire callbacks — updated outputs so visibility changes flow correctly
|
| 493 |
refresh_btn.click(
|
| 494 |
refresh_sessions_cb,
|
|
|
|
| 334 |
|
| 335 |
except Exception as e:
|
| 336 |
display_msgs[-1]["content"] = f"⚠️ Error: {str(e)}"
|
| 337 |
+
yield (display_msgs, "", selected_label)
|
| 338 |
|
| 339 |
# ---------------------------
|
| 340 |
# App UI
|
|
|
|
| 348 |
default_selected = labels[0] if labels else None
|
| 349 |
|
| 350 |
with gr.Blocks(title="Backend-Focused LLaMA/Mistral CRUD Assistant", theme=gr.themes.Soft()) as demo:
|
| 351 |
+
# Minimal CSS for compact, professional look
|
| 352 |
gr.HTML("""
|
| 353 |
<style>
|
| 354 |
+
/* compact action row below chat list */
|
| 355 |
+
#session-actions-row .gr-button {
|
| 356 |
+
margin-right: 6px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
}
|
| 358 |
+
/* keep settings compact */
|
| 359 |
+
.compact-sliders .gr-slider,
|
| 360 |
+
.compact-sliders .gr-number { margin-bottom: 0.5rem !important; }
|
| 361 |
.system-message-compact .gr-textarea {
|
| 362 |
min-height: 80px !important;
|
| 363 |
max-height: 120px !important;
|
| 364 |
}
|
| 365 |
</style>
|
|
|
|
| 366 |
""")
|
| 367 |
|
| 368 |
gr.Markdown("## 🗄️ LLaMA & Mistral Backend-Focused CRUD Automation — with Persistent History")
|
|
|
|
| 370 |
with gr.Row(equal_height=True):
|
| 371 |
with gr.Column(scale=1, min_width=260):
|
| 372 |
gr.Markdown("### 📁 Sessions")
|
| 373 |
+
|
| 374 |
# Main session list
|
| 375 |
session_list = gr.Radio(
|
| 376 |
choices=labels,
|
|
|
|
| 378 |
label="Your Chats",
|
| 379 |
interactive=True
|
| 380 |
)
|
| 381 |
+
|
| 382 |
+
# Row for actions (visible/hidden controlled via callbacks)
|
| 383 |
with gr.Row(elem_id="session-actions-row"):
|
| 384 |
new_btn = gr.Button("New Chat", elem_id="new-chat-btn")
|
| 385 |
rename_btn = gr.Button("Rename", elem_id="rename-chat-btn", visible=False)
|
| 386 |
+
save_title_btn = gr.Button("Save", elem_id="save-title-btn", visible=False)
|
| 387 |
del_btn = gr.Button("Delete", elem_id="delete-chat-btn", visible=False)
|
| 388 |
refresh_btn = gr.Button("Refresh", elem_id="refresh-btn", visible=False)
|
| 389 |
+
|
| 390 |
# Rename textbox (hidden until Rename is clicked)
|
| 391 |
edit_title_box = gr.Textbox(
|
| 392 |
label="Edit Chat Name",
|
| 393 |
placeholder="Type new chat name here…",
|
| 394 |
visible=False
|
| 395 |
)
|
| 396 |
+
|
| 397 |
+
# Callback to open the rename box (show edit box + save button)
|
| 398 |
+
def show_rename_ui():
|
| 399 |
+
return gr.update(visible=True), gr.update(visible=True)
|
| 400 |
+
|
| 401 |
+
rename_btn.click(fn=show_rename_ui, outputs=[edit_title_box, save_title_btn])
|
| 402 |
+
|
| 403 |
+
# Callback for renaming -> updates DB and refreshes list, clears edit box
|
| 404 |
def rename_session_cb(new_title, selected_label):
|
| 405 |
sid = label_to_id(selected_label)
|
| 406 |
if sid and new_title.strip():
|
|
|
|
| 409 |
cur.execute("UPDATE sessions SET title=? WHERE id=?", (new_title.strip(), sid))
|
| 410 |
conn.commit()
|
| 411 |
conn.close()
|
|
|
|
|
|
|
| 412 |
labels, _ = list_sessions()
|
| 413 |
new_selected = next((lbl for lbl in labels if lbl.startswith(f"{sid} ")), None)
|
| 414 |
+
# return updated session list selection and clear the edit box value
|
| 415 |
return gr.update(choices=labels, value=new_selected), gr.update(value="")
|
| 416 |
+
|
| 417 |
+
save_title_btn.click(
|
| 418 |
rename_session_cb,
|
| 419 |
inputs=[edit_title_box, session_list],
|
| 420 |
outputs=[session_list, edit_title_box]
|
| 421 |
)
|
| 422 |
+
|
| 423 |
# -------- Model selection --------
|
| 424 |
gr.Markdown("### 🤖 Model Selection")
|
| 425 |
model_choice = gr.Dropdown(
|
|
|
|
| 428 |
label="Choose a model",
|
| 429 |
interactive=True
|
| 430 |
)
|
| 431 |
+
|
| 432 |
# -------- Dataset selection --------
|
| 433 |
gr.Markdown("### 📚 Dataset Selection")
|
| 434 |
dataset_choice = gr.Dropdown(
|
|
|
|
| 437 |
label="Select a dataset",
|
| 438 |
interactive=True
|
| 439 |
)
|
| 440 |
+
|
| 441 |
# -------- Generation settings --------
|
| 442 |
gr.Markdown("### ⚙️ Generation Settings")
|
| 443 |
with gr.Group(elem_classes="system-message-compact"):
|
|
|
|
| 446 |
label="System message",
|
| 447 |
lines=3
|
| 448 |
)
|
| 449 |
+
|
| 450 |
with gr.Group(elem_classes="compact-sliders"):
|
| 451 |
max_tokens = gr.Slider(256, 4096, value=1200, step=16, label="Max tokens")
|
| 452 |
temperature = gr.Slider(0.0, 2.0, value=0.25, step=0.05, label="Temperature")
|
| 453 |
top_p = gr.Slider(0.1, 1.0, value=0.9, step=0.05, label="Top-p")
|
| 454 |
+
|
| 455 |
with gr.Column(scale=3):
|
| 456 |
chatbot = gr.Chatbot(label="Assistant", height=500, type="messages")
|
| 457 |
with gr.Row():
|
|
|
|
| 460 |
send_btn = gr.Button("Send ▶️", variant="primary")
|
| 461 |
regen_btn = gr.Button("Regenerate 🔁", variant="secondary")
|
| 462 |
|
|
|
|
|
|
|
| 463 |
# Wire callbacks — updated outputs so visibility changes flow correctly
|
| 464 |
refresh_btn.click(
|
| 465 |
refresh_sessions_cb,
|