Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
import os
|
2 |
-
from sklearn.linear_model import LinearRegression # <-- Add this line
|
3 |
import random
|
4 |
import os
|
5 |
import shutil
|
@@ -14,6 +12,7 @@ from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
|
|
14 |
from reportlab.lib import colors
|
15 |
from datetime import datetime
|
16 |
import joblib
|
|
|
17 |
|
18 |
# Initialize the face mesh model
|
19 |
mp_face_mesh = mp.solutions.face_mesh
|
@@ -207,22 +206,22 @@ def analyze_face(input_data):
|
|
207 |
if isinstance(input_data, str): # Video input (file path in Replit)
|
208 |
cap = cv2.VideoCapture(input_data)
|
209 |
if not cap.isOpened():
|
210 |
-
return
|
211 |
ret, frame = cap.read()
|
212 |
cap.release()
|
213 |
if not ret:
|
214 |
-
return
|
215 |
else: # Image input
|
216 |
frame = input_data
|
217 |
if frame is None:
|
218 |
-
return
|
219 |
|
220 |
# Resize image to reduce processing time
|
221 |
frame = cv2.resize(frame, (640, 480)) # Adjust resolution for Replit
|
222 |
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
223 |
result = face_mesh.process(frame_rgb)
|
224 |
if not result.multi_face_landmarks:
|
225 |
-
return
|
226 |
landmarks = result.multi_face_landmarks[
|
227 |
0].landmark # Fixed: Use integer index
|
228 |
features = extract_features(frame_rgb, landmarks)
|
|
|
|
|
|
|
1 |
import random
|
2 |
import os
|
3 |
import shutil
|
|
|
12 |
from reportlab.lib import colors
|
13 |
from datetime import datetime
|
14 |
import joblib
|
15 |
+
from sklearn.linear_model import LinearRegression
|
16 |
|
17 |
# Initialize the face mesh model
|
18 |
mp_face_mesh = mp.solutions.face_mesh
|
|
|
206 |
if isinstance(input_data, str): # Video input (file path in Replit)
|
207 |
cap = cv2.VideoCapture(input_data)
|
208 |
if not cap.isOpened():
|
209 |
+
return None, None # Return None for both parts if error occurs
|
210 |
ret, frame = cap.read()
|
211 |
cap.release()
|
212 |
if not ret:
|
213 |
+
return None, None # Return None for both parts if error occurs
|
214 |
else: # Image input
|
215 |
frame = input_data
|
216 |
if frame is None:
|
217 |
+
return None, None # Return None for both parts if error occurs
|
218 |
|
219 |
# Resize image to reduce processing time
|
220 |
frame = cv2.resize(frame, (640, 480)) # Adjust resolution for Replit
|
221 |
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
222 |
result = face_mesh.process(frame_rgb)
|
223 |
if not result.multi_face_landmarks:
|
224 |
+
return None, None # Return None for both parts if no face is detected
|
225 |
landmarks = result.multi_face_landmarks[
|
226 |
0].landmark # Fixed: Use integer index
|
227 |
features = extract_features(frame_rgb, landmarks)
|