Ashoka74 commited on
Commit
f17bf1f
Β·
verified Β·
1 Parent(s): f14a178

Update gradio_demo.py

Browse files
Files changed (1) hide show
  1. gradio_demo.py +17 -20
gradio_demo.py CHANGED
@@ -835,17 +835,12 @@ def compress_image(image):
835
  compressed_img = np.array(Image.open("compressed_image.jpg"))
836
  return compressed_img
837
 
838
-
839
  @spaces.GPU(duration=60)
840
  @torch.inference_mode
841
- @hydra.main(config_path="/home/user/app/configs", config_name="sam2_hiera_l")
842
- def process_image(cfg: DictConfig, input_image, input_text):
843
  """Main processing function for the Gradio interface"""
844
 
845
- print(f"Config: {cfg}")
846
- print(f"Input Image: {input_image}")
847
- print(f"Input Text: {input_text}")
848
-
849
  # Initialize configs
850
  API_TOKEN = "9c8c865e10ec1821bea79d9fa9dc8720"
851
  SAM2_CHECKPOINT = "./checkpoints/sam2_hiera_large.pt"
@@ -1294,9 +1289,9 @@ with block:
1294
 
1295
  # return mask_mover.create_composite(original_bg, x_pos, y_pos, scale)
1296
 
1297
- # class BackgroundManager:
1298
- # def __init__(self):
1299
- # self.original_bg = None
1300
 
1301
  # # def update_position(self, background, x_pos, y_pos, scale):
1302
  # # """Update composite when position changes"""
@@ -1313,13 +1308,18 @@ with block:
1313
 
1314
  # # return mask_mover.create_composite(self.original_bg, x_pos, y_pos, scale)
1315
 
1316
- # def update_position(background, x_pos, y_pos, scale):
1317
- # if background is None:
1318
- # return None
1319
- # # Restore a fresh copy of the original background
1320
- # fresh_bg = bg_manager.original_bg.copy()
1321
- # # Composite the foreground once
1322
- # return mask_mover.create_composite(fresh_bg, float(x_pos), float(y_pos), float(scale))
 
 
 
 
 
1323
 
1324
  def update_position(background, x_pos, y_pos, scale):
1325
  if background is None:
@@ -1330,9 +1330,6 @@ with block:
1330
 
1331
 
1332
 
1333
- # Create an instance of BackgroundManager
1334
- # bg_manager = BackgroundManager()
1335
-
1336
  input_bg.change(
1337
  fn=lambda new_bg: setattr(bg_manager, 'original_bg', None) or new_bg,
1338
  inputs=[input_bg],
 
835
  compressed_img = np.array(Image.open("compressed_image.jpg"))
836
  return compressed_img
837
 
838
+ # @hydra.main(config_path="/home/user/app/configs", config_name="sam2_hiera_l")
839
  @spaces.GPU(duration=60)
840
  @torch.inference_mode
841
+ def process_image(input_image, input_text):
 
842
  """Main processing function for the Gradio interface"""
843
 
 
 
 
 
844
  # Initialize configs
845
  API_TOKEN = "9c8c865e10ec1821bea79d9fa9dc8720"
846
  SAM2_CHECKPOINT = "./checkpoints/sam2_hiera_large.pt"
 
1289
 
1290
  # return mask_mover.create_composite(original_bg, x_pos, y_pos, scale)
1291
 
1292
+ class BackgroundManager:
1293
+ def __init__(self):
1294
+ self.original_bg = None
1295
 
1296
  # # def update_position(self, background, x_pos, y_pos, scale):
1297
  # # """Update composite when position changes"""
 
1308
 
1309
  # # return mask_mover.create_composite(self.original_bg, x_pos, y_pos, scale)
1310
 
1311
+ # def update_position(background, x_pos, y_pos, scale):
1312
+ # if background is None:
1313
+ # return None
1314
+ # # Restore a fresh copy of the original background
1315
+ # fresh_bg = bg_manager.original_bg.copy()
1316
+ # # Composite the foreground once
1317
+ # return mask_mover.create_composite(fresh_bg, float(x_pos), float(y_pos), float(scale))
1318
+
1319
+
1320
+
1321
+ # Create an instance of BackgroundManager
1322
+ # bg_manager = BackgroundManager()
1323
 
1324
  def update_position(background, x_pos, y_pos, scale):
1325
  if background is None:
 
1330
 
1331
 
1332
 
 
 
 
1333
  input_bg.change(
1334
  fn=lambda new_bg: setattr(bg_manager, 'original_bg', None) or new_bg,
1335
  inputs=[input_bg],