Spaces:
Sleeping
Sleeping
Update accident_app.py
Browse files- accident_app.py +10 -1
accident_app.py
CHANGED
@@ -85,12 +85,21 @@ def create_chunks_from_frames(frames, window_size=30):
|
|
85 |
chunks[-1] = pad_chunk(chunks[-1])
|
86 |
return chunks
|
87 |
|
88 |
-
|
89 |
def overlay_predictions_to_video(frames, predictions):
|
90 |
temp_dir = 'temp_frames'
|
91 |
|
92 |
# Clear existing frames and video if they exist
|
93 |
if os.path.exists(temp_dir):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
shutil.rmtree(temp_dir)
|
95 |
os.makedirs(temp_dir)
|
96 |
|
|
|
85 |
chunks[-1] = pad_chunk(chunks[-1])
|
86 |
return chunks
|
87 |
|
|
|
88 |
def overlay_predictions_to_video(frames, predictions):
|
89 |
temp_dir = 'temp_frames'
|
90 |
|
91 |
# Clear existing frames and video if they exist
|
92 |
if os.path.exists(temp_dir):
|
93 |
+
for filename in os.listdir(temp_dir):
|
94 |
+
file_path = os.path.join(temp_dir, filename)
|
95 |
+
try:
|
96 |
+
if os.path.isfile(file_path) or os.path.islink(file_path):
|
97 |
+
os.unlink(file_path)
|
98 |
+
elif os.path.isdir(file_path):
|
99 |
+
shutil.rmtree(file_path)
|
100 |
+
except Exception as e:
|
101 |
+
print(f'Failed to delete {file_path}. Reason: {e}')
|
102 |
+
|
103 |
shutil.rmtree(temp_dir)
|
104 |
os.makedirs(temp_dir)
|
105 |
|