Ashoka74 commited on
Commit
7ab3373
Β·
verified Β·
1 Parent(s): d44199f

Update gradio_demo.py

Browse files
Files changed (1) hide show
  1. gradio_demo.py +9 -6
gradio_demo.py CHANGED
@@ -785,6 +785,8 @@ class MaskMover:
785
 
786
  return np.array(result.convert('RGB')) # Convert back to 'RGB' if needed
787
 
 
 
788
  @spaces.GPU(duration=60)
789
  @torch.inference_mode()
790
  def get_depth(image):
@@ -1358,9 +1360,10 @@ with block:
1358
  # return composite
1359
 
1360
  class BackgroundManager:
1361
- def __init__(self):
1362
  self.original_bg = None # To store the original background
1363
  self.current_mask = None # To store the current mask applied
 
1364
 
1365
  def update_background(self, new_bg):
1366
  """Set a new background."""
@@ -1375,14 +1378,14 @@ with block:
1375
  print("No original background set.")
1376
  return None
1377
 
1378
- # Start from a clean copy of the original background
1379
- fresh_bg = self.original_bg.copy()
1380
 
1381
  # Debugging
1382
  print(f"Updating position: x={x_pos}, y={y_pos}, scale={scale}")
1383
 
1384
- # Composite the foreground onto the fresh background
1385
- composite = mask_mover.create_composite(fresh_bg, x_pos, y_pos, scale)
1386
 
1387
  # Update the current mask
1388
  self.current_mask = composite
@@ -1391,7 +1394,7 @@ with block:
1391
 
1392
  # Create an instance of BackgroundManager
1393
  #bg_manager = gr.State(BackgroundManager())
1394
- bg_manager = BackgroundManager()
1395
 
1396
 
1397
  def update_position_wrapper(background, x_pos, y_pos, scale):
 
785
 
786
  return np.array(result.convert('RGB')) # Convert back to 'RGB' if needed
787
 
788
+
789
+
790
  @spaces.GPU(duration=60)
791
  @torch.inference_mode()
792
  def get_depth(image):
 
1360
  # return composite
1361
 
1362
  class BackgroundManager:
1363
+ def __init__(self, mask_mover):
1364
  self.original_bg = None # To store the original background
1365
  self.current_mask = None # To store the current mask applied
1366
+ self.mask_mover = mask_mover # Reference to the MaskMover instance
1367
 
1368
  def update_background(self, new_bg):
1369
  """Set a new background."""
 
1378
  print("No original background set.")
1379
  return None
1380
 
1381
+ # Use the original background from MaskMover
1382
+ bg = self.mask_mover.original_fg # Assuming original_fg is the background
1383
 
1384
  # Debugging
1385
  print(f"Updating position: x={x_pos}, y={y_pos}, scale={scale}")
1386
 
1387
+ # Composite the foreground onto the original background
1388
+ composite = self.mask_mover.create_composite(bg, x_pos, y_pos, scale)
1389
 
1390
  # Update the current mask
1391
  self.current_mask = composite
 
1394
 
1395
  # Create an instance of BackgroundManager
1396
  #bg_manager = gr.State(BackgroundManager())
1397
+ bg_manager = BackgroundManager(mask_mover)
1398
 
1399
 
1400
  def update_position_wrapper(background, x_pos, y_pos, scale):