Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -51,11 +51,17 @@ def run_model(input_image):
|
|
51 |
return tmp_file.name
|
52 |
|
53 |
def create_batch(input_image: Image) -> dict[str, Any]:
|
54 |
-
img_cond = (
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
57 |
mask_cond = img_cond[:, :, -1:]
|
58 |
-
rgb_cond = torch.lerp(
|
|
|
|
|
59 |
|
60 |
batch_elem = {
|
61 |
"rgb_cond": rgb_cond,
|
@@ -73,7 +79,11 @@ def checkerboard(squares: int, size: int, min_value: float = 0.5):
|
|
73 |
base[1::2, ::2] = 1
|
74 |
base[::2, 1::2] = 1
|
75 |
repeat_mult = size // squares
|
76 |
-
return (
|
|
|
|
|
|
|
|
|
77 |
|
78 |
def remove_background(input_image: Image) -> Image:
|
79 |
return rembg.remove(input_image, session=rembg_session)
|
@@ -87,12 +97,20 @@ def resize_foreground(image: Image, ratio: float) -> Image:
|
|
87 |
size = max(fg.shape[0], fg.shape[1])
|
88 |
ph0, pw0 = (size - fg.shape[0]) // 2, (size - fg.shape[1]) // 2
|
89 |
ph1, pw1 = size - fg.shape[0] - ph0, size - fg.shape[1] - pw0
|
90 |
-
new_image = np.pad(
|
|
|
|
|
|
|
|
|
91 |
|
92 |
new_size = int(new_image.shape[0] / ratio)
|
93 |
ph0, pw0 = (new_size - size) // 2, (new_size - size) // 2
|
94 |
ph1, pw1 = new_size - size - ph0, new_size - size - pw0
|
95 |
-
new_image = np.pad(
|
|
|
|
|
|
|
|
|
96 |
new_image = Image.fromarray(new_image, mode="RGBA").resize((COND_WIDTH, COND_HEIGHT))
|
97 |
return new_image
|
98 |
|
@@ -193,12 +211,24 @@ class CustomTheme(gr.themes.Base):
|
|
193 |
)
|
194 |
|
195 |
css = """
|
196 |
-
|
|
|
|
|
|
|
|
|
197 |
background-color: #191a1e !important;
|
198 |
margin: 0 !important;
|
199 |
padding: 0 !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
height: 100%;
|
201 |
width: 100%;
|
|
|
202 |
}
|
203 |
|
204 |
.gr-block, .gr-row, .gr-column, .gr-box, .gr-examples, .gr-examples .gr-box, .gr-examples .gr-card {
|
|
|
51 |
return tmp_file.name
|
52 |
|
53 |
def create_batch(input_image: Image) -> dict[str, Any]:
|
54 |
+
img_cond = (
|
55 |
+
torch.from_numpy(
|
56 |
+
np.asarray(input_image.resize((COND_WIDTH, COND_HEIGHT))).astype(np.float32) / 255.0
|
57 |
+
)
|
58 |
+
.float()
|
59 |
+
.clip(0, 1)
|
60 |
+
)
|
61 |
mask_cond = img_cond[:, :, -1:]
|
62 |
+
rgb_cond = torch.lerp(
|
63 |
+
torch.tensor(BACKGROUND_COLOR)[None, None, :], img_cond[:, :, :3], mask_cond
|
64 |
+
)
|
65 |
|
66 |
batch_elem = {
|
67 |
"rgb_cond": rgb_cond,
|
|
|
79 |
base[1::2, ::2] = 1
|
80 |
base[::2, 1::2] = 1
|
81 |
repeat_mult = size // squares
|
82 |
+
return (
|
83 |
+
base.repeat(repeat_mult, axis=0)
|
84 |
+
.repeat(repeat_mult, axis=1)[:, :, None]
|
85 |
+
.repeat(3, axis=-1)
|
86 |
+
)
|
87 |
|
88 |
def remove_background(input_image: Image) -> Image:
|
89 |
return rembg.remove(input_image, session=rembg_session)
|
|
|
97 |
size = max(fg.shape[0], fg.shape[1])
|
98 |
ph0, pw0 = (size - fg.shape[0]) // 2, (size - fg.shape[1]) // 2
|
99 |
ph1, pw1 = size - fg.shape[0] - ph0, size - fg.shape[1] - pw0
|
100 |
+
new_image = np.pad(
|
101 |
+
fg, ((ph0, ph1), (pw0, pw1), (0, 0)),
|
102 |
+
mode="constant",
|
103 |
+
constant_values=0,
|
104 |
+
)
|
105 |
|
106 |
new_size = int(new_image.shape[0] / ratio)
|
107 |
ph0, pw0 = (new_size - size) // 2, (new_size - size) // 2
|
108 |
ph1, pw1 = new_size - size - ph0, new_size - size - pw0
|
109 |
+
new_image = np.pad(
|
110 |
+
new_image, ((ph0, ph1), (pw0, pw1), (0, 0)),
|
111 |
+
mode="constant",
|
112 |
+
constant_values=0,
|
113 |
+
)
|
114 |
new_image = Image.fromarray(new_image, mode="RGBA").resize((COND_WIDTH, COND_HEIGHT))
|
115 |
return new_image
|
116 |
|
|
|
211 |
)
|
212 |
|
213 |
css = """
|
214 |
+
*, *::before, *::after {
|
215 |
+
box-sizing: border-box;
|
216 |
+
}
|
217 |
+
|
218 |
+
html, body {
|
219 |
background-color: #191a1e !important;
|
220 |
margin: 0 !important;
|
221 |
padding: 0 !important;
|
222 |
+
height: 100vh;
|
223 |
+
width: 100vw;
|
224 |
+
overflow: hidden;
|
225 |
+
}
|
226 |
+
|
227 |
+
#root, #__next, .gradio-container, .gr-app {
|
228 |
+
background-color: #191a1e !important;
|
229 |
height: 100%;
|
230 |
width: 100%;
|
231 |
+
overflow: hidden;
|
232 |
}
|
233 |
|
234 |
.gr-block, .gr-row, .gr-column, .gr-box, .gr-examples, .gr-examples .gr-box, .gr-examples .gr-card {
|