Update app.py
Browse files
app.py
CHANGED
|
@@ -1,67 +1,22 @@
|
|
| 1 |
import os
|
| 2 |
-
|
| 3 |
-
# ---- HARD CPU SAFETY ----
|
| 4 |
-
os.environ["DIFFUSERS_NO_BITSANDBYTES"] = "1"
|
| 5 |
-
os.environ["CUDA_VISIBLE_DEVICES"] = ""
|
| 6 |
-
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
|
| 7 |
-
|
| 8 |
import torch
|
| 9 |
-
|
| 10 |
-
from diffusers import Flux2KleinPipeline
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
print("Loading FLUX.2 Klein 4B (CPU mode)...")
|
| 17 |
|
| 18 |
-
pipe =
|
| 19 |
-
"black-forest-labs/FLUX.
|
| 20 |
-
torch_dtype=
|
| 21 |
)
|
| 22 |
-
pipe.to(DEVICE)
|
| 23 |
-
|
| 24 |
-
pipe.enable_attention_slicing()
|
| 25 |
-
|
| 26 |
-
def generate(
|
| 27 |
-
prompt,
|
| 28 |
-
steps=2,
|
| 29 |
-
guidance=1.0,
|
| 30 |
-
width=384,
|
| 31 |
-
height=384,
|
| 32 |
-
):
|
| 33 |
-
image = pipe(
|
| 34 |
-
prompt=prompt,
|
| 35 |
-
num_inference_steps=steps,
|
| 36 |
-
guidance_scale=guidance,
|
| 37 |
-
width=width,
|
| 38 |
-
height=height,
|
| 39 |
-
).images[0]
|
| 40 |
-
return image
|
| 41 |
-
|
| 42 |
-
with gr.Blocks() as demo:
|
| 43 |
-
gr.Markdown("# FLUX.2 Klein 4B — CPU (Experimental)")
|
| 44 |
-
|
| 45 |
-
prompt = gr.Textbox(
|
| 46 |
-
label="Prompt",
|
| 47 |
-
placeholder="A watercolor painting of a small house in the mountains",
|
| 48 |
-
)
|
| 49 |
-
|
| 50 |
-
with gr.Row():
|
| 51 |
-
steps = gr.Slider(1, 4, value=2, step=1, label="Steps")
|
| 52 |
-
guidance = gr.Slider(0.5, 2.0, value=1.0, step=0.1, label="CFG")
|
| 53 |
-
|
| 54 |
-
with gr.Row():
|
| 55 |
-
width = gr.Slider(256, MAX_SIZE, value=384, step=64, label="Width")
|
| 56 |
-
height = gr.Slider(256, MAX_SIZE, value=384, step=64, label="Height")
|
| 57 |
|
| 58 |
-
|
| 59 |
-
output = gr.Image()
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
)
|
| 66 |
|
| 67 |
-
|
|
|
|
|
|
| 1 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import torch
|
| 3 |
+
from diffusers import FluxPipeline
|
|
|
|
| 4 |
|
| 5 |
+
# Force CPU
|
| 6 |
+
os.environ["CUDA_VISIBLE_DEVICES"] = ""
|
| 7 |
+
os.environ["DIFFUSERS_NO_BITSANDBYTES"] = "1"
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
pipe = FluxPipeline.from_pretrained(
|
| 10 |
+
"black-forest-labs/FLUX.1-dev",
|
| 11 |
+
torch_dtype=torch.float32
|
| 12 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
pipe.to("cpu")
|
|
|
|
| 15 |
|
| 16 |
+
image = pipe(
|
| 17 |
+
prompt="a cinematic portrait of a cyberpunk warrior",
|
| 18 |
+
num_inference_steps=20
|
| 19 |
+
).images[0]
|
|
|
|
| 20 |
|
| 21 |
+
image.save("output.png")
|
| 22 |
+
print("✅ Generated on CPU")
|