Spaces:
Runtime error
Runtime error
Update gradio_demo.py
Browse files- gradio_demo.py +24 -5
gradio_demo.py
CHANGED
@@ -1217,6 +1217,12 @@ with block:
|
|
1217 |
# Create an instance of BackgroundManager
|
1218 |
bg_manager = BackgroundManager()
|
1219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1220 |
|
1221 |
x_slider.change(
|
1222 |
fn=lambda bg, x, y, scale: bg_manager.update_position(bg, x, y, scale),
|
@@ -1289,26 +1295,39 @@ with block:
|
|
1289 |
# Create composite in cropped region
|
1290 |
fg_local_x = int(new_width/2 + crop_width*padding)
|
1291 |
fg_local_y = int(new_height/2 + crop_height*padding)
|
1292 |
-
cropped_composite = mask_mover.create_composite(crop_region, fg_local_x, fg_local_y, scale)
|
1293 |
|
1294 |
# Process the cropped region
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1295 |
crop_args = list(args)
|
1296 |
-
crop_args[0] =
|
1297 |
-
crop_args[1] = crop_region
|
1298 |
crop_args[3] = crop_width
|
1299 |
crop_args[4] = crop_height
|
1300 |
-
crop_args = crop_args[:-3] #
|
1301 |
|
1302 |
# Get relit result
|
1303 |
relit_crop = process_relight_bg(*crop_args)[0]
|
1304 |
|
|
|
1305 |
# Resize relit result to match crop dimensions if needed
|
1306 |
if relit_crop.shape[:2] != (crop_height, crop_width):
|
1307 |
relit_crop = resize_without_crop(relit_crop, crop_width, crop_height)
|
|
|
|
|
|
|
1308 |
|
1309 |
# Place relit crop back into original background
|
1310 |
result = background.copy()
|
1311 |
-
result[crop_y:crop_y+crop_height, crop_x:crop_x+crop_width] = relit_crop
|
|
|
|
|
1312 |
|
1313 |
return result
|
1314 |
|
|
|
1217 |
# Create an instance of BackgroundManager
|
1218 |
bg_manager = BackgroundManager()
|
1219 |
|
1220 |
+
input_bg.change(
|
1221 |
+
fn=lambda new_bg: setattr(bg_manager, 'original_bg', None) or new_bg,
|
1222 |
+
inputs=[input_bg],
|
1223 |
+
outputs=[input_bg],
|
1224 |
+
show_progress=False
|
1225 |
+
)
|
1226 |
|
1227 |
x_slider.change(
|
1228 |
fn=lambda bg, x, y, scale: bg_manager.update_position(bg, x, y, scale),
|
|
|
1295 |
# Create composite in cropped region
|
1296 |
fg_local_x = int(new_width/2 + crop_width*padding)
|
1297 |
fg_local_y = int(new_height/2 + crop_height*padding)
|
1298 |
+
#cropped_composite = mask_mover.create_composite(crop_region, fg_local_x, fg_local_y, scale)
|
1299 |
|
1300 |
# Process the cropped region
|
1301 |
+
# crop_args = list(args)
|
1302 |
+
# crop_args[0] = cropped_composite
|
1303 |
+
# crop_args[1] = crop_region
|
1304 |
+
# crop_args[3] = crop_width
|
1305 |
+
# crop_args[4] = crop_height
|
1306 |
+
# crop_args = crop_args[:-3] # Remove position and scale arguments
|
1307 |
+
|
1308 |
crop_args = list(args)
|
1309 |
+
crop_args[0] = None # or an empty placeholder for fg if needed
|
1310 |
+
crop_args[1] = crop_region # keep the background as is
|
1311 |
crop_args[3] = crop_width
|
1312 |
crop_args[4] = crop_height
|
1313 |
+
crop_args = crop_args[:-3] # remove position/scale arguments
|
1314 |
|
1315 |
# Get relit result
|
1316 |
relit_crop = process_relight_bg(*crop_args)[0]
|
1317 |
|
1318 |
+
|
1319 |
# Resize relit result to match crop dimensions if needed
|
1320 |
if relit_crop.shape[:2] != (crop_height, crop_width):
|
1321 |
relit_crop = resize_without_crop(relit_crop, crop_width, crop_height)
|
1322 |
+
|
1323 |
+
final_composite = mask_mover.create_composite(relit_crop, fg_local_x, fg_local_y, scale)
|
1324 |
+
|
1325 |
|
1326 |
# Place relit crop back into original background
|
1327 |
result = background.copy()
|
1328 |
+
#result[crop_y:crop_y+crop_height, crop_x:crop_x+crop_width] = relit_crop
|
1329 |
+
result[crop_y:crop_y+crop_height, crop_x:crop_x+crop_width] = final_composite
|
1330 |
+
|
1331 |
|
1332 |
return result
|
1333 |
|