Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -308,6 +308,7 @@ def process_video(api, drive_service, video_file):
|
|
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())
|
@@ -421,37 +422,65 @@ def main():
|
|
421 |
if uploaded_file := st.session_state.get('uploaded_file'):
|
422 |
st.video(uploaded_file)
|
423 |
|
424 |
-
download_container = st.container()
|
425 |
-
|
426 |
if st.session_state.get('uploaded_file'):
|
427 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
428 |
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
437 |
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
with download_container:
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
455 |
|
456 |
st.markdown('</div>', unsafe_allow_html=True)
|
457 |
|
|
|
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 |
+
st.session_state['bvh_path'] = bvh_path # Save path for deletion later
|
312 |
|
313 |
# Generate a unique timestamp for this result
|
314 |
st.session_state['bvh_timestamp'] = int(time.time())
|
|
|
422 |
if uploaded_file := st.session_state.get('uploaded_file'):
|
423 |
st.video(uploaded_file)
|
424 |
|
|
|
|
|
425 |
if st.session_state.get('uploaded_file'):
|
426 |
+
# Create containers for progress indicators and buttons
|
427 |
+
progress_container = st.container()
|
428 |
+
button_container = st.container()
|
429 |
+
download_container = st.container()
|
430 |
+
|
431 |
+
# Place these progress indicators above the button but only show when processing
|
432 |
+
with progress_container:
|
433 |
+
# This section will be populated during processing
|
434 |
+
pass
|
435 |
|
436 |
+
# Place the button below the progress indicators
|
437 |
+
with button_container:
|
438 |
+
st.markdown('<h3 class="section-title">Processing Options</h3>', unsafe_allow_html=True)
|
439 |
+
if st.button("Start Motion Capture", key="start_capture_button"):
|
440 |
+
# Clear previous BVH data when starting a new process
|
441 |
+
if 'bvh_data' in st.session_state:
|
442 |
+
del st.session_state['bvh_data']
|
443 |
+
if 'bvh_filename' in st.session_state:
|
444 |
+
del st.session_state['bvh_filename']
|
445 |
+
if 'bvh_timestamp' in st.session_state:
|
446 |
+
del st.session_state['bvh_timestamp']
|
447 |
+
if 'bvh_path' in st.session_state and os.path.exists(st.session_state['bvh_path']):
|
448 |
+
try:
|
449 |
+
os.remove(st.session_state['bvh_path'])
|
450 |
+
except Exception as e:
|
451 |
+
st.warning(f"Could not delete previous local file: {e}")
|
452 |
|
453 |
+
# Use the progress container for progress indicators
|
454 |
+
with progress_container:
|
455 |
+
result = process_video(api, drive_service, st.session_state['uploaded_file'])
|
456 |
+
|
457 |
+
if not result or 'bvh_data' not in result:
|
458 |
+
st.error("Failed to generate BVH file.")
|
459 |
+
|
460 |
+
# If BVH data is in session state (from a previous run), offer it for download
|
461 |
with download_container:
|
462 |
+
if 'bvh_data' in st.session_state and 'bvh_filename' in st.session_state:
|
463 |
+
timestamp = st.session_state.get('bvh_timestamp', int(time.time()))
|
464 |
+
|
465 |
+
# Create a callback for when download completes
|
466 |
+
def on_download_complete():
|
467 |
+
if 'bvh_path' in st.session_state and os.path.exists(st.session_state['bvh_path']):
|
468 |
+
try:
|
469 |
+
os.remove(st.session_state['bvh_path'])
|
470 |
+
st.session_state['bvh_path_deleted'] = True
|
471 |
+
except Exception as e:
|
472 |
+
st.warning(f"Failed to delete local BVH file: {e}")
|
473 |
+
|
474 |
+
# This doesn't actually work as Streamlit doesn't support download callbacks
|
475 |
+
# Instead, we'll clean up at the start of a new process
|
476 |
+
download_button = st.download_button(
|
477 |
+
label="Download BVH",
|
478 |
+
data=st.session_state['bvh_data'],
|
479 |
+
file_name=st.session_state['bvh_filename'],
|
480 |
+
mime="application/octet-stream",
|
481 |
+
key=f"download_saved_{timestamp}",
|
482 |
+
on_click=on_download_complete
|
483 |
+
)
|
484 |
|
485 |
st.markdown('</div>', unsafe_allow_html=True)
|
486 |
|