Skip to content

FLUX - Official Inference Repo for FLUX.1 Models

Published: at 10:11 AM

Inference Options

Inference Partners

Local Installation

  1. Clone the repository: cd $HOME && git clone https://github.com/black-forest-labs/flux
  2. Create a virtual environment: cd $HOME/flux && python3.10 -m venv .venv
  3. Activate the environment: source .venv/bin/activate
  4. Install dependencies: pip install -e '.[all]'

Models

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

  1. Register for an API key at https://api.bfl.ml.
  2. 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

Further Information