Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -283,42 +283,48 @@ 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 |
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
|
292 |
lora["title"] = lora.get("title", "Unknown LoRA")
|
293 |
lora["trigger_word"] = lora.get("trigger_word", "")
|
294 |
-
|
295 |
|
296 |
-
|
297 |
-
#
|
298 |
-
|
299 |
-
repo_image_url = f"https://huggingface.co/{repo}/resolve/main/
|
300 |
response = requests.head(repo_image_url)
|
301 |
if response.status_code == 200:
|
302 |
-
|
|
|
303 |
else:
|
304 |
-
print(f"Repo
|
|
|
|
|
305 |
|
306 |
-
|
307 |
-
|
|
|
|
|
|
|
308 |
response = requests.head(image)
|
309 |
if response.status_code == 200:
|
310 |
-
lora["image"] = image
|
311 |
else:
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
if not lora["image"]:
|
316 |
-
raise ValueError("No valid image found, using default.")
|
317 |
-
|
318 |
except Exception as e:
|
319 |
-
|
320 |
-
|
|
|
321 |
|
|
|
322 |
loras_json.append(lora)
|
323 |
|
324 |
return loras_json
|
@@ -327,6 +333,7 @@ def download_loras_images(loras_json_orig: list[dict]):
|
|
327 |
|
328 |
|
329 |
|
|
|
330 |
def add_custom_lora(custom_lora, selected_indices, current_loras, gallery):
|
331 |
if custom_lora:
|
332 |
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 |
+
api = HfApi(token=HF_TOKEN)
|
287 |
loras_json = []
|
288 |
+
|
289 |
for lora in loras_json_orig:
|
290 |
repo = lora.get("repo", None)
|
|
|
291 |
|
292 |
# Standardwerte setzen
|
293 |
lora["title"] = lora.get("title", "Unknown LoRA")
|
294 |
lora["trigger_word"] = lora.get("trigger_word", "")
|
295 |
+
lora["image"] = lora.get("image", "/home/user/app/custom.png") # Fallback
|
296 |
|
297 |
+
if repo and api.repo_exists(repo_id=repo, token=HF_TOKEN):
|
298 |
+
# Wenn das Repo existiert, prüfen, ob das Bild von dort geladen werden kann
|
299 |
+
try:
|
300 |
+
repo_image_url = f"https://huggingface.co/{repo}/resolve/main/{lora['image']}"
|
301 |
response = requests.head(repo_image_url)
|
302 |
if response.status_code == 200:
|
303 |
+
# URL innerhalb des REPOs funktioniert
|
304 |
+
lora["image"] = repo_image_url
|
305 |
else:
|
306 |
+
print(f"Repo image not found: {repo_image_url}")
|
307 |
+
except Exception as e:
|
308 |
+
print(f"Error checking repo image: {e}")
|
309 |
|
310 |
+
# Prüfen auf externe URL (falls angegeben und gültig)
|
311 |
+
image = lora.get("image", None)
|
312 |
+
try:
|
313 |
+
if image and "http" in image:
|
314 |
+
# Bild-URL testen, falls extern
|
315 |
response = requests.head(image)
|
316 |
if response.status_code == 200:
|
317 |
+
lora["image"] = image
|
318 |
else:
|
319 |
+
raise ValueError("Invalid external image URL.")
|
320 |
+
else:
|
321 |
+
raise ValueError("Invalid or missing image URL.")
|
|
|
|
|
|
|
322 |
except Exception as e:
|
323 |
+
# Fehler beim Bild-Download -> Standardbild verwenden
|
324 |
+
print(f"Failed to download image for LoRA '{repo}': {e}")
|
325 |
+
lora["image"] = "/home/user/app/custom.png"
|
326 |
|
327 |
+
# Fügen Sie das LoRA in die Liste ein
|
328 |
loras_json.append(lora)
|
329 |
|
330 |
return loras_json
|
|
|
333 |
|
334 |
|
335 |
|
336 |
+
|
337 |
def add_custom_lora(custom_lora, selected_indices, current_loras, gallery):
|
338 |
if custom_lora:
|
339 |
try:
|