Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -373,48 +373,40 @@ def select_lora(selected_indices, loras_state):
|
|
373 |
|
374 |
|
375 |
|
376 |
-
def add_custom_lora(custom_lora, selected_indices, current_loras, gallery):
|
377 |
-
|
378 |
-
|
|
|
|
|
379 |
title, repo, path, trigger_word, image = check_custom_model(custom_lora)
|
380 |
-
|
|
|
|
|
381 |
try:
|
382 |
image = download_file_mod(image)
|
383 |
except Exception as e:
|
384 |
-
|
385 |
image = None
|
386 |
-
|
387 |
existing_item_index = next((index for (index, item) in enumerate(current_loras) if item['repo'] == repo), None)
|
388 |
if existing_item_index is None:
|
389 |
-
|
390 |
-
|
391 |
-
new_item = {
|
392 |
-
"image": image if image else get_custom_image(), # Integration der neuen Funktion
|
393 |
"title": title,
|
394 |
"repo": repo,
|
395 |
"weights": path,
|
396 |
"trigger_word": trigger_word
|
397 |
-
}
|
398 |
-
|
399 |
-
existing_item_index = len(current_loras)
|
400 |
-
current_loras.append(new_item)
|
401 |
-
|
402 |
-
# Update gallery
|
403 |
-
gallery_items = [(item["image"], item["title"]) for item in current_loras]
|
404 |
-
# Update selected_indices if there's room
|
405 |
-
if len(selected_indices) < 2:
|
406 |
-
selected_indices.append(existing_item_index)
|
407 |
-
else:
|
408 |
-
gr.Warning("You can select up to 2 LoRAs, remove one to select a new one.")
|
409 |
-
|
410 |
-
return current_loras, gr.update(value=gallery_items)
|
411 |
-
except Exception as e:
|
412 |
-
print(e)
|
413 |
-
gr.Warning(str(e))
|
414 |
-
return current_loras, gr.update()
|
415 |
-
else:
|
416 |
-
return current_loras, gr.update()
|
417 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
418 |
|
419 |
|
420 |
|
@@ -1109,8 +1101,8 @@ with gr.Blocks(theme='NoCrypt/miku@>=1.2.2', fill_width=True, css=css, delete_ca
|
|
1109 |
)
|
1110 |
add_custom_lora_button.click(
|
1111 |
add_custom_lora,
|
1112 |
-
inputs=[custom_lora, selected_indices, loras_state, gallery],
|
1113 |
-
outputs=[loras_state, gallery,
|
1114 |
)
|
1115 |
remove_custom_lora_button.click(
|
1116 |
remove_custom_lora,
|
|
|
373 |
|
374 |
|
375 |
|
376 |
+
def add_custom_lora(custom_lora, selected_indices, current_loras, gallery, debug_log):
|
377 |
+
logs = debug_log
|
378 |
+
try:
|
379 |
+
logs = append_debug_log(f"Adding custom LoRA: {custom_lora}", logs)
|
380 |
+
if custom_lora:
|
381 |
title, repo, path, trigger_word, image = check_custom_model(custom_lora)
|
382 |
+
logs = append_debug_log(f"Loaded custom LoRA: {repo}", logs)
|
383 |
+
|
384 |
+
if image is not None and "http" in image and not is_repo_public(repo):
|
385 |
try:
|
386 |
image = download_file_mod(image)
|
387 |
except Exception as e:
|
388 |
+
logs = append_debug_log(f"Error downloading image: {e}", logs)
|
389 |
image = None
|
390 |
+
|
391 |
existing_item_index = next((index for (index, item) in enumerate(current_loras) if item['repo'] == repo), None)
|
392 |
if existing_item_index is None:
|
393 |
+
current_loras.append({
|
394 |
+
"image": image or "/path/to/default-placeholder.png",
|
|
|
|
|
395 |
"title": title,
|
396 |
"repo": repo,
|
397 |
"weights": path,
|
398 |
"trigger_word": trigger_word
|
399 |
+
})
|
400 |
+
logs = append_debug_log(f"New LoRA added: {title}", logs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
401 |
|
402 |
+
gallery_items = [(item["image"], item["title"]) for item in current_loras]
|
403 |
+
return current_loras, gr.update(value=gallery_items), gr.update(value=logs)
|
404 |
+
else:
|
405 |
+
logs = append_debug_log("No custom LoRA provided.", logs)
|
406 |
+
return current_loras, gallery, gr.update(value=logs)
|
407 |
+
except Exception as e:
|
408 |
+
logs = append_debug_log(f"Error: {e}", logs)
|
409 |
+
return current_loras, gallery, gr.update(value=logs)
|
410 |
|
411 |
|
412 |
|
|
|
1101 |
)
|
1102 |
add_custom_lora_button.click(
|
1103 |
add_custom_lora,
|
1104 |
+
inputs=[custom_lora, selected_indices, loras_state, gallery, debug_log],
|
1105 |
+
outputs=[loras_state, gallery, debug_log]
|
1106 |
)
|
1107 |
remove_custom_lora_button.click(
|
1108 |
remove_custom_lora,
|