Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
@@ -33,36 +33,42 @@ Here are some examples of images generated using this style LoRA:
|
|
33 |
|
34 |
## Inference Example
|
35 |
```python
|
36 |
-
from huggingface_hub import hf_hub_download
|
37 |
from diffusers import FluxKontextPipeline
|
38 |
from diffusers.utils import load_image
|
39 |
import torch
|
40 |
|
41 |
-
#
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
45 |
|
46 |
-
#
|
47 |
-
|
48 |
-
|
49 |
|
50 |
-
# Load
|
51 |
image = load_image("https://huggingface.co/datasets/black-forest-labs/kontext-bench/resolve/main/test/images/0003.jpg").resize((1024, 1024))
|
52 |
|
53 |
-
#
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
pipeline.load_lora_weights(f"./LoRAs/{LORA_FILENAME}", adapter_name="lora")
|
58 |
-
pipeline.set_adapters(["lora"], adapter_weights=[1])
|
59 |
|
60 |
# Run inference
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
-
print(f"Image saved as {
|
66 |
```
|
67 |
|
68 |
Feel free to open an issue or contact us for feedback or collaboration!
|
|
|
33 |
|
34 |
## Inference Example
|
35 |
```python
|
|
|
36 |
from diffusers import FluxKontextPipeline
|
37 |
from diffusers.utils import load_image
|
38 |
import torch
|
39 |
|
40 |
+
# Load the base pipeline
|
41 |
+
pipeline = FluxKontextPipeline.from_pretrained(
|
42 |
+
"black-forest-labs/FLUX.1-Kontext-dev",
|
43 |
+
torch_dtype=torch.bfloat16
|
44 |
+
).to('cuda')
|
45 |
|
46 |
+
# Load the LoRA adapter for the Macaron style directly from the Hub
|
47 |
+
pipeline.load_lora_weights("Kontext-Style/Macaron_lora", weight_name="Macaron_lora_weights.safetensors", adapter_name="lora")
|
48 |
+
pipeline.set_adapters(["lora"], adapter_weights=[1])
|
49 |
|
50 |
+
# Load a source image (you can use any image)
|
51 |
image = load_image("https://huggingface.co/datasets/black-forest-labs/kontext-bench/resolve/main/test/images/0003.jpg").resize((1024, 1024))
|
52 |
|
53 |
+
# Prepare the prompt
|
54 |
+
# The style_name is used in the prompt and for the output filename.
|
55 |
+
style_name = "Macaron"
|
56 |
+
prompt = f"Turn this image into the Macaron style."
|
|
|
|
|
57 |
|
58 |
# Run inference
|
59 |
+
result_image = pipeline(
|
60 |
+
image=image,
|
61 |
+
prompt=prompt,
|
62 |
+
height=1024,
|
63 |
+
width=1024,
|
64 |
+
num_inference_steps=24
|
65 |
+
).images[0]
|
66 |
+
|
67 |
+
# Save the result
|
68 |
+
output_filename = f"{style_name.replace(' ', '_')}.png"
|
69 |
+
result_image.save(output_filename)
|
70 |
|
71 |
+
print(f"Image saved as {output_filename}")
|
72 |
```
|
73 |
|
74 |
Feel free to open an issue or contact us for feedback or collaboration!
|