Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,26 +38,19 @@ model_configs = {
|
|
| 38 |
'vitg': {'encoder': 'vitg', 'features': 384, 'out_channels': [1536, 1536, 1536, 1536]}
|
| 39 |
}
|
| 40 |
|
| 41 |
-
|
| 42 |
-
0.
|
| 43 |
-
0.
|
| 44 |
-
0.
|
| 45 |
-
0
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
1.
|
| 51 |
-
1.
|
| 52 |
-
1.
|
| 53 |
-
1.29:{"width":1152,"height":896},
|
| 54 |
-
1.38:{"width":1152,"height":832},
|
| 55 |
-
1.46:{"width":1216,"height":832},
|
| 56 |
-
1.67:{"width":1280,"height":768},
|
| 57 |
-
1.75:{"width":1344,"height":768},
|
| 58 |
-
2.00:{"width":1408,"height":704}
|
| 59 |
}
|
| 60 |
-
ratios = np.array(list(ratios_map.keys()))
|
| 61 |
|
| 62 |
encoder = 'vitl'
|
| 63 |
model = DepthAnythingV2(**model_configs[encoder])
|
|
@@ -154,19 +147,12 @@ def tile(downscale_factor, input_image):
|
|
| 154 |
control_image = input_image.resize((input_image.size[0] // downscale_factor, input_image.size[1] // downscale_factor)).resize(input_image.size, Image.NEAREST)
|
| 155 |
return control_image
|
| 156 |
|
| 157 |
-
def
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
w,h = chosen_ratio['width'], chosen_ratio['height']
|
| 164 |
-
return w,h
|
| 165 |
-
|
| 166 |
-
def resize_img(image):
|
| 167 |
-
image = image.convert('RGB')
|
| 168 |
-
w,h = get_size(image)
|
| 169 |
-
resized_image = image.resize((w, h))
|
| 170 |
return resized_image
|
| 171 |
|
| 172 |
@spaces.GPU(duration=180)
|
|
|
|
| 38 |
'vitg': {'encoder': 'vitg', 'features': 384, 'out_channels': [1536, 1536, 1536, 1536]}
|
| 39 |
}
|
| 40 |
|
| 41 |
+
RATIO_CONFIGS_1024 = {
|
| 42 |
+
0.6666666666666666: {"width": 832, "height": 1248},
|
| 43 |
+
0.7432432432432432: {"width": 880, "height": 1184},
|
| 44 |
+
0.8028169014084507: {"width": 912, "height": 1136},
|
| 45 |
+
1.0: {"width": 1024, "height": 1024},
|
| 46 |
+
1.2456140350877194: {"width": 1136, "height": 912},
|
| 47 |
+
1.3454545454545455: {"width": 1184, "height": 880},
|
| 48 |
+
1.4339622641509433: {"width": 1216, "height": 848},
|
| 49 |
+
1.5: {"width": 1248, "height": 832},
|
| 50 |
+
1.5490196078431373: {"width": 1264, "height": 816},
|
| 51 |
+
1.62: {"width": 1296, "height": 800},
|
| 52 |
+
1.7708333333333333: {"width": 1360, "height": 768},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
}
|
|
|
|
| 54 |
|
| 55 |
encoder = 'vitl'
|
| 56 |
model = DepthAnythingV2(**model_configs[encoder])
|
|
|
|
| 147 |
control_image = input_image.resize((input_image.size[0] // downscale_factor, input_image.size[1] // downscale_factor)).resize(input_image.size, Image.NEAREST)
|
| 148 |
return control_image
|
| 149 |
|
| 150 |
+
def resize_img(control_image):
|
| 151 |
+
image_ratio = control_image.width / control_image.height
|
| 152 |
+
ratio = min(RATIO_CONFIGS_1024.keys(), key=lambda k: abs(k - image_ratio))
|
| 153 |
+
to_height = RATIO_CONFIGS_1024[ratio]["height"]
|
| 154 |
+
to_width = RATIO_CONFIGS_1024[ratio]["width"]
|
| 155 |
+
resized_image = control_image.resize((to_width, to_height), resample=Image.Resampling.LANCZOS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
return resized_image
|
| 157 |
|
| 158 |
@spaces.GPU(duration=180)
|