Update README.md to include the `diffusers` usage (#2)
Browse files- Update README.md (b0c8ee0c4f28dfadf654e1c84e20313e668a72c5)
Co-authored-by: Sayak Paul <[email protected]>
README.md
CHANGED
@@ -32,6 +32,47 @@ Developers and creatives looking to build on top of `FLUX.1 Depth [dev]` are enc
|
|
32 |
## API Endpoints
|
33 |
`FLUX.1 Depth [pro]` is available in our API [bfl.ml](https://docs.bfl.ml/)
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
---
|
37 |
|
|
|
32 |
## API Endpoints
|
33 |
`FLUX.1 Depth [pro]` is available in our API [bfl.ml](https://docs.bfl.ml/)
|
34 |
|
35 |
+
## Diffusers
|
36 |
+
|
37 |
+
To use FLUX.1-Depth-dev-lora with the 🧨 diffusers python library, first install or upgrade `diffusers`, `peft`, and `image_gen_aux`.
|
38 |
+
|
39 |
+
```bash
|
40 |
+
pip install -U git+https://github.com/huggingface/diffusers
|
41 |
+
pip install git+https://github.com/asomoza/image_gen_aux.git
|
42 |
+
pip install -U peft
|
43 |
+
```
|
44 |
+
|
45 |
+
Then you can use the `FluxControlPipeline` to run it:
|
46 |
+
|
47 |
+
```py
|
48 |
+
import torch
|
49 |
+
from diffusers import FluxControlPipeline, FluxTransformer2DModel
|
50 |
+
from diffusers.utils import load_image
|
51 |
+
from image_gen_aux import DepthPreprocessor
|
52 |
+
|
53 |
+
pipe = FluxControlPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16).to("cuda")
|
54 |
+
pipe.load_lora_weights("black-forest-labs/FLUX.1-Depth-dev-lora", adapter_name="depth")
|
55 |
+
pipe.set_adapters("depth", 0.85)
|
56 |
+
|
57 |
+
prompt = "A robot made of exotic candies and chocolates of different kinds. The background is filled with confetti and celebratory gifts."
|
58 |
+
control_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/robot.png")
|
59 |
+
|
60 |
+
processor = DepthPreprocessor.from_pretrained("LiheYoung/depth-anything-large-hf")
|
61 |
+
control_image = processor(control_image)[0].convert("RGB")
|
62 |
+
|
63 |
+
image = pipe(
|
64 |
+
prompt=prompt,
|
65 |
+
control_image=control_image,
|
66 |
+
height=1024,
|
67 |
+
width=1024,
|
68 |
+
num_inference_steps=30,
|
69 |
+
guidance_scale=10.0,
|
70 |
+
generator=torch.Generator().manual_seed(42),
|
71 |
+
).images[0]
|
72 |
+
image.save("output.png")
|
73 |
+
```
|
74 |
+
|
75 |
+
To learn more, check out the [diffusers documentation](https://huggingface.co/docs/diffusers/main/en/api/pipelines/flux).
|
76 |
|
77 |
---
|
78 |
|