Spaces:
Runtime error
Runtime error
Update pages/2_ ⬆️_Upload_Video.py
Browse files- pages/2_ ⬆️_Upload_Video.py +20 -7
pages/2_ ⬆️_Upload_Video.py
CHANGED
|
@@ -38,6 +38,12 @@ upload_process_frame = ProcessFrame(thresholds=thresholds)
|
|
| 38 |
pose = get_mediapipe_pose()
|
| 39 |
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
output_video_file = f'output_recorded.mp4'
|
| 42 |
|
| 43 |
if os.path.exists(output_video_file):
|
|
@@ -68,7 +74,6 @@ if up_file and uploaded:
|
|
| 68 |
tfile.write(up_file.read())
|
| 69 |
|
| 70 |
vf = cv2.VideoCapture(tfile.name)
|
| 71 |
-
vf_av = av.open(tfile.name)
|
| 72 |
|
| 73 |
# --------------------- Write the processed video frame. --------------------
|
| 74 |
fps = int(vf.get(cv2.CAP_PROP_FPS))
|
|
@@ -83,11 +88,14 @@ if up_file and uploaded:
|
|
| 83 |
txt = st.sidebar.markdown(ip_vid_str, unsafe_allow_html=True)
|
| 84 |
ip_video = st.sidebar.video(tfile.name)
|
| 85 |
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
# convert frame from BGR to RGB before processing it.
|
| 89 |
-
|
| 90 |
-
out_frame, _ = upload_process_frame.process(
|
| 91 |
stframe.image(out_frame)
|
| 92 |
video_output.write(out_frame[...,::-1])
|
| 93 |
|
|
@@ -106,12 +114,17 @@ if up_file and uploaded:
|
|
| 106 |
|
| 107 |
if os.path.exists(output_video_file):
|
| 108 |
with open(output_video_file, 'rb') as op_vid:
|
| 109 |
-
download_button.download_button('Download Video', data = op_vid, file_name='output_recorded.mp4')
|
| 110 |
-
|
| 111 |
-
|
|
|
|
| 112 |
|
| 113 |
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
|
| 117 |
|
|
|
|
| 38 |
pose = get_mediapipe_pose()
|
| 39 |
|
| 40 |
|
| 41 |
+
download = None
|
| 42 |
+
|
| 43 |
+
if 'download' not in st.session_state:
|
| 44 |
+
st.session_state['download'] = False
|
| 45 |
+
|
| 46 |
+
|
| 47 |
output_video_file = f'output_recorded.mp4'
|
| 48 |
|
| 49 |
if os.path.exists(output_video_file):
|
|
|
|
| 74 |
tfile.write(up_file.read())
|
| 75 |
|
| 76 |
vf = cv2.VideoCapture(tfile.name)
|
|
|
|
| 77 |
|
| 78 |
# --------------------- Write the processed video frame. --------------------
|
| 79 |
fps = int(vf.get(cv2.CAP_PROP_FPS))
|
|
|
|
| 88 |
txt = st.sidebar.markdown(ip_vid_str, unsafe_allow_html=True)
|
| 89 |
ip_video = st.sidebar.video(tfile.name)
|
| 90 |
|
| 91 |
+
while vf.isOpened():
|
| 92 |
+
ret, frame = vf.read()
|
| 93 |
+
if not ret:
|
| 94 |
+
break
|
| 95 |
|
| 96 |
# convert frame from BGR to RGB before processing it.
|
| 97 |
+
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 98 |
+
out_frame, _ = upload_process_frame.process(frame, pose)
|
| 99 |
stframe.image(out_frame)
|
| 100 |
video_output.write(out_frame[...,::-1])
|
| 101 |
|
|
|
|
| 114 |
|
| 115 |
if os.path.exists(output_video_file):
|
| 116 |
with open(output_video_file, 'rb') as op_vid:
|
| 117 |
+
download = download_button.download_button('Download Video', data = op_vid, file_name='output_recorded.mp4')
|
| 118 |
+
|
| 119 |
+
if download:
|
| 120 |
+
st.session_state['download'] = True
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
+
if os.path.exists(output_video_file) and st.session_state['download']:
|
| 125 |
+
os.remove(output_video_file)
|
| 126 |
+
st.session_state['download'] = False
|
| 127 |
+
download_button.empty()
|
| 128 |
|
| 129 |
|
| 130 |
|