Git Product home page Git Product logo

flux's Introduction

FLUX

by Black Forest Labs: https://blackforestlabs.ai

grid

This repo contains minimal inference code to run text-to-image and image-to-image with our Flux latent rectified flow transformers.

Inference partners

We are happy to partner with Replicate and FAL. You can sample our models using their services. Below we list relevant links.

Replicate:

FAL:

Local installation

cd $HOME && git clone https://github.com/black-forest-labs/flux
cd $HOME/flux
python3.10 -m venv .venv
source .venv/bin/activate
pip install -e '.[all]'

Models

We are offering three models:

  • FLUX.1 [pro] the base model, available via API
  • FLUX.1 [dev] guidance-distilled variant
  • FLUX.1 [schnell] guidance and step-distilled variant
Name HuggingFace repo License md5sum
FLUX.1 [schnell] https://huggingface.co/black-forest-labs/FLUX.1-schnell apache-2.0 a9e1e277b9b16add186f38e3f5a34044
FLUX.1 [dev] https://huggingface.co/black-forest-labs/FLUX.1-dev FLUX.1-dev Non-Commercial License a6bd8c16dfc23db6aee2f63a2eba78c0
FLUX.1 [pro] Only available in our API.

The weights of the autoencoder are also released under apache-2.0 and can be found in either of the two HuggingFace repos above. They are the same for both models.

Usage

The weights will be downloaded automatically from HuggingFace once you start one of the demos. To download FLUX.1 [dev], you will need to be logged in, see here. If you have downloaded the model weights manually, you can specify the downloaded paths via environment-variables:

export FLUX_SCHNELL=<path_to_flux_schnell_sft_file>
export FLUX_DEV=<path_to_flux_dev_sft_file>
export AE=<path_to_ae_sft_file>

For interactive sampling run

python -m flux --name <name> --loop

Or to generate a single sample run

python -m flux --name <name> \
  --height <height> --width <width> \
  --prompt "<prompt>"

We also provide a streamlit demo that does both text-to-image and image-to-image. The demo can be run via

streamlit run demo_st.py

API usage

Our API offers access to the pro model. It is documented here: docs.bfl.ml.

In this repository we also offer an easy python interface. To use this, you first need to register with the API on api.bfl.ml, and create a new API key.

To use the API key either run export BFL_API_KEY=<your_key_here> or provide it via the api_key=<your_key_here> parameter. Is is also expected that you have installed the package as above.

Usage from python:

from flux.api import ImageRequest

# this will create an api request directly but not block until the generation is finished
request = ImageRequest("A beautiful beach")
# or: request = ImageRequest("A beautiful beach", api_key="your_key_here")

# any of the following will block until the generation is finished
request.url
# -> https:<...>/sample.jpg
request.bytes
# -> b"..." bytes for the generated image
request.save("outputs/api.jpg")
# saves the sample to local storage
request.image
# -> a PIL image

Usage from the command line:

$ python -m flux.api --prompt="A beautiful beach" url
https:<...>/sample.jpg

# generate and save the result
$ 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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.