williamberman commited on
Commit
9dd235f
1 Parent(s): 91fa361

move models

Browse files
Files changed (1) hide show
  1. app.py +20 -5
app.py CHANGED
@@ -10,13 +10,14 @@ import torchvision.transforms.functional as TF
10
  from diffusion import make_sigmas
11
  from huggingface_hub import hf_hub_download
12
 
13
- device = "cuda" if torch.cuda.is_available() else "cpu"
14
- pipe = AutoPipelineForInpainting.from_pretrained("diffusers/stable-diffusion-xl-1.0-inpainting-0.1", torch_dtype=torch.float16, variant="fp16").to(device)
 
15
 
16
- comparing_unet = SDXLUNet.load(hf_hub_download("stabilityai/stable-diffusion-xl-base-1.0", "unet/diffusion_pytorch_model.fp16.safetensors"), device=device)
17
- comparing_vae = SDXLVae.load(hf_hub_download("madebyollin/sdxl-vae-fp16-fix", "diffusion_pytorch_model.safetensors"), device=device)
18
  comparing_vae.to(torch.float16)
19
- comparing_controlnet = SDXLControlNetPreEncodedControlnetCond.load(hf_hub_download("williamberman/sdxl_controlnet_inpainting", "sdxl_controlnet_inpaint_pre_encoded_controlnet_cond_checkpoint_200000.safetensors"), device=device)
20
  comparing_controlnet.to(torch.float16)
21
 
22
  def read_content(file_path: str) -> str:
@@ -44,7 +45,17 @@ def predict(dict, prompt="", negative_prompt="", guidance_scale=7.5, steps=20, s
44
  init_image = dict["image"].convert("RGB").resize((1024, 1024))
45
  mask = dict["mask"].convert("RGB").resize((1024, 1024))
46
 
 
 
 
47
  output = pipe(prompt = prompt, negative_prompt=negative_prompt, image=init_image, mask_image=mask, guidance_scale=guidance_scale, num_inference_steps=int(steps), strength=strength)
 
 
 
 
 
 
 
48
 
49
  image = TF.to_tensor(dict["image"].convert("RGB").resize((1024, 1024)))
50
  mask = TF.to_tensor(dict["mask"].convert("L").resize((1024, 1024)))
@@ -62,6 +73,10 @@ def predict(dict, prompt="", negative_prompt="", guidance_scale=7.5, steps=20, s
62
  text_encoder_one=pipe.text_encoder, text_encoder_two=pipe.text_encoder_2, unet=comparing_unet, controlnet=comparing_controlnet
63
  )
64
  out = comparing_vae.output_tensor_to_pil(comparing_vae.decode(out))
 
 
 
 
65
 
66
  return output.images[0], out[0], gr.update(visible=True)
67
 
 
10
  from diffusion import make_sigmas
11
  from huggingface_hub import hf_hub_download
12
 
13
+ pipe = AutoPipelineForInpainting.from_pretrained("diffusers/stable-diffusion-xl-1.0-inpainting-0.1", torch_dtype=torch.float16, variant="fp16")
14
+ pipe.text_encoder.to("cuda")
15
+ pipe.text_encoder_2.to("cuda")
16
 
17
+ comparing_unet = SDXLUNet.load(hf_hub_download("stabilityai/stable-diffusion-xl-base-1.0", "unet/diffusion_pytorch_model.fp16.safetensors"))
18
+ comparing_vae = SDXLVae.load(hf_hub_download("madebyollin/sdxl-vae-fp16-fix", "diffusion_pytorch_model.safetensors"))
19
  comparing_vae.to(torch.float16)
20
+ comparing_controlnet = SDXLControlNetPreEncodedControlnetCond.load(hf_hub_download("williamberman/sdxl_controlnet_inpainting", "sdxl_controlnet_inpaint_pre_encoded_controlnet_cond_checkpoint_200000.safetensors"))
21
  comparing_controlnet.to(torch.float16)
22
 
23
  def read_content(file_path: str) -> str:
 
45
  init_image = dict["image"].convert("RGB").resize((1024, 1024))
46
  mask = dict["mask"].convert("RGB").resize((1024, 1024))
47
 
48
+ pipe.vae.to('cuda')
49
+ pipe.unet.to('cuda')
50
+ pipe.controlnet.to('cuda')
51
  output = pipe(prompt = prompt, negative_prompt=negative_prompt, image=init_image, mask_image=mask, guidance_scale=guidance_scale, num_inference_steps=int(steps), strength=strength)
52
+ pipe.vae.to('cpu')
53
+ pipe.unet.to('cpu')
54
+ pipe.controlnet.to('cpu')
55
+
56
+ comparing_unet.to('cuda')
57
+ comparing_vae.to('cuda')
58
+ comparing_controlnet.to('cuda')
59
 
60
  image = TF.to_tensor(dict["image"].convert("RGB").resize((1024, 1024)))
61
  mask = TF.to_tensor(dict["mask"].convert("L").resize((1024, 1024)))
 
73
  text_encoder_one=pipe.text_encoder, text_encoder_two=pipe.text_encoder_2, unet=comparing_unet, controlnet=comparing_controlnet
74
  )
75
  out = comparing_vae.output_tensor_to_pil(comparing_vae.decode(out))
76
+
77
+ comparing_unet.to('cpu')
78
+ comparing_vae.to('cpu')
79
+ comparing_controlnet.to('cpu')
80
 
81
  return output.images[0], out[0], gr.update(visible=True)
82