Spaces:
Running
on
Zero
Running
on
Zero
Update app_lora1.py
Browse files- app_lora1.py +14 -25
app_lora1.py
CHANGED
|
@@ -160,42 +160,31 @@ def get_pipeline(script_name):
|
|
| 160 |
return PIPELINES[script_name]
|
| 161 |
|
| 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(
|
| 183 |
except Exception as e:
|
| 184 |
-
log(f"❌
|
| 185 |
raise RuntimeError(f"Pipeline build failed for {script_name}") from e
|
| 186 |
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 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 |
# =========================================================
|
|
|
|
| 160 |
return PIPELINES[script_name]
|
| 161 |
|
| 162 |
log(f"🔧 Building pipeline from {script_name}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
namespace = {
|
| 165 |
+
"__file__": script_name,
|
| 166 |
+
"__name__": "__main__",
|
| 167 |
+
|
| 168 |
+
# Minimal required globals
|
| 169 |
"torch": torch,
|
|
|
|
|
|
|
|
|
|
| 170 |
}
|
| 171 |
|
|
|
|
| 172 |
try:
|
| 173 |
+
exec(SCRIPT_CODE[script_name], namespace)
|
| 174 |
except Exception as e:
|
| 175 |
+
log(f"❌ Script failed: {script_name}")
|
| 176 |
raise RuntimeError(f"Pipeline build failed for {script_name}") from e
|
| 177 |
|
| 178 |
+
if "pipe" not in namespace:
|
| 179 |
+
raise RuntimeError(
|
| 180 |
+
f"{script_name} did not define `pipe`.\n"
|
| 181 |
+
f"Each script MUST assign a variable named `pipe`."
|
| 182 |
+
)
|
|
|
|
|
|
|
| 183 |
|
| 184 |
+
PIPELINES[script_name] = namespace["pipe"]
|
| 185 |
+
log(f"✅ Pipeline ready: {script_name}")
|
|
|
|
| 186 |
|
| 187 |
+
return PIPELINES[script_name]
|
| 188 |
|
| 189 |
|
| 190 |
# =========================================================
|