hugohabicht01 commited on
Commit
32883c9
·
1 Parent(s): 915a67a

further attempts...

Browse files
Files changed (2) hide show
  1. app.py +10 -15
  2. blurnonymize.py +2 -2
app.py CHANGED
@@ -97,24 +97,19 @@ except Exception as e:
97
  raise gr.Error(f"Failed to load model {MODEL_NAME}. Check logs. Error: {e}")
98
 
99
 
100
- # --- Blurnonymizer Instance ---
101
- try:
102
- blurnonymizer_instance = blurnonymize.ImageBlurnonymizer()
103
- print("Blurnonymizer initialized successfully.")
104
- except Exception as e:
105
- print(f"Error initializing Blurnonymizer: {e}")
106
- print(traceback.format_exc())
107
- raise gr.Error(f"Failed to initialize Blurnonymizer. Check logs. Error: {e}")
108
-
109
  # --- Core Processing Function ---
110
  @spaces.GPU(duration=30)
111
  def anonymise_image(input_image_np: np.ndarray, boxes: list[BoundingBox]):
112
- """Calls the blurnonymizer instance to censor the image."""
113
- if not blurnonymizer_instance:
114
- raise gr.Error("Blurnonymizer not initialized.")
115
- return blurnonymizer_instance.censor_image_blur_easy(
116
- input_image_np, boxes, method="segmentation", verbose=False # Set verbose as needed
117
- )
 
 
 
 
118
 
119
 
120
  def run_model_inference(input_image_pil: Image.Image, prompt_text: str):
 
97
  raise gr.Error(f"Failed to load model {MODEL_NAME}. Check logs. Error: {e}")
98
 
99
 
 
 
 
 
 
 
 
 
 
100
  # --- Core Processing Function ---
101
  @spaces.GPU(duration=30)
102
  def anonymise_image(input_image_np: np.ndarray, boxes: list[BoundingBox]):
103
+ # --- Blurnonymizer Instance ---
104
+ try:
105
+ blurnonymizer_instance = blurnonymize.ImageBlurnonymizer()
106
+ return blurnonymizer_instance.censor_image_blur_easy(
107
+ input_image_np, boxes, method="segmentation", verbose=False # Set verbose as needed
108
+ )
109
+ except Exception as e:
110
+ print(f"Error initializing Blurnonymizer: {e}")
111
+ print(traceback.format_exc())
112
+ raise gr.Error(f"Failed to initialize Blurnonymizer. Check logs. Error: {e}")
113
 
114
 
115
  def run_model_inference(input_image_pil: Image.Image, prompt_text: str):
blurnonymize.py CHANGED
@@ -163,8 +163,8 @@ class ImageBlurnonymizer:
163
  torch.cuda.set_device(device)
164
  self.predictor = SAM2ImagePredictor.from_pretrained(
165
  "facebook/sam2.1-hiera-small",
166
- device=device,
167
- )
168
 
169
  @staticmethod
170
  def _smoothen_mask(mask: np.ndarray):
 
163
  torch.cuda.set_device(device)
164
  self.predictor = SAM2ImagePredictor.from_pretrained(
165
  "facebook/sam2.1-hiera-small",
166
+ device="cuda",
167
+ ).to("cuda").eval()
168
 
169
  @staticmethod
170
  def _smoothen_mask(mask: np.ndarray):