JefferyJapheth commited on
Commit
2165cdc
1 Parent(s): 9f9bcb1

app with exception handling for face landmark

Browse files
Files changed (1) hide show
  1. app.py +16 -14
app.py CHANGED
@@ -219,22 +219,24 @@ with mp_holistic.Holistic(min_detection_confidence=0.5, min_tracking_confidence=
219
  image, results = mediapipe_detection(frame, holistic)
220
  print(results)
221
 
222
- if results is not None:
223
  landmarks = extract_keypoints(results)
224
- if landmarks is not None:
225
- # Calculate the number of landmarks per frame
226
- landmarks_per_frame = len(landmarks) // (N_ROWS * N_DIMS)
227
- # Reshape the landmarks to have shape (None, N_ROWS, N_DIMS)
228
- landmarks = landmarks.reshape(-1, landmarks_per_frame, N_DIMS)
229
- # Initialize PreprocessLayer
230
- preprocess_layer = PreprocessLayer()
231
- # Call the PreprocessLayer to preprocess the landmarks
232
- processed_landmarks, _ = preprocess_layer.call(landmarks)
233
- prediction = make_prediction(processed_landmarks) # Pass the preprocessed landmarks to make_prediction
234
- print("Prediction:", prediction)
235
- return prediction
 
 
236
  else:
237
- return "Could not detect landmarks. Make sure your webcam is working properly."
238
 
239
 
240
  # Define the Gradio interface
 
219
  image, results = mediapipe_detection(frame, holistic)
220
  print(results)
221
 
222
+ if results is not None and results.face_landmarks is not None:
223
  landmarks = extract_keypoints(results)
224
+ if landmarks is not None:
225
+ # Calculate the number of landmarks per frame
226
+ landmarks_per_frame = len(landmarks) // (N_ROWS * N_DIMS)
227
+ # Reshape the landmarks to have shape (None, N_ROWS, N_DIMS)
228
+ landmarks = landmarks.reshape(-1, landmarks_per_frame, N_DIMS)
229
+ # Initialize PreprocessLayer
230
+ preprocess_layer = PreprocessLayer()
231
+ # Call the PreprocessLayer to preprocess the landmarks
232
+ processed_landmarks, _ = preprocess_layer.call(landmarks)
233
+ prediction = make_prediction(processed_landmarks) # Pass the preprocessed landmarks to make_prediction
234
+ print("Prediction:", prediction)
235
+ return prediction
236
+ else:
237
+ return "Could not detect landmarks or extract keypoints. Make sure your webcam is working properly."
238
  else:
239
+ return "Could not detect face landmarks. Make sure your webcam is working properly."
240
 
241
 
242
  # Define the Gradio interface