bulatko commited on
Commit
619881b
·
1 Parent(s): 127405e

fix: validate target_dir in detect_objects before processing

Browse files

- Add early return if target_dir is None or invalid
- Handle reconstruct() error return properly
- Show clear error message when no video/images uploaded

Files changed (1) hide show
  1. mvp.py +9 -2
mvp.py CHANGED
@@ -1131,6 +1131,10 @@ def detect_objects(text_labels, target_dir, conf_thres, *viz_args):
1131
  """
1132
  Detect objects from text labels and return the detected objects.
1133
  """
 
 
 
 
1134
  # Require non-empty text labels
1135
  if not text_labels or not isinstance(text_labels, str) or len([l.strip() for l in text_labels.split(";") if l.strip()]) == 0:
1136
  return None, "Please enter at least one text label (separated by ';')."
@@ -1141,12 +1145,15 @@ def detect_objects(text_labels, target_dir, conf_thres, *viz_args):
1141
  check_weights()
1142
  except Exception as e:
1143
  print(f"Warning: could not ensure Mask2Former weights: {e}")
1144
-
1145
  # 1. Run reconstruction first if needed (checking if predictions exist)
1146
  predictions_path = os.path.join(target_dir, "predictions.npz")
1147
  if not os.path.exists(predictions_path):
1148
  print("Predictions not found, running reconstruction first...")
1149
- reconstruct(target_dir, 50.0, *viz_args, text_labels=text_labels)
 
 
 
1150
 
1151
 
1152
  # Extract text features if provided
 
1131
  """
1132
  Detect objects from text labels and return the detected objects.
1133
  """
1134
+ # Validate target_dir first
1135
+ if not target_dir or target_dir == "None" or not os.path.isdir(target_dir):
1136
+ return None, "Please upload a video or images first."
1137
+
1138
  # Require non-empty text labels
1139
  if not text_labels or not isinstance(text_labels, str) or len([l.strip() for l in text_labels.split(";") if l.strip()]) == 0:
1140
  return None, "Please enter at least one text label (separated by ';')."
 
1145
  check_weights()
1146
  except Exception as e:
1147
  print(f"Warning: could not ensure Mask2Former weights: {e}")
1148
+
1149
  # 1. Run reconstruction first if needed (checking if predictions exist)
1150
  predictions_path = os.path.join(target_dir, "predictions.npz")
1151
  if not os.path.exists(predictions_path):
1152
  print("Predictions not found, running reconstruction first...")
1153
+ result = reconstruct(target_dir, 50.0, *viz_args, text_labels=text_labels)
1154
+ # Check if reconstruction failed
1155
+ if result and len(result) >= 2 and result[0] is None:
1156
+ return None, result[1] # Return error message from reconstruct
1157
 
1158
 
1159
  # Extract text features if provided