Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,24 +7,20 @@ from diffusers import DiffusionPipeline
|
|
| 7 |
print("Loading Z-Image-Turbo pipeline...")
|
| 8 |
pipe = DiffusionPipeline.from_pretrained(
|
| 9 |
"Tongyi-MAI/Z-Image-Turbo",
|
| 10 |
-
torch_dtype=torch.
|
| 11 |
-
low_cpu_mem_usage=
|
| 12 |
)
|
| 13 |
-
pipe.to("
|
| 14 |
-
|
| 15 |
-
# ======== AoTI compilation + FA3 ========
|
| 16 |
-
# pipe.transformer.layers._repeated_blocks = ["ZImageTransformerBlock"]
|
| 17 |
-
# spaces.aoti_blocks_load(pipe.transformer.layers, "zerogpu-aoti/Z-Image", variant="fa3")
|
| 18 |
|
| 19 |
print("Pipeline loaded!")
|
| 20 |
|
| 21 |
-
@spaces.GPU
|
| 22 |
def generate_image(prompt, height, width, num_inference_steps, seed, randomize_seed, progress=gr.Progress(track_tqdm=True)):
|
| 23 |
"""Generate an image from the given prompt."""
|
| 24 |
if randomize_seed:
|
| 25 |
seed = torch.randint(0, 2**32 - 1, (1,)).item()
|
| 26 |
|
| 27 |
-
generator = torch.Generator("
|
|
|
|
| 28 |
image = pipe(
|
| 29 |
prompt=prompt,
|
| 30 |
height=int(height),
|
|
@@ -194,67 +190,5 @@ with gr.Blocks(fill_height=True) as demo:
|
|
| 194 |
if __name__ == "__main__":
|
| 195 |
demo.launch(
|
| 196 |
theme=custom_theme,
|
| 197 |
-
css="""
|
| 198 |
-
.header-text h1 {
|
| 199 |
-
font-size: 2.5rem !important;
|
| 200 |
-
font-weight: 700 !important;
|
| 201 |
-
margin-bottom: 0.5rem !important;
|
| 202 |
-
background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
|
| 203 |
-
-webkit-background-clip: text;
|
| 204 |
-
-webkit-text-fill-color: transparent;
|
| 205 |
-
background-clip: text;
|
| 206 |
-
}
|
| 207 |
-
|
| 208 |
-
.header-text p {
|
| 209 |
-
font-size: 1.1rem !important;
|
| 210 |
-
color: #64748b !important;
|
| 211 |
-
margin-top: 0 !important;
|
| 212 |
-
}
|
| 213 |
-
|
| 214 |
-
.footer-text {
|
| 215 |
-
padding: 1rem 0;
|
| 216 |
-
}
|
| 217 |
-
|
| 218 |
-
.footer-text a {
|
| 219 |
-
color: #f59e0b !important;
|
| 220 |
-
text-decoration: none !important;
|
| 221 |
-
font-weight: 500;
|
| 222 |
-
}
|
| 223 |
-
|
| 224 |
-
.footer-text a:hover {
|
| 225 |
-
text-decoration: underline !important;
|
| 226 |
-
}
|
| 227 |
-
|
| 228 |
-
/* Mobile optimizations */
|
| 229 |
-
@media (max-width: 768px) {
|
| 230 |
-
.header-text h1 {
|
| 231 |
-
font-size: 1.8rem !important;
|
| 232 |
-
}
|
| 233 |
-
|
| 234 |
-
.header-text p {
|
| 235 |
-
font-size: 1rem !important;
|
| 236 |
-
}
|
| 237 |
-
}
|
| 238 |
-
|
| 239 |
-
/* Smooth transitions */
|
| 240 |
-
button, .gr-button {
|
| 241 |
-
transition: all 0.2s ease !important;
|
| 242 |
-
}
|
| 243 |
-
|
| 244 |
-
button:hover, .gr-button:hover {
|
| 245 |
-
transform: translateY(-1px);
|
| 246 |
-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
|
| 247 |
-
}
|
| 248 |
-
|
| 249 |
-
/* Better spacing */
|
| 250 |
-
.gradio-container {
|
| 251 |
-
max-width: 1400px !important;
|
| 252 |
-
margin: 0 auto !important;
|
| 253 |
-
}
|
| 254 |
-
""",
|
| 255 |
-
footer_links=[
|
| 256 |
-
"api",
|
| 257 |
-
"gradio"
|
| 258 |
-
],
|
| 259 |
mcp_server=True
|
| 260 |
-
)
|
|
|
|
| 7 |
print("Loading Z-Image-Turbo pipeline...")
|
| 8 |
pipe = DiffusionPipeline.from_pretrained(
|
| 9 |
"Tongyi-MAI/Z-Image-Turbo",
|
| 10 |
+
torch_dtype=torch.float32, # CPU-friendly
|
| 11 |
+
low_cpu_mem_usage=True,
|
| 12 |
)
|
| 13 |
+
pipe.to("cpu") # CPU mode
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
print("Pipeline loaded!")
|
| 16 |
|
|
|
|
| 17 |
def generate_image(prompt, height, width, num_inference_steps, seed, randomize_seed, progress=gr.Progress(track_tqdm=True)):
|
| 18 |
"""Generate an image from the given prompt."""
|
| 19 |
if randomize_seed:
|
| 20 |
seed = torch.randint(0, 2**32 - 1, (1,)).item()
|
| 21 |
|
| 22 |
+
generator = torch.Generator("cpu").manual_seed(int(seed))
|
| 23 |
+
|
| 24 |
image = pipe(
|
| 25 |
prompt=prompt,
|
| 26 |
height=int(height),
|
|
|
|
| 190 |
if __name__ == "__main__":
|
| 191 |
demo.launch(
|
| 192 |
theme=custom_theme,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
mcp_server=True
|
| 194 |
+
)
|