Spaces:
Running
on
Zero
Running
on
Zero
support size
Browse files
app.py
CHANGED
|
@@ -9,6 +9,27 @@ import os
|
|
| 9 |
import numpy as np
|
| 10 |
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
dtype = torch.bfloat16
|
| 13 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 14 |
|
|
@@ -57,7 +78,14 @@ def process_images(image, image2=None,prompt="a girl",inpaint_model="black-fores
|
|
| 57 |
generator = torch.Generator("cuda").manual_seed(seed)
|
| 58 |
generators.append(generator)
|
| 59 |
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
guidance_scale=0,num_inference_steps=num_inference_steps,max_sequence_length=256)
|
| 62 |
|
| 63 |
return output.images[0]
|
|
|
|
| 9 |
import numpy as np
|
| 10 |
|
| 11 |
|
| 12 |
+
def convert_to_fit_size(original_width_and_height, maximum_size = 2048):
|
| 13 |
+
width, height =original_width_and_height
|
| 14 |
+
if width <= maximum_size and height <= maximum_size:
|
| 15 |
+
return width,height
|
| 16 |
+
|
| 17 |
+
if width > height:
|
| 18 |
+
scaling_factor = maximum_size / width
|
| 19 |
+
else:
|
| 20 |
+
scaling_factor = maximum_size / height
|
| 21 |
+
|
| 22 |
+
new_width = int(width * scaling_factor)
|
| 23 |
+
new_height = int(height * scaling_factor)
|
| 24 |
+
return new_width, new_height
|
| 25 |
+
|
| 26 |
+
def adjust_to_multiple_of_32(width: int, height: int):
|
| 27 |
+
width = width - (width % 32)
|
| 28 |
+
height = height - (height % 32)
|
| 29 |
+
return width, height
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
dtype = torch.bfloat16
|
| 34 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 35 |
|
|
|
|
| 78 |
generator = torch.Generator("cuda").manual_seed(seed)
|
| 79 |
generators.append(generator)
|
| 80 |
|
| 81 |
+
width,height = convert_to_fit_size(image.size)
|
| 82 |
+
print(f"fit {width}x{height}")
|
| 83 |
+
width,height = adjust_to_multiple_of_32(width,height)
|
| 84 |
+
print(f"multiple {width}x{height}")
|
| 85 |
+
image = image.resize((width, height), Image.LANCZOS)
|
| 86 |
+
mask = mask.resize((width, height), Image.NEAREST)
|
| 87 |
+
|
| 88 |
+
output = pipe(prompt=prompt, image=image, mask_image=mask_image,generator=generator,strength=strength,width=width,height=height,
|
| 89 |
guidance_scale=0,num_inference_steps=num_inference_steps,max_sequence_length=256)
|
| 90 |
|
| 91 |
return output.images[0]
|