readme: #!/usr/bin/env python3
  from diffusers import DiffusionPipeline
  import PIL
  import requests
  from io import BytesIO
  import torch
  
  
  def download_image(url):
      response = requests.get(url)
      return PIL.Image.open(BytesIO(response.content)).convert("RGB")
  
  pipe = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", custom_pipeline="stable_diffusion_mega", torch_dtype=torch.float16, revision="fp16")
  pipe.to("cuda")
  pipe.enable_attention_slicing()
  
  
  ### Text-to-Image
  
  images = pipe.text2img("An astronaut riding a horse").images
  
  ### Image-to-Image
  
  init_image = download_image("https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg")
  
  prompt = "A fantasy landscape, trending on artstation"
  
  images = pipe.img2img(prompt=prompt, init_image=init_image, strength=0.75, guidance_scale=7.5).images
  
  ### Inpainting
  
  img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
  mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
  init_image = download_image(img_url).resize((512, 512))
  mask_image = download_image(mask_url).resize((512, 512))
  
  prompt = "a cat sitting on a bench"
  images = pipe.inpaint(prompt=prompt, init_image=init_image, mask_image=mask_image, strength=0.75).images