File size: 2,540 Bytes
2d8d909
5ac1f2b
 
 
 
 
 
 
 
2d8d909
5ac1f2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
---

language:
- en
license: creativeml-openrail-m
tags:
- stable-diffusion
- stable-diffusion-diffusers
- text-to-image
- diffusers
---


diffuser port of https://huggingface.co/osunlp/InstructPix2Pix-MagicBrush.
diffuser version of `MagicBrush-epoch-52-step-4999.ckpt` **with EMA**.

```python

from PIL import Image, ImageOps

import requests

import torch

from diffusers import StableDiffusionInstructPix2PixPipeline, EulerAncestralDiscreteScheduler

from PIL import Image



url = "https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/mountain.png"



def download_image(url):

    image = Image.open(requests.get(url, stream=True).raw)

    image = ImageOps.exif_transpose(image)

    image = image.convert("RGB")

    return image



image = download_image(url)

prompt = "make the mountains snowy"



class MagicBrush():

    def __init__(self, weight="vinesmsuic/magicbrush-ema"):

        self.pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(

                        weight, 

                        torch_dtype=torch.float16

                    ).to("cuda")

        self.pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(self.pipe.scheduler.config)

        

    def infer_one_image(self, src_image, instruct_prompt, seed):

        generator = torch.manual_seed(seed)

        image = self.pipe(instruct_prompt, image=src_image, num_inference_steps=20, image_guidance_scale=1.5, guidance_scale=7, generator=generator).images[0]

        return image



model = MagicBrush()

image_output = model.infer_one_image(image, prompt, 42)

image_output

```

![](https://i.imgur.com/rL3zEkh.png)

## License

This model is open access and available to all, with a CreativeML OpenRAIL-M license further specifying rights and usage.
The CreativeML OpenRAIL License specifies: 

1. You can't use the model to deliberately produce nor share illegal or harmful outputs or content 
2. The authors claims no rights on the outputs you generate, you are free to use them and are accountable for their use which must not go against the provisions set in the license
3. You may re-distribute the weights and use the model commercially and/or as a service. If you do, please be aware you have to include the same use restrictions as the ones in the license and share a copy of the CreativeML OpenRAIL-M to all your users (please read the license entirely and carefully)
[Please read the full license here](https://huggingface.co/spaces/CompVis/stable-diffusion-license)