Xsong123 commited on
Commit
fc13d09
·
verified ·
1 Parent(s): d7c51da

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +25 -19
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
- # Define the style and model details
42
- STYLE_NAME = "Snoopy"
43
- LORA_FILENAME = "Snoopy_lora_weights.safetensors"
44
- REPO_ID = "Kontext-Style/Snoopy_lora"
 
45
 
46
- # Download the LoRA weights
47
- # Make sure you have created a folder named 'LoRAs' in your current directory
48
- hf_hub_download(repo_id=REPO_ID, filename=LORA_FILENAME, local_dir="./LoRAs")
49
 
50
- # Load an 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
- # Load the pipeline
54
- pipeline = FluxKontextPipeline.from_pretrained("black-forest-labs/FLUX.1-Kontext-dev", torch_dtype=torch.bfloat16).to('cuda')
55
-
56
- # Load and set the LoRA adapter
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
- prompt = f"Turn this image into the {STYLE_NAME.replace('_', ' ')} style."
62
- result_image = pipeline(image=image, prompt=prompt, height=1024, width=1024, num_inference_steps=24).images[0]
63
- result_image.save(f"{STYLE_NAME}.png")
 
 
 
 
 
 
 
 
64
 
65
- print(f"Image saved as {STYLE_NAME}.png")
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 Snoopy style directly from the Hub
47
+ pipeline.load_lora_weights("Kontext-Style/Snoopy_lora", weight_name="Snoopy_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 = "Snoopy"
56
+ prompt = f"Turn this image into the Snoopy 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!