arubaDev commited on
Commit
3ded322
·
verified ·
1 Parent(s): 8c93395

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -23
app.py CHANGED
@@ -401,20 +401,31 @@ with gr.Blocks(title="Backend-Focused LLaMA/Mistral CRUD Assistant", theme=gr.th
401
 
402
  with gr.Row(equal_height=True):
403
  with gr.Column(scale=1, min_width=260):
404
- gr.Markdown("### 📁 Sessions")
 
 
405
  session_list = gr.Radio(
406
  choices=labels,
407
  value=default_selected,
408
- label="Your chats",
409
  interactive=True
410
  )
411
- # -----------------------
412
- # Editable title input
413
- # -----------------------
414
- # Hidden initially will be shown when a chat is created/selected
415
- edit_title_box = gr.Textbox(label="✏️ Rename Chat", placeholder="Edit selected chat title...", visible=False)
416
- save_title_btn = gr.Button("💾", elem_id="save-title-btn", visible=False)
417
-
 
 
 
 
 
 
 
 
 
418
  def rename_session_cb(new_title, selected_label):
419
  sid = label_to_id(selected_label)
420
  if sid and new_title.strip():
@@ -423,21 +434,16 @@ with gr.Blocks(title="Backend-Focused LLaMA/Mistral CRUD Assistant", theme=gr.th
423
  cur.execute("UPDATE sessions SET title=? WHERE id=?", (new_title.strip(), sid))
424
  conn.commit()
425
  conn.close()
426
-
427
  # Refresh the session list and keep the same one selected
428
  labels, _ = list_sessions()
429
  new_selected = next((lbl for lbl in labels if lbl.startswith(f"{sid} ")), None)
430
  return gr.update(choices=labels, value=new_selected)
431
-
432
- # Connect button to callback
433
  save_title_btn.click(rename_session_cb, inputs=[edit_title_box, session_list], outputs=session_list)
434
-
435
- # Action buttons: New Chat always visible, others hidden initially
436
- with gr.Row(elem_id="session-action-row"):
437
- new_btn = gr.Button("➕", elem_id="new-chat-btn")
438
- del_btn = gr.Button("🗑️", elem_id="delete-chat-btn", visible=False)
439
- refresh_btn = gr.Button("🔄", elem_id="refresh-btn", visible=False)
440
-
441
  gr.Markdown("### 🤖 Model Selection")
442
  model_choice = gr.Dropdown(
443
  choices=list(MODELS.keys()),
@@ -445,7 +451,8 @@ with gr.Blocks(title="Backend-Focused LLaMA/Mistral CRUD Assistant", theme=gr.th
445
  label="Choose a model",
446
  interactive=True
447
  )
448
-
 
449
  gr.Markdown("### 📚 Dataset Selection")
450
  dataset_choice = gr.Dropdown(
451
  choices=DATASETS,
@@ -453,7 +460,8 @@ with gr.Blocks(title="Backend-Focused LLaMA/Mistral CRUD Assistant", theme=gr.th
453
  label="Select a dataset",
454
  interactive=True
455
  )
456
-
 
457
  gr.Markdown("### ⚙️ Generation Settings")
458
  with gr.Group(elem_classes="system-message-compact"):
459
  system_box = gr.Textbox(
@@ -461,12 +469,13 @@ with gr.Blocks(title="Backend-Focused LLaMA/Mistral CRUD Assistant", theme=gr.th
461
  label="System message",
462
  lines=3
463
  )
464
-
465
  with gr.Group(elem_classes="compact-sliders"):
466
  max_tokens = gr.Slider(256, 4096, value=1200, step=16, label="Max tokens")
467
  temperature = gr.Slider(0.0, 2.0, value=0.25, step=0.05, label="Temperature")
468
  top_p = gr.Slider(0.1, 1.0, value=0.9, step=0.05, label="Top-p")
469
-
 
470
  with gr.Column(scale=3):
471
  chatbot = gr.Chatbot(label="Assistant", height=500, type="messages")
472
  with gr.Row():
@@ -475,6 +484,7 @@ with gr.Blocks(title="Backend-Focused LLaMA/Mistral CRUD Assistant", theme=gr.th
475
  send_btn = gr.Button("Send ▶️", variant="primary")
476
  regen_btn = gr.Button("Regenerate 🔁", variant="secondary")
477
 
 
478
  # Wire callbacks — updated outputs so visibility changes flow correctly
479
  refresh_btn.click(
480
  refresh_sessions_cb,
 
401
 
402
  with gr.Row(equal_height=True):
403
  with gr.Column(scale=1, min_width=260):
404
+ gr.Markdown("### 📁 Chats")
405
+
406
+ # --- Chat list ---
407
  session_list = gr.Radio(
408
  choices=labels,
409
  value=default_selected,
410
+ label="Your Chats",
411
  interactive=True
412
  )
413
+
414
+ # --- Action buttons appear just below the chat list ---
415
+ with gr.Row():
416
+ new_btn = gr.Button("➕ New", elem_id="new-chat-btn")
417
+ del_btn = gr.Button("🗑️ Delete", elem_id="delete-chat-btn", visible=False)
418
+ refresh_btn = gr.Button("🔄 Refresh", elem_id="refresh-btn", visible=False)
419
+
420
+ # --- Rename box & save button below the action buttons ---
421
+ edit_title_box = gr.Textbox(
422
+ label="✏️ Rename Chat",
423
+ placeholder="Edit selected chat title...",
424
+ visible=False
425
+ )
426
+ save_title_btn = gr.Button("💾 Save Title", elem_id="save-title-btn", visible=False)
427
+
428
+ # Callback for renaming session
429
  def rename_session_cb(new_title, selected_label):
430
  sid = label_to_id(selected_label)
431
  if sid and new_title.strip():
 
434
  cur.execute("UPDATE sessions SET title=? WHERE id=?", (new_title.strip(), sid))
435
  conn.commit()
436
  conn.close()
437
+
438
  # Refresh the session list and keep the same one selected
439
  labels, _ = list_sessions()
440
  new_selected = next((lbl for lbl in labels if lbl.startswith(f"{sid} ")), None)
441
  return gr.update(choices=labels, value=new_selected)
442
+
443
+ # Connect rename button
444
  save_title_btn.click(rename_session_cb, inputs=[edit_title_box, session_list], outputs=session_list)
445
+
446
+ # --- Model Selection ---
 
 
 
 
 
447
  gr.Markdown("### 🤖 Model Selection")
448
  model_choice = gr.Dropdown(
449
  choices=list(MODELS.keys()),
 
451
  label="Choose a model",
452
  interactive=True
453
  )
454
+
455
+ # --- Dataset Selection ---
456
  gr.Markdown("### 📚 Dataset Selection")
457
  dataset_choice = gr.Dropdown(
458
  choices=DATASETS,
 
460
  label="Select a dataset",
461
  interactive=True
462
  )
463
+
464
+ # --- Generation Settings ---
465
  gr.Markdown("### ⚙️ Generation Settings")
466
  with gr.Group(elem_classes="system-message-compact"):
467
  system_box = gr.Textbox(
 
469
  label="System message",
470
  lines=3
471
  )
472
+
473
  with gr.Group(elem_classes="compact-sliders"):
474
  max_tokens = gr.Slider(256, 4096, value=1200, step=16, label="Max tokens")
475
  temperature = gr.Slider(0.0, 2.0, value=0.25, step=0.05, label="Temperature")
476
  top_p = gr.Slider(0.1, 1.0, value=0.9, step=0.05, label="Top-p")
477
+
478
+ # --- Chatbot & Input Column ---
479
  with gr.Column(scale=3):
480
  chatbot = gr.Chatbot(label="Assistant", height=500, type="messages")
481
  with gr.Row():
 
484
  send_btn = gr.Button("Send ▶️", variant="primary")
485
  regen_btn = gr.Button("Regenerate 🔁", variant="secondary")
486
 
487
+
488
  # Wire callbacks — updated outputs so visibility changes flow correctly
489
  refresh_btn.click(
490
  refresh_sessions_cb,