macgaga commited on
Commit
f0555a1
·
verified ·
1 Parent(s): 4633f83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -21
app.py CHANGED
@@ -283,38 +283,38 @@ def randomize_loras(selected_indices, loras_state):
283
  return selected_info_1, selected_info_2, selected_indices, lora_scale_1, lora_scale_2, lora_image_1, lora_image_2, random_prompt
284
 
285
  def download_loras_images(loras_json_orig: list[dict]):
286
- api = HfApi(token=HF_TOKEN)
287
  loras_json = []
288
  for lora in loras_json_orig:
289
  repo = lora.get("repo", None)
290
- if repo is None or not api.repo_exists(repo_id=repo, token=HF_TOKEN):
291
- print(f"LoRA '{repo}' does not exist.")
292
- continue
293
 
294
- if "title" not in lora.keys() or "trigger_word" not in lora.keys() or "image" not in lora.keys():
295
- # Standardwerte setzen
296
- lora["title"] = lora.get("title", "Unknown LoRA")
297
- lora["trigger_word"] = lora.get("trigger_word", "")
298
- lora["image"] = "/home/user/app/custom.png" # Fallback-Standardbild
299
 
300
- image = lora.get("image", None)
301
- try:
302
- if image and "http" in image:
303
- # Bild herunterladen, falls es eine gültige URL ist
304
- image = download_file_mod(image)
305
- else:
306
- raise ValueError("Invalid or missing image URL.")
307
- except Exception as e:
308
- # Fehler beim Bild-Download -> Standardbild verwenden
309
- print(f"Failed to download image for LoRA '{repo}': {e}")
310
- image = "/home/user/app/custom.png"
 
 
 
311
 
312
- lora["image"] = image
313
  loras_json.append(lora)
 
314
  return loras_json
315
 
316
 
317
 
 
318
  def add_custom_lora(custom_lora, selected_indices, current_loras, gallery):
319
  if custom_lora:
320
  try:
 
283
  return selected_info_1, selected_info_2, selected_indices, lora_scale_1, lora_scale_2, lora_image_1, lora_image_2, random_prompt
284
 
285
  def download_loras_images(loras_json_orig: list[dict]):
 
286
  loras_json = []
287
  for lora in loras_json_orig:
288
  repo = lora.get("repo", None)
289
+ image = lora.get("image", None)
 
 
290
 
291
+ # Standardwerte setzen, falls sie fehlen
292
+ lora["title"] = lora.get("title", "Unknown LoRA")
293
+ lora["trigger_word"] = lora.get("trigger_word", "")
294
+ lora["image"] = image or "/home/user/app/custom.png" # Standardbild setzen
 
295
 
296
+ # Validierung der Bild-URL (ohne erzwungenen Download)
297
+ if image and "http" in image:
298
+ try:
299
+ response = requests.head(image)
300
+ if response.status_code == 200:
301
+ lora["image"] = image # URL ist gültig, kein Download erforderlich
302
+ else:
303
+ raise ValueError(f"Image URL responded with status {response.status_code}")
304
+ except Exception as e:
305
+ print(f"Failed to validate image URL for LoRA '{repo}': {e}")
306
+ lora["image"] = "/home/user/app/custom.png" # Platzhalterbild verwenden
307
+ else:
308
+ print(f"Invalid or missing image URL for LoRA '{repo}'")
309
+ lora["image"] = "/home/user/app/custom.png" # Platzhalterbild verwenden
310
 
 
311
  loras_json.append(lora)
312
+
313
  return loras_json
314
 
315
 
316
 
317
+
318
  def add_custom_lora(custom_lora, selected_indices, current_loras, gallery):
319
  if custom_lora:
320
  try: