Update app.py
Browse files
app.py
CHANGED
@@ -284,7 +284,7 @@ def randomize_loras(selected_indices, loras_state):
|
|
284 |
|
285 |
def download_loras_images(loras_json_orig: list[dict]):
|
286 |
"""
|
287 |
-
|
288 |
"""
|
289 |
loras_json = []
|
290 |
|
@@ -292,26 +292,28 @@ def download_loras_images(loras_json_orig: list[dict]):
|
|
292 |
repo = lora.get("repo", None)
|
293 |
image_url = lora.get("image", None)
|
294 |
|
295 |
-
# Standardwerte
|
296 |
lora["title"] = lora.get("title", "Unknown LoRA")
|
297 |
lora["trigger_word"] = lora.get("trigger_word", "")
|
298 |
|
299 |
-
#
|
300 |
if repo and image_url:
|
301 |
if not image_url.startswith("http"):
|
302 |
-
#
|
303 |
image_url = f"https://huggingface.co/{repo}/resolve/main/{image_url}"
|
304 |
try:
|
305 |
-
# Validieren, ob die URL erreichbar ist
|
306 |
response = requests.head(image_url)
|
307 |
if response.status_code != 200:
|
308 |
-
raise ValueError(f"
|
309 |
except Exception as e:
|
310 |
-
print(f"
|
311 |
-
image_url = None
|
|
|
|
|
|
|
312 |
|
313 |
-
#
|
314 |
-
lora["image"] = image_url
|
315 |
loras_json.append(lora)
|
316 |
|
317 |
return loras_json
|
@@ -319,6 +321,7 @@ def download_loras_images(loras_json_orig: list[dict]):
|
|
319 |
|
320 |
|
321 |
|
|
|
322 |
def add_custom_lora(custom_lora, selected_indices, current_loras, gallery):
|
323 |
"""
|
324 |
Funktion zum Hinzufügen eines benutzerdefinierten LoRA (Low-Rank Adaptation).
|
@@ -403,20 +406,33 @@ def add_custom_lora(custom_lora, selected_indices, current_loras, gallery):
|
|
403 |
|
404 |
|
405 |
|
406 |
-
def update_gallery_with_loras(
|
407 |
"""
|
408 |
-
Aktualisiert die Galerie
|
409 |
"""
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
420 |
|
421 |
|
422 |
|
|
|
284 |
|
285 |
def download_loras_images(loras_json_orig: list[dict]):
|
286 |
"""
|
287 |
+
Überarbeitete Funktion zur Verarbeitung von Bild-URLs aus JSON-Daten und Repositories.
|
288 |
"""
|
289 |
loras_json = []
|
290 |
|
|
|
292 |
repo = lora.get("repo", None)
|
293 |
image_url = lora.get("image", None)
|
294 |
|
295 |
+
# Standardwerte und Fallbacks
|
296 |
lora["title"] = lora.get("title", "Unknown LoRA")
|
297 |
lora["trigger_word"] = lora.get("trigger_word", "")
|
298 |
|
299 |
+
# URL-Validierung und Korrektur
|
300 |
if repo and image_url:
|
301 |
if not image_url.startswith("http"):
|
302 |
+
# URL für Bilder aus Repos korrekt erstellen
|
303 |
image_url = f"https://huggingface.co/{repo}/resolve/main/{image_url}"
|
304 |
try:
|
|
|
305 |
response = requests.head(image_url)
|
306 |
if response.status_code != 200:
|
307 |
+
raise ValueError(f"Bild-URL nicht erreichbar: {image_url}")
|
308 |
except Exception as e:
|
309 |
+
print(f"Fehler beim Laden des Bildes: {e}")
|
310 |
+
image_url = None
|
311 |
+
else:
|
312 |
+
# Falls keine Bild-URL oder Repo angegeben, Platzhalter verwenden
|
313 |
+
image_url = "/path/to/default-placeholder.png"
|
314 |
|
315 |
+
# Finales Bild in das JSON-Objekt einfügen
|
316 |
+
lora["image"] = image_url
|
317 |
loras_json.append(lora)
|
318 |
|
319 |
return loras_json
|
|
|
321 |
|
322 |
|
323 |
|
324 |
+
|
325 |
def add_custom_lora(custom_lora, selected_indices, current_loras, gallery):
|
326 |
"""
|
327 |
Funktion zum Hinzufügen eines benutzerdefinierten LoRA (Low-Rank Adaptation).
|
|
|
406 |
|
407 |
|
408 |
|
409 |
+
def update_gallery_with_loras(selected_indices, loras_state, gallery):
|
410 |
"""
|
411 |
+
Aktualisiert die Galerie basierend auf der Auswahl. Implementiert die Vorschau-Logik.
|
412 |
"""
|
413 |
+
if not selected_indices:
|
414 |
+
# Galerieansicht: Keine Auswahl
|
415 |
+
gallery_items = [(lora["image"], lora["title"]) for lora in loras_state]
|
416 |
+
return gr.update(value=gallery_items), gr.update(visible=False), gr.update(visible=True)
|
417 |
+
|
418 |
+
# Vorschauansicht: Ein Bild wurde ausgewählt
|
419 |
+
selected_lora = loras_state[selected_indices[0]] # Nur das erste ausgewählte Bild
|
420 |
+
preview_image = selected_lora["image"]
|
421 |
+
preview_title = selected_lora["title"]
|
422 |
+
preview_trigger_word = selected_lora.get("trigger_word", "")
|
423 |
+
preview_button_visible = True
|
424 |
+
|
425 |
+
# Micro-Thumbnails erstellen
|
426 |
+
micro_thumbnails = [(lora["image"], "") for lora in loras_state]
|
427 |
+
|
428 |
+
return (
|
429 |
+
gr.update(value=[(preview_image, preview_title)], visible=True),
|
430 |
+
gr.update(value=micro_thumbnails, visible=True),
|
431 |
+
gr.update(visible=False), # Galerie deaktivieren
|
432 |
+
gr.update(value=preview_trigger_word, visible=True),
|
433 |
+
gr.update(visible=preview_button_visible),
|
434 |
+
)
|
435 |
+
|
436 |
|
437 |
|
438 |
|