Spaces:
Running
on
Zero
Running
on
Zero
Update app_lora1.py
Browse files- app_lora1.py +23 -10
app_lora1.py
CHANGED
|
@@ -162,29 +162,42 @@ def get_pipeline(script_name):
|
|
| 162 |
log(f"🔧 Building pipeline from {script_name}")
|
| 163 |
code = SCRIPT_CODE[script_name]
|
| 164 |
|
| 165 |
-
# Extract lines after from_pretrained
|
| 166 |
pipe_lines = extract_pipe_lines(code)
|
|
|
|
| 167 |
|
| 168 |
-
# Safe namespace
|
| 169 |
-
|
|
|
|
| 170 |
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
if pipe is None:
|
| 179 |
raise RuntimeError(f"{script_name} did not define `pipe`.")
|
| 180 |
|
| 181 |
-
|
|
|
|
|
|
|
| 182 |
|
| 183 |
PIPELINES[script_name] = pipe
|
| 184 |
log("✅ Pipeline ready")
|
| 185 |
return pipe
|
| 186 |
|
| 187 |
|
|
|
|
| 188 |
# =========================================================
|
| 189 |
# IMAGE GENERATION
|
| 190 |
# =========================================================
|
|
|
|
| 162 |
log(f"🔧 Building pipeline from {script_name}")
|
| 163 |
code = SCRIPT_CODE[script_name]
|
| 164 |
|
| 165 |
+
# Extract all lines after from_pretrained
|
| 166 |
pipe_lines = extract_pipe_lines(code)
|
| 167 |
+
pipe_code = "\n".join(pipe_lines) # <-- combine into full block
|
| 168 |
|
| 169 |
+
# Safe namespace
|
| 170 |
+
from diffusers.models.transformers.z_image_transformer_2d import ZImageTransformer2DModel
|
| 171 |
+
from diffusers.models.model_loading_utils import GGUFQuantizationConfig
|
| 172 |
|
| 173 |
+
namespace = {
|
| 174 |
+
"torch": torch,
|
| 175 |
+
"ZImagePipeline": ZImagePipeline,
|
| 176 |
+
"ZImageTransformer2DModel": ZImageTransformer2DModel,
|
| 177 |
+
"GGUFQuantizationConfig": GGUFQuantizationConfig,
|
| 178 |
+
}
|
| 179 |
|
| 180 |
+
# Execute entire block at once
|
| 181 |
+
try:
|
| 182 |
+
exec(pipe_code, namespace)
|
| 183 |
+
except Exception as e:
|
| 184 |
+
log(f"❌ Pipeline build failed: {e}")
|
| 185 |
+
raise RuntimeError(f"Pipeline build failed for {script_name}") from e
|
| 186 |
+
|
| 187 |
+
pipe = namespace.get("pipe", None)
|
| 188 |
if pipe is None:
|
| 189 |
raise RuntimeError(f"{script_name} did not define `pipe`.")
|
| 190 |
|
| 191 |
+
# Move to CUDA only if not device_map
|
| 192 |
+
if not hasattr(pipe, "hf_device_map"):
|
| 193 |
+
pipe = pipe.to("cuda")
|
| 194 |
|
| 195 |
PIPELINES[script_name] = pipe
|
| 196 |
log("✅ Pipeline ready")
|
| 197 |
return pipe
|
| 198 |
|
| 199 |
|
| 200 |
+
|
| 201 |
# =========================================================
|
| 202 |
# IMAGE GENERATION
|
| 203 |
# =========================================================
|