Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: 🏆😻
|
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 5.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: true
|
| 10 |
license: mit
|
|
|
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.6.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: true
|
| 10 |
license: mit
|
app.py
CHANGED
|
@@ -133,7 +133,7 @@ def change_base_model(repo_id: str, cn_on: bool, disable_model_cache: bool, mode
|
|
| 133 |
change_base_model.zerogpu = True
|
| 134 |
|
| 135 |
def download_file_mod(url, directory=os.getcwd()):
|
| 136 |
-
path = download_hf_file(directory, url)
|
| 137 |
if not path: raise Exception(f"Download error: {url}")
|
| 138 |
return path
|
| 139 |
|
|
@@ -270,11 +270,30 @@ def randomize_loras(selected_indices, loras_state):
|
|
| 270 |
random_prompt = random.choice(prompt_values)
|
| 271 |
return selected_info_1, selected_info_2, selected_indices, lora_scale_1, lora_scale_2, lora_image_1, lora_image_2, random_prompt
|
| 272 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
def add_custom_lora(custom_lora, selected_indices, current_loras, gallery):
|
| 274 |
if custom_lora:
|
| 275 |
try:
|
| 276 |
title, repo, path, trigger_word, image = check_custom_model(custom_lora)
|
| 277 |
-
if "http" in image and not is_repo_public(repo):
|
| 278 |
try:
|
| 279 |
image = download_file_mod(image)
|
| 280 |
except Exception as e:
|
|
@@ -603,7 +622,8 @@ def get_huggingface_safetensors(link):
|
|
| 603 |
base_model = model_card.data.get("base_model")
|
| 604 |
print(f"Base model: {base_model}")
|
| 605 |
if base_model not in ["black-forest-labs/FLUX.1-dev", "black-forest-labs/FLUX.1-schnell"]:
|
| 606 |
-
raise Exception("Not a FLUX LoRA!")
|
|
|
|
| 607 |
image_path = model_card.data.get("widget", [{}])[0].get("output", {}).get("url", None)
|
| 608 |
trigger_word = model_card.data.get("instance_prompt", "")
|
| 609 |
image_url = f"https://huggingface.co/{link}/resolve/main/{image_path}" if image_path else None
|
|
@@ -652,6 +672,8 @@ def update_history(new_image, history):
|
|
| 652 |
history.insert(0, new_image)
|
| 653 |
return history
|
| 654 |
|
|
|
|
|
|
|
| 655 |
css = '''
|
| 656 |
#gen_column{align-self: stretch}
|
| 657 |
#gen_btn{height: 100%}
|
|
@@ -732,7 +754,7 @@ with gr.Blocks(theme='NoCrypt/miku@>=1.2.2', fill_width=True, css=css, delete_ca
|
|
| 732 |
with gr.Column():
|
| 733 |
selected_info = gr.Markdown("")
|
| 734 |
gallery = gr.Gallery([(item["image"], item["title"]) for item in loras], label="LoRA Gallery", allow_preview=False,
|
| 735 |
-
columns=
|
| 736 |
with gr.Group():
|
| 737 |
with gr.Row(elem_id="custom_lora_structure"):
|
| 738 |
custom_lora = gr.Textbox(label="Custom LoRA", info="LoRA Hugging Face path or *.safetensors public URL", placeholder="multimodalart/vintage-ads-flux", scale=3, min_width=150)
|
|
|
|
| 133 |
change_base_model.zerogpu = True
|
| 134 |
|
| 135 |
def download_file_mod(url, directory=os.getcwd()):
|
| 136 |
+
path = download_hf_file(directory, url, hf_token=HF_TOKEN)
|
| 137 |
if not path: raise Exception(f"Download error: {url}")
|
| 138 |
return path
|
| 139 |
|
|
|
|
| 270 |
random_prompt = random.choice(prompt_values)
|
| 271 |
return selected_info_1, selected_info_2, selected_indices, lora_scale_1, lora_scale_2, lora_image_1, lora_image_2, random_prompt
|
| 272 |
|
| 273 |
+
def download_loras_images(loras_json: list[dict]):
|
| 274 |
+
loras_json = copy.deepcopy(loras_json)
|
| 275 |
+
for i, lora in enumerate(loras_json):
|
| 276 |
+
repo = lora.get("repo", None)
|
| 277 |
+
if repo is None: continue
|
| 278 |
+
if "title" not in lora.keys() or "trigger_word" not in lora.keys() or "image" not in lora.keys():
|
| 279 |
+
title, _repo, _path, trigger_word, image_def = check_custom_model(repo)
|
| 280 |
+
if "title" not in lora.keys(): loras_json[i]["title"] = title
|
| 281 |
+
if "trigger_word" not in lora.keys(): loras_json[i]["trigger_word"] = trigger_word
|
| 282 |
+
if "image" not in lora.keys(): lora["image"] = image_def
|
| 283 |
+
image = lora.get("image", None)
|
| 284 |
+
try:
|
| 285 |
+
if not is_repo_public(repo) and image is not None and "http" in image: image = download_file_mod(image)
|
| 286 |
+
loras_json[i]["image"] = image if image else "/home/user/app/custom.png"
|
| 287 |
+
except Exception as e:
|
| 288 |
+
print(e)
|
| 289 |
+
continue
|
| 290 |
+
return loras_json
|
| 291 |
+
|
| 292 |
def add_custom_lora(custom_lora, selected_indices, current_loras, gallery):
|
| 293 |
if custom_lora:
|
| 294 |
try:
|
| 295 |
title, repo, path, trigger_word, image = check_custom_model(custom_lora)
|
| 296 |
+
if image is not None and "http" in image and not is_repo_public(repo):
|
| 297 |
try:
|
| 298 |
image = download_file_mod(image)
|
| 299 |
except Exception as e:
|
|
|
|
| 622 |
base_model = model_card.data.get("base_model")
|
| 623 |
print(f"Base model: {base_model}")
|
| 624 |
if base_model not in ["black-forest-labs/FLUX.1-dev", "black-forest-labs/FLUX.1-schnell"]:
|
| 625 |
+
#raise Exception("Not a FLUX LoRA!")
|
| 626 |
+
gr.Warning("Not a FLUX LoRA?")
|
| 627 |
image_path = model_card.data.get("widget", [{}])[0].get("output", {}).get("url", None)
|
| 628 |
trigger_word = model_card.data.get("instance_prompt", "")
|
| 629 |
image_url = f"https://huggingface.co/{link}/resolve/main/{image_path}" if image_path else None
|
|
|
|
| 672 |
history.insert(0, new_image)
|
| 673 |
return history
|
| 674 |
|
| 675 |
+
loras = download_loras_images(loras)
|
| 676 |
+
|
| 677 |
css = '''
|
| 678 |
#gen_column{align-self: stretch}
|
| 679 |
#gen_btn{height: 100%}
|
|
|
|
| 754 |
with gr.Column():
|
| 755 |
selected_info = gr.Markdown("")
|
| 756 |
gallery = gr.Gallery([(item["image"], item["title"]) for item in loras], label="LoRA Gallery", allow_preview=False,
|
| 757 |
+
columns=4, elem_id="gallery", show_share_button=False, interactive=False)
|
| 758 |
with gr.Group():
|
| 759 |
with gr.Row(elem_id="custom_lora_structure"):
|
| 760 |
custom_lora = gr.Textbox(label="Custom LoRA", info="LoRA Hugging Face path or *.safetensors public URL", placeholder="multimodalart/vintage-ads-flux", scale=3, min_width=150)
|