File size: 785 Bytes
ff7a54c
 
3c943b9
 
ff7daae
 
ff7a54c
ff7daae
 
 
 
 
ff7a54c
ff7daae
 
 
 
ff7a54c
 
 
 
 
 
 
 
 
ff7daae
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import torch
from diffusers import FluxPipeline
from huggingface_hub import login

# Authenticate (required for gated models)
login(token="hf_yourtokenhere")  # Replace with your token

# Load the model (use bfloat16 for faster inference + less VRAM)
pipe = FluxPipeline.from_pretrained(
    "black-forest-labs/FLUX.1-schnell",
    torch_dtype=torch.bfloat16
)

# Enable CPU offloading if you have limited GPU memory
pipe.enable_model_cpu_offload()

# Generate an image
prompt = "A cat holding a sign that says hello world"
image = pipe(
    prompt,
    guidance_scale=0.0,
    num_inference_steps=4,
    max_sequence_length=256,
    generator=torch.Generator("cpu").manual_seed(0)
).images[0]

# Save the output
image.save("flux-schnell-output.png")
print("Image saved successfully!")