Spaces:
Running
on
Zero
Running
on
Zero
cap image size, ensure result dimension is divisible by 8
Browse files
app.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
import torch
|
2 |
import spaces
|
3 |
import gradio as gr
|
@@ -17,6 +19,29 @@ pipe = FluxInpaintPipeline.from_pretrained(
|
|
17 |
"black-forest-labs/FLUX.1-schnell", torch_dtype=torch.bfloat16).to(DEVICE)
|
18 |
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
@spaces.GPU()
|
21 |
def process(input_image_editor, input_text, progress=gr.Progress(track_tqdm=True)):
|
22 |
if not input_text:
|
@@ -34,7 +59,7 @@ def process(input_image_editor, input_text, progress=gr.Progress(track_tqdm=True
|
|
34 |
gr.Info("Please draw a mask on the image.")
|
35 |
return None
|
36 |
|
37 |
-
width, height = image.size
|
38 |
|
39 |
return pipe(
|
40 |
prompt=input_text,
|
@@ -42,7 +67,8 @@ def process(input_image_editor, input_text, progress=gr.Progress(track_tqdm=True
|
|
42 |
mask_image=mask_image,
|
43 |
width=width,
|
44 |
height=height,
|
45 |
-
strength=0.7
|
|
|
46 |
).images[0]
|
47 |
|
48 |
|
|
|
1 |
+
from typing import Tuple
|
2 |
+
|
3 |
import torch
|
4 |
import spaces
|
5 |
import gradio as gr
|
|
|
19 |
"black-forest-labs/FLUX.1-schnell", torch_dtype=torch.bfloat16).to(DEVICE)
|
20 |
|
21 |
|
22 |
+
def resize_image_dimensions(
|
23 |
+
original_resolution_wh: Tuple[int, int],
|
24 |
+
maximum_dimension: int = 2048
|
25 |
+
) -> Tuple[int, int]:
|
26 |
+
width, height = original_resolution_wh
|
27 |
+
|
28 |
+
if width > height:
|
29 |
+
scaling_factor = maximum_dimension / width
|
30 |
+
else:
|
31 |
+
scaling_factor = maximum_dimension / height
|
32 |
+
|
33 |
+
new_width = int(width * scaling_factor)
|
34 |
+
new_height = int(height * scaling_factor)
|
35 |
+
|
36 |
+
new_width = new_width - (new_width % 8)
|
37 |
+
new_height = new_height - (new_height % 8)
|
38 |
+
|
39 |
+
new_width = min(maximum_dimension, new_width)
|
40 |
+
new_height = min(maximum_dimension, new_height)
|
41 |
+
|
42 |
+
return new_width, new_height
|
43 |
+
|
44 |
+
|
45 |
@spaces.GPU()
|
46 |
def process(input_image_editor, input_text, progress=gr.Progress(track_tqdm=True)):
|
47 |
if not input_text:
|
|
|
59 |
gr.Info("Please draw a mask on the image.")
|
60 |
return None
|
61 |
|
62 |
+
width, height = resize_image_dimensions(original_resolution_wh=image.size)
|
63 |
|
64 |
return pipe(
|
65 |
prompt=input_text,
|
|
|
67 |
mask_image=mask_image,
|
68 |
width=width,
|
69 |
height=height,
|
70 |
+
strength=0.7,
|
71 |
+
num_inference_steps=2
|
72 |
).images[0]
|
73 |
|
74 |
|