Inference Options
Inference Partners
Local Installation
- Clone the repository:
cd $HOME && git clone https://github.com/black-forest-labs/flux
- Create a virtual environment:
cd $HOME/flux && python3.10 -m venv .venv
- Activate the environment:
source .venv/bin/activate
- Install dependencies:
pip install -e '.[all]'
Models
- FLUX.1 [pro]: Available through the Black Forest Labs API.
- FLUX.1 [dev]: Guidance-distilled variant, downloadable from HuggingFace.
- FLUX.1 [schnell]: Guidance and step-distilled variant, downloadable from HuggingFace.
Usage
Interactive Sampling
python -m flux --name <name> --loop
Single Sample Generation
python -m flux --name <name> \
--height <height> --width <width> \
--prompt "<prompt>"
Streamlit Demo
streamlit run demo_st.py
Gradio Demo
python demo_gr.py --name flux-schnell --device cuda
Diffusers Integration
import torch
from diffusers import FluxPipeline
model_id = "black-forest-labs/FLUX.1-schnell"
pipe = FluxPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16)
pipe.enable_model_cpu_offload()
prompt = "A cat holding a sign that says hello world"
seed = 42
image = pipe(
prompt,
output_type="pil",
num_inference_steps=4,
generator=torch.Generator("cpu").manual_seed(seed)
).images[0]
image.save("flux-schnell.png")
API Usage
- Register for an API key at https://api.bfl.ml.
- Set the API key:
export BFL_API_KEY=<your_key_here>
Python
from flux.api import ImageRequest
request = ImageRequest("A beautiful beach")
# Access the generated image
request.url
request.bytes
request.save("outputs/api.jpg")
request.image
Command Line
# Get image URL
python -m flux.api --prompt="A beautiful beach" url
# Save the image
python -m flux.api --prompt="A beautiful beach" save outputs/api
# Open the image directly
python -m flux.api --prompt="A beautiful beach" image show