Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -55,7 +55,7 @@ def load_lora_opt(pipe, lora_input):
|
|
| 55 |
|
| 56 |
# If it's just an ID like "author/model"
|
| 57 |
if "/" in lora_input and not lora_input.startswith("http"):
|
| 58 |
-
pipe.load_lora_weights(lora_input)
|
| 59 |
return
|
| 60 |
|
| 61 |
if lora_input.startswith("http"):
|
|
@@ -64,7 +64,7 @@ def load_lora_opt(pipe, lora_input):
|
|
| 64 |
# Repo page (no blob/resolve)
|
| 65 |
if "huggingface.co" in url and "/blob/" not in url and "/resolve/" not in url:
|
| 66 |
repo_id = urlparse(url).path.strip("/")
|
| 67 |
-
pipe.load_lora_weights(repo_id)
|
| 68 |
return
|
| 69 |
|
| 70 |
# Blob link → convert to resolve link
|
|
@@ -83,7 +83,7 @@ def load_lora_opt(pipe, lora_input):
|
|
| 83 |
for chunk in resp.iter_content(chunk_size=8192):
|
| 84 |
f.write(chunk)
|
| 85 |
print(f"Saved LoRA to {local_path}")
|
| 86 |
-
pipe.load_lora_weights(local_path)
|
| 87 |
finally:
|
| 88 |
shutil.rmtree(tmp_dir, ignore_errors=True)
|
| 89 |
|
|
@@ -110,7 +110,11 @@ def generate_qwen(
|
|
| 110 |
|
| 111 |
start_time = time.time()
|
| 112 |
|
| 113 |
-
pipe_qwen.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
use_lora = False
|
| 115 |
if lora_input and lora_input.strip() != "":
|
| 116 |
load_lora_opt(pipe_qwen, lora_input)
|
|
@@ -122,17 +126,14 @@ def generate_qwen(
|
|
| 122 |
negative_prompt=negative_prompt if negative_prompt else "",
|
| 123 |
height=height,
|
| 124 |
width=width,
|
| 125 |
-
true_cfg_scale=guidance_scale,
|
| 126 |
guidance_scale=1.0,
|
|
|
|
| 127 |
num_inference_steps=num_inference_steps,
|
| 128 |
num_images_per_prompt=num_images,
|
| 129 |
generator=generator,
|
| 130 |
output_type="pil",
|
| 131 |
).images
|
| 132 |
|
| 133 |
-
if use_lora:
|
| 134 |
-
pipe_qwen.unload_lora_weights()
|
| 135 |
-
|
| 136 |
end_time = time.time()
|
| 137 |
duration = end_time - start_time
|
| 138 |
|
|
@@ -144,6 +145,12 @@ def generate_qwen(
|
|
| 144 |
for i, img_path in enumerate(image_paths):
|
| 145 |
zipf.write(img_path, arcname=f"Img_{i}.png")
|
| 146 |
zip_path = zip_name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
return image_paths, seed, f"{duration:.2f}", zip_path
|
| 149 |
|
|
|
|
| 55 |
|
| 56 |
# If it's just an ID like "author/model"
|
| 57 |
if "/" in lora_input and not lora_input.startswith("http"):
|
| 58 |
+
pipe.load_lora_weights(lora_input, adapter_name="default")
|
| 59 |
return
|
| 60 |
|
| 61 |
if lora_input.startswith("http"):
|
|
|
|
| 64 |
# Repo page (no blob/resolve)
|
| 65 |
if "huggingface.co" in url and "/blob/" not in url and "/resolve/" not in url:
|
| 66 |
repo_id = urlparse(url).path.strip("/")
|
| 67 |
+
pipe.load_lora_weights(repo_id, adapter_name="default")
|
| 68 |
return
|
| 69 |
|
| 70 |
# Blob link → convert to resolve link
|
|
|
|
| 83 |
for chunk in resp.iter_content(chunk_size=8192):
|
| 84 |
f.write(chunk)
|
| 85 |
print(f"Saved LoRA to {local_path}")
|
| 86 |
+
pipe.load_lora_weights(local_path, adapter_name="default")
|
| 87 |
finally:
|
| 88 |
shutil.rmtree(tmp_dir, ignore_errors=True)
|
| 89 |
|
|
|
|
| 110 |
|
| 111 |
start_time = time.time()
|
| 112 |
|
| 113 |
+
current_adapters = pipe_qwen.get_list_adapters()
|
| 114 |
+
for adapter in current_adapters:
|
| 115 |
+
pipe_qwen.delete_adapters(adapter)
|
| 116 |
+
pipe_qwen.disable_lora()
|
| 117 |
+
|
| 118 |
use_lora = False
|
| 119 |
if lora_input and lora_input.strip() != "":
|
| 120 |
load_lora_opt(pipe_qwen, lora_input)
|
|
|
|
| 126 |
negative_prompt=negative_prompt if negative_prompt else "",
|
| 127 |
height=height,
|
| 128 |
width=width,
|
|
|
|
| 129 |
guidance_scale=1.0,
|
| 130 |
+
true_guidance_scale=guidance_scale,
|
| 131 |
num_inference_steps=num_inference_steps,
|
| 132 |
num_images_per_prompt=num_images,
|
| 133 |
generator=generator,
|
| 134 |
output_type="pil",
|
| 135 |
).images
|
| 136 |
|
|
|
|
|
|
|
|
|
|
| 137 |
end_time = time.time()
|
| 138 |
duration = end_time - start_time
|
| 139 |
|
|
|
|
| 145 |
for i, img_path in enumerate(image_paths):
|
| 146 |
zipf.write(img_path, arcname=f"Img_{i}.png")
|
| 147 |
zip_path = zip_name
|
| 148 |
+
|
| 149 |
+
# Clean up adapters
|
| 150 |
+
current_adapters = pipe_qwen.get_list_adapters()
|
| 151 |
+
for adapter in current_adapters:
|
| 152 |
+
pipe_qwen.delete_adapters(adapter)
|
| 153 |
+
pipe_qwen.disable_lora()
|
| 154 |
|
| 155 |
return image_paths, seed, f"{duration:.2f}", zip_path
|
| 156 |
|