Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -281,6 +281,17 @@ def process_video(api, drive_service, video_file):
|
|
281 |
bvh_path, bvh_data = download_and_save_bvh(bvh_url, bvh_filename or "motion_capture.bvh")
|
282 |
|
283 |
if bvh_path and bvh_data:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
284 |
progress_bar.progress(1.0)
|
285 |
progress_text.text("Complete!")
|
286 |
|
@@ -296,7 +307,7 @@ def process_video(api, drive_service, video_file):
|
|
296 |
|
297 |
# Save the BVH data to session state for download
|
298 |
st.session_state['bvh_data'] = bvh_data
|
299 |
-
st.session_state['bvh_filename'] =
|
300 |
|
301 |
# Generate a unique timestamp for this result
|
302 |
st.session_state['bvh_timestamp'] = int(time.time())
|
@@ -304,7 +315,7 @@ def process_video(api, drive_service, video_file):
|
|
304 |
return {
|
305 |
'bvh_data': bvh_data,
|
306 |
'bvh_path': bvh_path,
|
307 |
-
'bvh_filename':
|
308 |
'timestamp': st.session_state['bvh_timestamp']
|
309 |
}
|
310 |
|
@@ -416,20 +427,18 @@ def main():
|
|
416 |
st.markdown('<h3 class="section-title">Processing Options</h3>', unsafe_allow_html=True)
|
417 |
|
418 |
if st.button("Start Motion Capture", key="start_capture_button"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
419 |
result = process_video(api, drive_service, st.session_state['uploaded_file'])
|
420 |
|
421 |
-
|
422 |
-
|
423 |
-
# Now just offer it for download to the user
|
424 |
-
with download_container:
|
425 |
-
st.download_button(
|
426 |
-
label="Download BVH",
|
427 |
-
data=result['bvh_data'],
|
428 |
-
file_name=result['bvh_filename'],
|
429 |
-
mime="application/octet-stream",
|
430 |
-
key=f"download_new_{result['timestamp']}"
|
431 |
-
)
|
432 |
-
else:
|
433 |
st.error("Failed to generate BVH file.")
|
434 |
|
435 |
# If BVH data is in session state (from a previous run), offer it for download
|
|
|
281 |
bvh_path, bvh_data = download_and_save_bvh(bvh_url, bvh_filename or "motion_capture.bvh")
|
282 |
|
283 |
if bvh_path and bvh_data:
|
284 |
+
# Generate a timestamp for unique filenames
|
285 |
+
timestamp_str = time.strftime("%Y%m%d_%H%M%S")
|
286 |
+
|
287 |
+
# Create a filename with timestamp
|
288 |
+
if bvh_filename:
|
289 |
+
# Extract the base name without extension
|
290 |
+
base_name, ext = os.path.splitext(bvh_filename)
|
291 |
+
timestamped_filename = f"{base_name}_{timestamp_str}{ext}"
|
292 |
+
else:
|
293 |
+
timestamped_filename = f"motion_capture_{timestamp_str}.bvh"
|
294 |
+
|
295 |
progress_bar.progress(1.0)
|
296 |
progress_text.text("Complete!")
|
297 |
|
|
|
307 |
|
308 |
# Save the BVH data to session state for download
|
309 |
st.session_state['bvh_data'] = bvh_data
|
310 |
+
st.session_state['bvh_filename'] = timestamped_filename
|
311 |
|
312 |
# Generate a unique timestamp for this result
|
313 |
st.session_state['bvh_timestamp'] = int(time.time())
|
|
|
315 |
return {
|
316 |
'bvh_data': bvh_data,
|
317 |
'bvh_path': bvh_path,
|
318 |
+
'bvh_filename': timestamped_filename,
|
319 |
'timestamp': st.session_state['bvh_timestamp']
|
320 |
}
|
321 |
|
|
|
427 |
st.markdown('<h3 class="section-title">Processing Options</h3>', unsafe_allow_html=True)
|
428 |
|
429 |
if st.button("Start Motion Capture", key="start_capture_button"):
|
430 |
+
# Clear previous BVH data when starting a new process
|
431 |
+
if 'bvh_data' in st.session_state:
|
432 |
+
del st.session_state['bvh_data']
|
433 |
+
if 'bvh_filename' in st.session_state:
|
434 |
+
del st.session_state['bvh_filename']
|
435 |
+
if 'bvh_timestamp' in st.session_state:
|
436 |
+
del st.session_state['bvh_timestamp']
|
437 |
+
|
438 |
result = process_video(api, drive_service, st.session_state['uploaded_file'])
|
439 |
|
440 |
+
# No need to create a download button here as it will be created by the code below
|
441 |
+
if not result or 'bvh_data' not in result:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
442 |
st.error("Failed to generate BVH file.")
|
443 |
|
444 |
# If BVH data is in session state (from a previous run), offer it for download
|