Spaces:
Running
on
Zero
Running
on
Zero
Gamahea
commited on
Commit
Β·
2f0c8b4
1
Parent(s):
b40ee5f
Improve LoRA training UX - Auto-populate and navigation
Browse files1. Auto-populate LoRA Adapter Name when dataset is selected
- Generates suggested name from dataset key + timestamp
- Updates automatically on dataset selection change
2. Add 'Load for Training' button in Manage LoRA Adapters
- Select existing LoRA and click to prepare for continued training
- Auto-fills LoRA name with versioned suggestion (e.g., 'model_v2_1234')
- Enables 'Continue training' checkbox
- Selects the base LoRA adapter automatically
3. Improved base LoRA dropdown visibility
- Already toggles on checkbox change
- Now properly populated when using 'Load for Training'
User flow improvement:
- Dataset Training Auto-named LoRA ready to train
- Manage LoRAs Load for Training Training tab ready with all fields set
app.py
CHANGED
|
@@ -1517,6 +1517,49 @@ def toggle_base_lora(use_existing):
|
|
| 1517 |
"""Toggle visibility of base LoRA adapter dropdown"""
|
| 1518 |
return gr.Dropdown(visible=use_existing)
|
| 1519 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1520 |
def export_dataset(dataset_key):
|
| 1521 |
"""Export prepared dataset as zip file"""
|
| 1522 |
try:
|
|
@@ -2256,6 +2299,7 @@ with gr.Blocks(
|
|
| 2256 |
)
|
| 2257 |
|
| 2258 |
with gr.Row():
|
|
|
|
| 2259 |
download_lora_btn = gr.Button("β¬οΈ Download LoRA", variant="primary", size="lg", scale=1)
|
| 2260 |
delete_lora_btn = gr.Button("ποΈ Delete LoRA", variant="stop", size="lg", scale=1)
|
| 2261 |
|
|
@@ -2362,6 +2406,20 @@ with gr.Blocks(
|
|
| 2362 |
outputs=[selected_dataset]
|
| 2363 |
)
|
| 2364 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2365 |
start_training_btn.click(
|
| 2366 |
fn=start_lora_training,
|
| 2367 |
inputs=[lora_name_input, selected_dataset, batch_size, learning_rate, num_epochs, lora_rank, lora_alpha],
|
|
|
|
| 1517 |
"""Toggle visibility of base LoRA adapter dropdown"""
|
| 1518 |
return gr.Dropdown(visible=use_existing)
|
| 1519 |
|
| 1520 |
+
def auto_populate_lora_name(dataset_selection):
|
| 1521 |
+
"""Auto-populate LoRA name when dataset is selected"""
|
| 1522 |
+
try:
|
| 1523 |
+
if not dataset_selection or dataset_selection in ["No prepared datasets available", "Error loading datasets"]:
|
| 1524 |
+
return ""
|
| 1525 |
+
|
| 1526 |
+
# Extract dataset key from display name (format: "dataset_key (N samples)")
|
| 1527 |
+
dataset_key = dataset_selection.split(" (")[0].strip()
|
| 1528 |
+
|
| 1529 |
+
# Generate suggested LoRA name from dataset
|
| 1530 |
+
import time
|
| 1531 |
+
timestamp = int(time.time() % 10000) # Last 4 digits
|
| 1532 |
+
suggested_name = f"{dataset_key}_lora_{timestamp}"
|
| 1533 |
+
|
| 1534 |
+
return suggested_name
|
| 1535 |
+
|
| 1536 |
+
except Exception as e:
|
| 1537 |
+
logger.error(f"Failed to auto-populate LoRA name: {e}")
|
| 1538 |
+
return ""
|
| 1539 |
+
|
| 1540 |
+
def load_lora_for_training(selected_lora):
|
| 1541 |
+
"""Load selected LoRA for continued training - navigate to training tab"""
|
| 1542 |
+
try:
|
| 1543 |
+
if not selected_lora:
|
| 1544 |
+
return gr.Textbox(value="β No LoRA selected"), gr.Textbox(value=""), gr.Checkbox(value=False), gr.Dropdown(value=None)
|
| 1545 |
+
|
| 1546 |
+
# Generate suggested name for continued training
|
| 1547 |
+
import time
|
| 1548 |
+
timestamp = int(time.time() % 10000)
|
| 1549 |
+
suggested_name = f"{selected_lora}_v2_{timestamp}"
|
| 1550 |
+
|
| 1551 |
+
# Return updates: status message, new LoRA name, enable checkbox, select base LoRA
|
| 1552 |
+
return (
|
| 1553 |
+
gr.Textbox(value=f"β
Ready to continue training '{selected_lora}'"),
|
| 1554 |
+
gr.Textbox(value=suggested_name),
|
| 1555 |
+
gr.Checkbox(value=True),
|
| 1556 |
+
gr.Dropdown(value=selected_lora)
|
| 1557 |
+
)
|
| 1558 |
+
|
| 1559 |
+
except Exception as e:
|
| 1560 |
+
logger.error(f"Failed to load LoRA for training: {e}")
|
| 1561 |
+
return gr.Textbox(value=f"β Error: {str(e)}"), gr.Textbox(value=""), gr.Checkbox(value=False), gr.Dropdown(value=None)
|
| 1562 |
+
|
| 1563 |
def export_dataset(dataset_key):
|
| 1564 |
"""Export prepared dataset as zip file"""
|
| 1565 |
try:
|
|
|
|
| 2299 |
)
|
| 2300 |
|
| 2301 |
with gr.Row():
|
| 2302 |
+
load_for_training_btn = gr.Button("π Load for Training", variant="secondary", size="lg", scale=1)
|
| 2303 |
download_lora_btn = gr.Button("β¬οΈ Download LoRA", variant="primary", size="lg", scale=1)
|
| 2304 |
delete_lora_btn = gr.Button("ποΈ Delete LoRA", variant="stop", size="lg", scale=1)
|
| 2305 |
|
|
|
|
| 2406 |
outputs=[selected_dataset]
|
| 2407 |
)
|
| 2408 |
|
| 2409 |
+
# Auto-populate LoRA name when dataset is selected
|
| 2410 |
+
selected_dataset.change(
|
| 2411 |
+
fn=auto_populate_lora_name,
|
| 2412 |
+
inputs=[selected_dataset],
|
| 2413 |
+
outputs=[lora_name_input]
|
| 2414 |
+
)
|
| 2415 |
+
|
| 2416 |
+
# Load LoRA for continued training from Manage tab
|
| 2417 |
+
load_for_training_btn.click(
|
| 2418 |
+
fn=load_lora_for_training,
|
| 2419 |
+
inputs=[selected_lora_for_action],
|
| 2420 |
+
outputs=[lora_action_status, lora_name_input, use_existing_lora, base_lora_adapter]
|
| 2421 |
+
)
|
| 2422 |
+
|
| 2423 |
start_training_btn.click(
|
| 2424 |
fn=start_lora_training,
|
| 2425 |
inputs=[lora_name_input, selected_dataset, batch_size, learning_rate, num_epochs, lora_rank, lora_alpha],
|