vinesmsuic
commited on
Commit
•
2b1665d
1
Parent(s):
3938cda
Update README.md
Browse files
README.md
CHANGED
@@ -11,3 +11,39 @@ tags:
|
|
11 |
|
12 |
diffuser port of https://huggingface.co/osunlp/InstructPix2Pix-MagicBrush.
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
diffuser port of https://huggingface.co/osunlp/InstructPix2Pix-MagicBrush.
|
13 |
|
14 |
+
```python
|
15 |
+
from PIL import Image, ImageOps
|
16 |
+
import requests
|
17 |
+
import torch
|
18 |
+
from diffusers import StableDiffusionInstructPix2PixPipeline, EulerAncestralDiscreteScheduler
|
19 |
+
from PIL import Image
|
20 |
+
|
21 |
+
url = "https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/mountain.png"
|
22 |
+
|
23 |
+
def download_image(url):
|
24 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
25 |
+
image = ImageOps.exif_transpose(image)
|
26 |
+
image = image.convert("RGB")
|
27 |
+
return image
|
28 |
+
|
29 |
+
image = download_image(url)
|
30 |
+
prompt = "make the mountains snowy"
|
31 |
+
|
32 |
+
class MagicBrush():
|
33 |
+
def __init__(self, weight="vinesmsuic/magicbrush-paper"):
|
34 |
+
self.pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(
|
35 |
+
weight,
|
36 |
+
torch_dtype=torch.float16
|
37 |
+
).to("cuda")
|
38 |
+
self.pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(self.pipe.scheduler.config)
|
39 |
+
|
40 |
+
def infer_one_image(self, src_image, instruct_prompt, seed):
|
41 |
+
generator = torch.manual_seed(seed)
|
42 |
+
image = self.pipe(instruct_prompt, image=src_image, num_inference_steps=20, image_guidance_scale=1.5, guidance_scale=7, generator=generator).images[0]
|
43 |
+
return image
|
44 |
+
|
45 |
+
model = MagicBrush()
|
46 |
+
image_output = model.infer_one_image(image, prompt, 42)
|
47 |
+
image_output
|
48 |
+
```
|
49 |
+
|