Spaces:
Running
on
Zero
Running
on
Zero
fix resize
Browse files
app.py
CHANGED
@@ -21,6 +21,24 @@ def sanitize_prompt(prompt):
|
|
21 |
sanitized_prompt = allowed_chars.sub("", prompt)
|
22 |
return sanitized_prompt
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
|
26 |
|
@@ -40,8 +58,15 @@ def process_images(image,prompt="a girl",strength=0.75,seed=0,inference_step=4,p
|
|
40 |
generators = []
|
41 |
generator = torch.Generator(device).manual_seed(seed)
|
42 |
generators.append(generator)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
# more parameter see https://huggingface.co/docs/diffusers/api/pipelines/flux#diffusers.FluxInpaintPipeline
|
44 |
-
print(prompt)
|
45 |
output = pipe(prompt=prompt, image=image,generator=generator,strength=strength
|
46 |
,guidance_scale=0,num_inference_steps=num_inference_steps,max_sequence_length=256)
|
47 |
|
|
|
21 |
sanitized_prompt = allowed_chars.sub("", prompt)
|
22 |
return sanitized_prompt
|
23 |
|
24 |
+
def convert_to_fit_size(original_width_and_height, maximum_size = 2048):
|
25 |
+
width, height =original_width_and_height
|
26 |
+
if width <= maximum_size and height <= maximum_size:
|
27 |
+
return width,height
|
28 |
+
|
29 |
+
if width > height:
|
30 |
+
scaling_factor = maximum_size / width
|
31 |
+
else:
|
32 |
+
scaling_factor = maximum_size / height
|
33 |
+
|
34 |
+
new_width = int(width * scaling_factor)
|
35 |
+
new_height = int(height * scaling_factor)
|
36 |
+
return new_width, new_height
|
37 |
+
|
38 |
+
def adjust_to_multiple_of_32(width: int, height: int):
|
39 |
+
width = width - (width % 32)
|
40 |
+
height = height - (height % 32)
|
41 |
+
return width, height
|
42 |
|
43 |
|
44 |
|
|
|
58 |
generators = []
|
59 |
generator = torch.Generator(device).manual_seed(seed)
|
60 |
generators.append(generator)
|
61 |
+
width,height = convert_to_fit_size(image.size)
|
62 |
+
#print(f"fit {width}x{height}")
|
63 |
+
width,height = adjust_to_multiple_of_32(width,height)
|
64 |
+
#print(f"multiple {width}x{height}")
|
65 |
+
image = image.resize((width, height), Image.LANCZOS)
|
66 |
+
#mask_image = mask_image.resize((width, height), Image.NEAREST)
|
67 |
+
|
68 |
# more parameter see https://huggingface.co/docs/diffusers/api/pipelines/flux#diffusers.FluxInpaintPipeline
|
69 |
+
#print(prompt)
|
70 |
output = pipe(prompt=prompt, image=image,generator=generator,strength=strength
|
71 |
,guidance_scale=0,num_inference_steps=num_inference_steps,max_sequence_length=256)
|
72 |
|