黑森林實驗室: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 --share
FLUX.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