黑森林实验室:https://blackforestlabs.ai。我们的 API 文档可以在这里找到:docs.bfl.ml。

该存储库包含最少的推理代码,可使用我们的 Flux 潜在整流流转换器运行文本到图像和图像到图像。
我们很高兴与 Replicate、FAL、Mystic 和 Together 合作。您可以使用他们的服务对我们的模型进行采样。下面我们列出了相关链接。
复制:
错误:
神秘:
一起:
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] "我们提供三种型号:
FLUX1.1 [pro]仅可通过 API 获取FLUX.1 [pro]仅可通过 API 获取FLUX.1 [dev]指导蒸馏变体FLUX.1 [schnell]指导和分步蒸馏变体| 姓名 | HuggingFace 仓库 | 执照 | md5和 |
|---|---|---|---|
FLUX.1 [schnell] | https://huggingface.co/black-forest-labs/FLUX.1-schnell | 阿帕奇-2.0 | a9e1e277b9b16add186f38e3f5a34044 |
FLUX.1 [dev] | https://huggingface.co/black-forest-labs/FLUX.1-dev | FLUX.1-dev 非商业许可证 | a6bd8c16dfc23db6aee2f63a2eba78c0 |
FLUX.1 [pro] | 仅在我们的 API 中可用。 | ||
FLUX1.1 [pro] | 仅在我们的 API 中可用。 |
自动编码器的权重也在 apache-2.0 下发布,可以在上面的两个 HuggingFace 存储库中找到。两种型号的它们是相同的。
一旦您启动其中一个演示,权重就会自动从 HuggingFace 下载。要下载FLUX.1 [dev] ,您需要登录,请参阅此处。如果您手动下载了模型权重,则可以通过环境变量指定下载路径:
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 >用于交互式采样运行
python -m flux --name < name > --loop或者生成单个样本运行
python -m flux --name < name >
--height < height > --width < width >
--prompt " <prompt> "我们还提供了一个 Streamlit 演示,可以执行文本到图像和图像到图像的操作。该演示可以通过以下方式运行
streamlit run demo_st.py我们还提供基于 Gradio 的演示,以实现交互式体验。要运行 Gradio 演示:
python demo_gr.py --name flux-schnell --device cuda选项:
--name :选择要使用的模型(选项:“flux-schnell”、“flux-dev”)--device :指定要使用的设备(默认值:“cuda”(如果可用),否则“cpu”)--offload : 不使用时将模型卸载到 CPU--share :创建指向您的演示的公共链接要使用开发模型运行演示并创建公共链接:
python demo_gr.py --name flux-dev --shareFLUX.1 [schnell]和FLUX.1 [dev]与 ? 集成扩散器库。要将其与扩散器一起使用,请安装它:
pip install git+https://github.com/huggingface/diffusers.git然后就可以使用FluxPipeline来运行模型了
import torch
from diffusers import FluxPipeline
model_id = "black-forest-labs/FLUX.1-schnell" #you can also use `black-forest-labs/FLUX.1-dev`
pipe = FluxPipeline . from_pretrained ( "black-forest-labs/FLUX.1-schnell" , torch_dtype = torch . bfloat16 )
pipe . enable_model_cpu_offload () #save some VRAM by offloading the model to CPU. Remove this if you have enough GPU power
prompt = "A cat holding a sign that says hello world"
seed = 42
image = pipe (
prompt ,
output_type = "pil" ,
num_inference_steps = 4 , #use a larger number if you are using [dev]
generator = torch . Generator ( "cpu" ). manual_seed ( seed )
). images [ 0 ]
image . save ( "flux-schnell.png" )要了解更多信息,请查看扩散器文档
我们的 API 提供对我们模型的访问。它记录在此处:docs.bfl.ml。
在此存储库中,我们还提供了一个简单的 python 界面。要使用此功能,您首先需要在 api.bfl.ml 上注册 API,并创建一个新的 API 密钥。
要使用 API 密钥,请运行export BFL_API_KEY=<your_key_here>或通过api_key=<your_key_here>参数提供。还期望您已按上述方式安装了该软件包。
来自 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" , name = "flux.1.1-pro" )
# or: request = ImageRequest("A beautiful beach", name="flux.1.1-pro", 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从命令行使用:
$ 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