Alessio Grancini commited on
Commit
6df2431
·
verified ·
1 Parent(s): 1d9eab5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -64,7 +64,6 @@ def process_image(image):
64
  return image_segmentation, depth_colormap, dist_image, plot_fig
65
 
66
 
67
-
68
  @spaces.GPU # Requests GPU for depth estimation
69
  def test_process_img(image):
70
  image = utils.resize(image)
@@ -87,7 +86,6 @@ def process_video(vid_path=None):
87
  return None
88
 
89
 
90
-
91
  def update_segmentation_options(options):
92
  img_seg.is_show_bounding_boxes = True if 'Show Boundary Box' in options else False
93
  img_seg.is_show_segmentation = True if 'Show Segmentation Region' in options else False
@@ -234,8 +232,14 @@ def get_detection_data(image_data):
234
  if isinstance(image_data, dict):
235
  nested_dict = image_data.get("image", {}).get("image", {})
236
  full_data_url = nested_dict.get("data", "")
 
 
 
237
  else:
238
  full_data_url = image_data
 
 
 
239
 
240
  if not full_data_url:
241
  return {"error": "No base64 data found in input."}
@@ -250,6 +254,11 @@ def get_detection_data(image_data):
250
  img = np.array(img)
251
  img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
252
 
 
 
 
 
 
253
  #image = utils.resize(img)
254
  resized_image = utils.resize(img) #depth requires resizing
255
  print(f"Debug - Resized image shape: {resized_image.shape}")
 
64
  return image_segmentation, depth_colormap, dist_image, plot_fig
65
 
66
 
 
67
  @spaces.GPU # Requests GPU for depth estimation
68
  def test_process_img(image):
69
  image = utils.resize(image)
 
86
  return None
87
 
88
 
 
89
  def update_segmentation_options(options):
90
  img_seg.is_show_bounding_boxes = True if 'Show Boundary Box' in options else False
91
  img_seg.is_show_segmentation = True if 'Show Segmentation Region' in options else False
 
232
  if isinstance(image_data, dict):
233
  nested_dict = image_data.get("image", {}).get("image", {})
234
  full_data_url = nested_dict.get("data", "")
235
+ # get model size and confidence threshold
236
+ model_size = image_data.get("model_size", "Small - Better performance and less accuracy")
237
+ confidence_threshold = image_data.get("confidence_threshold", 0.6) # Default to 60%
238
  else:
239
  full_data_url = image_data
240
+
241
+ model_size = "Small - Better performance and less accuracy" # Fallback default
242
+ confidence_threshold = 0.6 # Fallback default
243
 
244
  if not full_data_url:
245
  return {"error": "No base64 data found in input."}
 
254
  img = np.array(img)
255
  img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
256
 
257
+ # Apply model size and confidence threshold
258
+ print(f"Applying settings - Model Size: {model_size}, Confidence Threshold: {confidence_threshold}")
259
+ model_selector(model_size) # Update models based on input
260
+ update_confidence_threshold(confidence_threshold * 100) # Scale to 0-100 for consistency
261
+
262
  #image = utils.resize(img)
263
  resized_image = utils.resize(img) #depth requires resizing
264
  print(f"Debug - Resized image shape: {resized_image.shape}")