Spaces:
Running
on
Zero
Running
on
Zero
Update app_lora1.py
Browse files- app_lora1.py +41 -11
app_lora1.py
CHANGED
|
@@ -2,6 +2,7 @@ import spaces
|
|
| 2 |
import os
|
| 3 |
import io
|
| 4 |
import torch
|
|
|
|
| 5 |
|
| 6 |
import gradio as gr
|
| 7 |
import requests
|
|
@@ -78,6 +79,7 @@ def pipeline_technology_info(pipe):
|
|
| 78 |
|
| 79 |
return "\n".join(f"• {t}" for t in tech)
|
| 80 |
|
|
|
|
| 81 |
def pipeline_debug_info(pipe):
|
| 82 |
return f"""
|
| 83 |
Pipeline Info
|
|
@@ -94,6 +96,15 @@ def latent_shape_info(height, width, pipe):
|
|
| 94 |
return f"Expected latent size: ({h}, {w})"
|
| 95 |
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
# =========================================================
|
| 98 |
# DOWNLOAD SCRIPTS (CPU ONLY)
|
| 99 |
# =========================================================
|
|
@@ -134,8 +145,6 @@ def register_scripts(selected_scripts):
|
|
| 134 |
# =========================================================
|
| 135 |
# GPU-ONLY PIPELINE BUILDER (CRITICAL)
|
| 136 |
# =========================================================
|
| 137 |
-
|
| 138 |
-
|
| 139 |
def get_pipeline(script_name):
|
| 140 |
if script_name in PIPELINES:
|
| 141 |
return PIPELINES[script_name]
|
|
@@ -148,6 +157,7 @@ def get_pipeline(script_name):
|
|
| 148 |
|
| 149 |
# Minimal required globals
|
| 150 |
"torch": torch,
|
|
|
|
| 151 |
}
|
| 152 |
|
| 153 |
try:
|
|
@@ -168,7 +178,6 @@ def get_pipeline(script_name):
|
|
| 168 |
return PIPELINES[script_name]
|
| 169 |
|
| 170 |
|
| 171 |
-
|
| 172 |
# =========================================================
|
| 173 |
# IMAGE GENERATION (LOGIC UNCHANGED)
|
| 174 |
# =========================================================
|
|
@@ -190,18 +199,27 @@ def generate_image(
|
|
| 190 |
raise RuntimeError("Pipeline not registered")
|
| 191 |
|
| 192 |
pipe = get_pipeline(pipeline_name)
|
| 193 |
-
|
| 194 |
-
|
| 195 |
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
# ✅ Correct, universal, ZeroGPU-safe
|
| 199 |
if not hasattr(pipe, "hf_device_map"):
|
| 200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
log("=== PIPELINE TECHNOLOGY ===")
|
| 202 |
log(pipeline_technology_info(pipe))
|
| 203 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
|
|
|
|
|
|
|
|
|
|
| 205 |
log("=== NEW GENERATION REQUEST ===")
|
| 206 |
log(f"Pipeline: {pipeline_name}")
|
| 207 |
log(f"Prompt: {prompt}")
|
|
@@ -230,6 +248,13 @@ def generate_image(
|
|
| 230 |
output_type="pil",
|
| 231 |
)
|
| 232 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
try:
|
| 234 |
log(pipeline_debug_info(pipe))
|
| 235 |
log(latent_shape_info(height, width, pipe))
|
|
@@ -238,7 +263,7 @@ def generate_image(
|
|
| 238 |
|
| 239 |
log("Generation complete ✅")
|
| 240 |
|
| 241 |
-
return
|
| 242 |
|
| 243 |
|
| 244 |
# =========================================================
|
|
@@ -284,7 +309,12 @@ with gr.Blocks(title="Z-Image Turbo – ZeroGPU") as demo:
|
|
| 284 |
|
| 285 |
run_btn = gr.Button("Generate")
|
| 286 |
|
| 287 |
-
gallery = gr.Gallery(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
used_seed = gr.Number(label="Used Seed")
|
| 289 |
logs = gr.Textbox(lines=12, label="Logs")
|
| 290 |
|
|
|
|
| 2 |
import os
|
| 3 |
import io
|
| 4 |
import torch
|
| 5 |
+
from PIL import Image
|
| 6 |
|
| 7 |
import gradio as gr
|
| 8 |
import requests
|
|
|
|
| 79 |
|
| 80 |
return "\n".join(f"• {t}" for t in tech)
|
| 81 |
|
| 82 |
+
|
| 83 |
def pipeline_debug_info(pipe):
|
| 84 |
return f"""
|
| 85 |
Pipeline Info
|
|
|
|
| 96 |
return f"Expected latent size: ({h}, {w})"
|
| 97 |
|
| 98 |
|
| 99 |
+
# =========================================================
|
| 100 |
+
# PIPELINE FEATURE REGISTRATION HELPER
|
| 101 |
+
# =========================================================
|
| 102 |
+
def register_pipeline_feature(pipe, text: str):
|
| 103 |
+
if not hasattr(pipe, "_enabled_features"):
|
| 104 |
+
pipe._enabled_features = []
|
| 105 |
+
pipe._enabled_features.append(text)
|
| 106 |
+
|
| 107 |
+
|
| 108 |
# =========================================================
|
| 109 |
# DOWNLOAD SCRIPTS (CPU ONLY)
|
| 110 |
# =========================================================
|
|
|
|
| 145 |
# =========================================================
|
| 146 |
# GPU-ONLY PIPELINE BUILDER (CRITICAL)
|
| 147 |
# =========================================================
|
|
|
|
|
|
|
| 148 |
def get_pipeline(script_name):
|
| 149 |
if script_name in PIPELINES:
|
| 150 |
return PIPELINES[script_name]
|
|
|
|
| 157 |
|
| 158 |
# Minimal required globals
|
| 159 |
"torch": torch,
|
| 160 |
+
"register_pipeline_feature": register_pipeline_feature,
|
| 161 |
}
|
| 162 |
|
| 163 |
try:
|
|
|
|
| 178 |
return PIPELINES[script_name]
|
| 179 |
|
| 180 |
|
|
|
|
| 181 |
# =========================================================
|
| 182 |
# IMAGE GENERATION (LOGIC UNCHANGED)
|
| 183 |
# =========================================================
|
|
|
|
| 199 |
raise RuntimeError("Pipeline not registered")
|
| 200 |
|
| 201 |
pipe = get_pipeline(pipeline_name)
|
|
|
|
|
|
|
| 202 |
|
| 203 |
+
# ✅ Correct, universal, ZeroGPU-safe
|
|
|
|
|
|
|
| 204 |
if not hasattr(pipe, "hf_device_map"):
|
| 205 |
+
pipe = pipe.to("cuda")
|
| 206 |
+
|
| 207 |
+
# =========================================================
|
| 208 |
+
# LOG PIPELINE TECHNOLOGY AND REGISTERED FEATURES
|
| 209 |
+
# =========================================================
|
| 210 |
log("=== PIPELINE TECHNOLOGY ===")
|
| 211 |
log(pipeline_technology_info(pipe))
|
| 212 |
|
| 213 |
+
log("=== PIPELINE FEATURES ===")
|
| 214 |
+
if hasattr(pipe, "_enabled_features"):
|
| 215 |
+
for f in pipe._enabled_features:
|
| 216 |
+
log(f"✔ {f}")
|
| 217 |
+
else:
|
| 218 |
+
log("✔ No explicit pipeline features registered")
|
| 219 |
|
| 220 |
+
# =========================================================
|
| 221 |
+
# GENERATION LOG
|
| 222 |
+
# =========================================================
|
| 223 |
log("=== NEW GENERATION REQUEST ===")
|
| 224 |
log(f"Pipeline: {pipeline_name}")
|
| 225 |
log(f"Prompt: {prompt}")
|
|
|
|
| 248 |
output_type="pil",
|
| 249 |
)
|
| 250 |
|
| 251 |
+
# Resize images to 512x512 for Gradio
|
| 252 |
+
fixed_images = []
|
| 253 |
+
for img in result.images:
|
| 254 |
+
if isinstance(img, Image.Image):
|
| 255 |
+
img = img.resize((512, 512), Image.BICUBIC)
|
| 256 |
+
fixed_images.append(img)
|
| 257 |
+
|
| 258 |
try:
|
| 259 |
log(pipeline_debug_info(pipe))
|
| 260 |
log(latent_shape_info(height, width, pipe))
|
|
|
|
| 263 |
|
| 264 |
log("Generation complete ✅")
|
| 265 |
|
| 266 |
+
return fixed_images, seed, log_buffer.getvalue()
|
| 267 |
|
| 268 |
|
| 269 |
# =========================================================
|
|
|
|
| 309 |
|
| 310 |
run_btn = gr.Button("Generate")
|
| 311 |
|
| 312 |
+
gallery = gr.Gallery(
|
| 313 |
+
columns=3,
|
| 314 |
+
height=512,
|
| 315 |
+
object_fit="contain",
|
| 316 |
+
label="Output (512×512)"
|
| 317 |
+
)
|
| 318 |
used_seed = gr.Number(label="Used Seed")
|
| 319 |
logs = gr.Textbox(lines=12, label="Logs")
|
| 320 |
|