macgaga commited on
Commit
1a0f40c
·
verified ·
1 Parent(s): f2965b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -14
app.py CHANGED
@@ -287,24 +287,41 @@ 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
- if repo is None or not api.repo_exists(repo_id=repo, token=HF_TOKEN):
291
- print(f"LoRA '{repo}' is not exsit.")
292
- continue
293
- if "title" not in lora.keys() or "trigger_word" not in lora.keys() or "image" not in lora.keys():
294
- title, _repo, _path, trigger_word, image_def = check_custom_model(repo)
295
- if "title" not in lora.keys(): lora["title"] = title
296
- if "trigger_word" not in lora.keys(): lora["trigger_word"] = trigger_word
297
- if "image" not in lora.keys(): lora["image"] = image_def
 
 
 
 
 
 
 
 
 
 
 
 
 
298
  image = lora.get("image", None)
299
- try:
300
- if not is_repo_public(repo) and image is not None and "http" in image and repo in image: image = download_file_mod(image)
301
- lora["image"] = image if image else "/home/user/app/custom.png"
302
- except Exception as e:
303
- print(f"Failed to download LoRA '{repo}''s image '{image if image else ''}'. {e}")
304
- lora["image"] = "/home/user/app/custom.png"
 
 
305
  loras_json.append(lora)
 
306
  return loras_json
307
 
 
308
  def add_custom_lora(custom_lora, selected_indices, current_loras, gallery):
309
  if custom_lora:
310
  try:
 
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: