Spaces:
Sleeping
Sleeping
Commit
·
3934710
1
Parent(s):
1a9225c
Update main.py
Browse files
main.py
CHANGED
@@ -4,6 +4,7 @@ import cv2
|
|
4 |
import face_detection
|
5 |
import numpy as np
|
6 |
import base64
|
|
|
7 |
|
8 |
app = Flask(__name__)
|
9 |
|
@@ -48,30 +49,31 @@ def video_feed():
|
|
48 |
return jsonify({'error': 'No video file in the request'})
|
49 |
|
50 |
video_file = request.files['video']
|
|
|
|
|
51 |
|
52 |
-
|
53 |
-
return jsonify({'error': 'Empty video file'})
|
54 |
|
55 |
-
|
56 |
-
video_bytes = video_file.read()
|
57 |
-
print(video_bytes[:10])
|
58 |
-
video_np = np.frombuffer(video_bytes, dtype=np.uint8)
|
59 |
-
vidcap = cv2.imdecode(video_np, cv2.IMREAD_COLOR)
|
60 |
-
except Exception as e:
|
61 |
-
return jsonify({'error': f'Error decoding video file: {str(e)}'})
|
62 |
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
65 |
|
66 |
-
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
detect_faces_and_save(image)
|
71 |
|
72 |
-
|
|
|
73 |
|
74 |
return jsonify({'result': 'Video parsed'})
|
|
|
|
|
75 |
@app.route('/')
|
76 |
def home():
|
77 |
return jsonify(message='Welcome to the Hugging Face Space!')
|
|
|
4 |
import face_detection
|
5 |
import numpy as np
|
6 |
import base64
|
7 |
+
import os
|
8 |
|
9 |
app = Flask(__name__)
|
10 |
|
|
|
49 |
return jsonify({'error': 'No video file in the request'})
|
50 |
|
51 |
video_file = request.files['video']
|
52 |
+
video_path = "uploaded_video.mp4"
|
53 |
+
video_file.save(video_path)
|
54 |
|
55 |
+
vidObj = cv2.VideoCapture(video_path)
|
|
|
56 |
|
57 |
+
success, image = vidObj.read()
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
+
while success:
|
60 |
+
try:
|
61 |
+
# Call your face detection function here
|
62 |
+
detect_faces_and_save(image)
|
63 |
+
except Exception as e:
|
64 |
+
return jsonify({'error': f'Error processing frames: {str(e)}'})
|
65 |
|
66 |
+
success, image = vidObj.read()
|
67 |
|
68 |
+
# Close the video capture object
|
69 |
+
vidObj.release()
|
|
|
70 |
|
71 |
+
# Delete the video file after processing
|
72 |
+
os.remove(video_path)
|
73 |
|
74 |
return jsonify({'result': 'Video parsed'})
|
75 |
+
|
76 |
+
|
77 |
@app.route('/')
|
78 |
def home():
|
79 |
return jsonify(message='Welcome to the Hugging Face Space!')
|