macgaga commited on
Commit
1e36e63
·
verified ·
1 Parent(s): 89c72b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -28
app.py CHANGED
@@ -287,41 +287,34 @@ def download_loras_images(loras_json_orig: list[dict]):
287
  loras_json = []
288
  for lora in loras_json_orig:
289
  repo = lora.get("repo", None)
 
 
 
290
 
291
- # Behandlung für Hugging Face-Repos
292
- if repo != "civitai":
293
- if repo is None or not api.repo_exists(repo_id=repo, token=HF_TOKEN):
294
- print(f"LoRA '{repo}' does not exist.")
295
- continue
296
- else:
297
- # Behandlung für Civitai-Links
298
- download_url = lora.get("url", None)
299
- if not download_url:
300
- print(f"No download URL provided for Civitai LoRA: {lora.get('title', 'Unknown')}")
301
- continue
302
- try:
303
- # Download der LoRA-Datei
304
- lora_path = download_file_mod(download_url)
305
- lora["weights"] = lora_path
306
- except Exception as e:
307
- print(f"Failed to download Civitai LoRA '{lora.get('title', 'Unknown')}' from '{download_url}': {e}")
308
- continue
309
 
310
- # Herunterladen oder Verarbeiten von Bildern
311
  image = lora.get("image", None)
312
- if image:
313
- try:
314
- if repo != "civitai" and not is_repo_public(repo) and "http" in image and repo in image:
315
- image = download_file_mod(image)
316
- except Exception as e:
317
- print(f"Failed to download image for LoRA '{repo}': {e}")
318
- image = "/home/user/app/custom.png"
319
- lora["image"] = image if image else "/home/user/app/custom.png"
320
- loras_json.append(lora)
 
321
 
 
 
322
  return loras_json
323
 
324
 
 
325
  def add_custom_lora(custom_lora, selected_indices, current_loras, gallery):
326
  if custom_lora:
327
  try:
 
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: