Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,27 +3,24 @@ import spaces
|
|
| 3 |
import gradio as gr
|
| 4 |
from diffusers import DiffusionPipeline
|
| 5 |
|
| 6 |
-
# Load the pipeline once at startup
|
| 7 |
print("Booting BRAINDANCE FACTORY neural core...")
|
| 8 |
pipe = DiffusionPipeline.from_pretrained(
|
| 9 |
"Tongyi-MAI/Z-Image-Turbo",
|
| 10 |
torch_dtype=torch.bfloat16,
|
| 11 |
low_cpu_mem_usage=False,
|
| 12 |
)
|
| 13 |
-
pipe.to("cuda")
|
| 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("Neural core online. Synaptic links established.")
|
| 20 |
|
| 21 |
@spaces.GPU
|
| 22 |
def generate_image(prompt, height, width, num_inference_steps, seed, randomize_seed, progress=gr.Progress(track_tqdm=True)):
|
| 23 |
"""Jack in. Generate."""
|
|
|
|
|
|
|
| 24 |
if randomize_seed:
|
| 25 |
seed = torch.randint(0, 2**32 - 1, (1,)).item()
|
| 26 |
-
|
| 27 |
generator = torch.Generator("cuda").manual_seed(int(seed))
|
| 28 |
image = pipe(
|
| 29 |
prompt=prompt,
|
|
@@ -33,7 +30,9 @@ def generate_image(prompt, height, width, num_inference_steps, seed, randomize_s
|
|
| 33 |
guidance_scale=0.0,
|
| 34 |
generator=generator,
|
| 35 |
).images[0]
|
| 36 |
-
|
|
|
|
|
|
|
| 37 |
return image, seed
|
| 38 |
|
| 39 |
ci_look = """
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
from diffusers import DiffusionPipeline
|
| 5 |
|
| 6 |
+
# Load the pipeline once at startup — on CPU only
|
| 7 |
print("Booting BRAINDANCE FACTORY neural core...")
|
| 8 |
pipe = DiffusionPipeline.from_pretrained(
|
| 9 |
"Tongyi-MAI/Z-Image-Turbo",
|
| 10 |
torch_dtype=torch.bfloat16,
|
| 11 |
low_cpu_mem_usage=False,
|
| 12 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
print("Neural core online. Synaptic links established.")
|
| 15 |
|
| 16 |
@spaces.GPU
|
| 17 |
def generate_image(prompt, height, width, num_inference_steps, seed, randomize_seed, progress=gr.Progress(track_tqdm=True)):
|
| 18 |
"""Jack in. Generate."""
|
| 19 |
+
pipe.to("cuda") # ✅ GPU is only available inside @spaces.GPU functions
|
| 20 |
+
|
| 21 |
if randomize_seed:
|
| 22 |
seed = torch.randint(0, 2**32 - 1, (1,)).item()
|
| 23 |
+
|
| 24 |
generator = torch.Generator("cuda").manual_seed(int(seed))
|
| 25 |
image = pipe(
|
| 26 |
prompt=prompt,
|
|
|
|
| 30 |
guidance_scale=0.0,
|
| 31 |
generator=generator,
|
| 32 |
).images[0]
|
| 33 |
+
|
| 34 |
+
pipe.to("cpu") # ✅ Optional but good practice: release GPU between ZeroGPU calls
|
| 35 |
+
|
| 36 |
return image, seed
|
| 37 |
|
| 38 |
ci_look = """
|