exx8 commited on
Commit
b1ae048
1 Parent(s): c4f7e78

Allow large pictures

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -9,7 +9,7 @@ device = "cuda"
9
 
10
  base = StableDiffusionXLDiffImg2ImgPipeline.from_pretrained(
11
  "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
12
- ).to(device)
13
 
14
  refiner = StableDiffusionXLDiffImg2ImgPipeline.from_pretrained(
15
  "stabilityai/stable-diffusion-xl-refiner-1.0",
@@ -18,7 +18,7 @@ refiner = StableDiffusionXLDiffImg2ImgPipeline.from_pretrained(
18
  torch_dtype=torch.float16,
19
  use_safetensors=True,
20
  variant="fp16",
21
- ).to(device)
22
 
23
  base.scheduler = DPMSolverMultistepScheduler.from_config(base.scheduler.config)
24
  refiner.scheduler = DPMSolverMultistepScheduler.from_config(base.scheduler.config)
@@ -46,17 +46,20 @@ def inference(image, map, gs, prompt, negative_prompt):
46
  validate_inputs(image, map)
47
  image = preprocess_image(image)
48
  map = preprocess_map(map)
49
- edited_images = base(prompt=prompt, original_image=image, image=image, strength=1, guidance_scale=gs,
 
50
  num_images_per_prompt=1,
51
  negative_prompt=negative_prompt,
52
  map=map,
53
  num_inference_steps=NUM_INFERENCE_STEPS, denoising_end=0.8, output_type="latent").images
54
-
55
- edited_images = refiner(prompt=prompt, original_image=image, image=edited_images, strength=1, guidance_scale=7.5,
 
56
  num_images_per_prompt=1,
57
  negative_prompt=negative_prompt,
58
  map=map,
59
  num_inference_steps=NUM_INFERENCE_STEPS, denoising_start=0.8).images[0]
 
60
  return edited_images
61
 
62
 
 
9
 
10
  base = StableDiffusionXLDiffImg2ImgPipeline.from_pretrained(
11
  "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
12
+ )
13
 
14
  refiner = StableDiffusionXLDiffImg2ImgPipeline.from_pretrained(
15
  "stabilityai/stable-diffusion-xl-refiner-1.0",
 
18
  torch_dtype=torch.float16,
19
  use_safetensors=True,
20
  variant="fp16",
21
+ )
22
 
23
  base.scheduler = DPMSolverMultistepScheduler.from_config(base.scheduler.config)
24
  refiner.scheduler = DPMSolverMultistepScheduler.from_config(base.scheduler.config)
 
46
  validate_inputs(image, map)
47
  image = preprocess_image(image)
48
  map = preprocess_map(map)
49
+ base_cuda = base.to(device)
50
+ edited_images = base_cuda(prompt=prompt, original_image=image, image=image, strength=1, guidance_scale=gs,
51
  num_images_per_prompt=1,
52
  negative_prompt=negative_prompt,
53
  map=map,
54
  num_inference_steps=NUM_INFERENCE_STEPS, denoising_end=0.8, output_type="latent").images
55
+ base_cuda=None
56
+ refiner_cuda = refiner.to(device)
57
+ edited_images = refiner_cuda(prompt=prompt, original_image=image, image=edited_images, strength=1, guidance_scale=7.5,
58
  num_images_per_prompt=1,
59
  negative_prompt=negative_prompt,
60
  map=map,
61
  num_inference_steps=NUM_INFERENCE_STEPS, denoising_start=0.8).images[0]
62
+ refiner_cuda=None
63
  return edited_images
64
 
65