Views
No views yet






1from diffusers import FluxKontextPipeline
2from diffusers.utils import load_image
3import torch
4
5# Load the base pipeline
6pipeline = FluxKontextPipeline.from_pretrained(
7 "black-forest-labs/FLUX.1-Kontext-dev",
8 torch_dtype=torch.bfloat16
9).to('cuda')
10
11# Load the LoRA adapter for the Pixel style directly from the Hub
12pipeline.load_lora_weights("Kontext-Style/Pixel_lora", weight_name="Pixel_lora_weights.safetensors", adapter_name="lora")
13pipeline.set_adapters(["lora"], adapter_weights=[1])
14
15# Load a source image (you can use any image)
16image = load_image("https://huggingface.co/datasets/black-forest-labs/kontext-bench/resolve/main/test/images/0003.jpg").resize((1024, 1024))
17
18# Prepare the prompt
19# The style_name is used in the prompt and for the output filename.
20style_name = "Pixel"
21prompt = f"Turn this image into the Pixel style."
22
23# Run inference
24result_image = pipeline(
25 image=image,
26 prompt=prompt,
27 height=1024,
28 width=1024,
29 num_inference_steps=24
30).images[0]
31
32# Save the result
33output_filename = f"{style_name.replace(' ', '_')}.png"
34result_image.save(output_filename)
35
36print(f"Image saved as {output_filename}")