Update streamlit_app.py
Browse files- streamlit_app.py +41 -44
streamlit_app.py
CHANGED
|
@@ -235,57 +235,54 @@ def main():
|
|
| 235 |
with col2:
|
| 236 |
st.header("2. Background Settings")
|
| 237 |
bg_type = handle_background_selection()
|
| 238 |
-
|
| 239 |
st.header("3. Process & Download")
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
|
|
|
|
|
|
| 247 |
st.session_state.processing = True
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
# Show processed video if available
|
| 279 |
if 'processed_video_path' in st.session_state and st.session_state.processed_video_path:
|
| 280 |
st.markdown("### Processed Video")
|
| 281 |
-
|
| 282 |
try:
|
| 283 |
-
# Display the video directly from the file
|
| 284 |
with open(st.session_state.processed_video_path, 'rb') as f:
|
| 285 |
video_bytes = f.read()
|
| 286 |
st.video(video_bytes)
|
| 287 |
-
|
| 288 |
-
# Download button
|
| 289 |
st.download_button(
|
| 290 |
label="πΎ Download Processed Video",
|
| 291 |
data=video_bytes,
|
|
@@ -298,4 +295,4 @@ def main():
|
|
| 298 |
logger.error(f"Error displaying video: {str(e)}", exc_info=True)
|
| 299 |
|
| 300 |
if __name__ == "__main__":
|
| 301 |
-
main()
|
|
|
|
| 235 |
with col2:
|
| 236 |
st.header("2. Background Settings")
|
| 237 |
bg_type = handle_background_selection()
|
| 238 |
+
|
| 239 |
st.header("3. Process & Download")
|
| 240 |
+
# ------- FORM WRAP START --------
|
| 241 |
+
with st.form("process_form"):
|
| 242 |
+
submitted = st.form_submit_button(
|
| 243 |
+
"π Process Video",
|
| 244 |
+
disabled=not st.session_state.uploaded_video or st.session_state.processing
|
| 245 |
+
)
|
| 246 |
+
|
| 247 |
+
process_status = st.empty()
|
| 248 |
+
if submitted and not st.session_state.processing:
|
| 249 |
st.session_state.processing = True
|
| 250 |
+
with st.spinner("Processing video (this may take a few minutes)..."):
|
| 251 |
+
try:
|
| 252 |
+
# Prepare background based on type
|
| 253 |
+
background = None
|
| 254 |
+
if bg_type == "image" and 'bg_image' in st.session_state and st.session_state.bg_image is not None:
|
| 255 |
+
background = st.session_state.bg_image
|
| 256 |
+
elif bg_type == "color" and 'bg_color' in st.session_state:
|
| 257 |
+
background = st.session_state.bg_color
|
| 258 |
+
|
| 259 |
+
# Process the video
|
| 260 |
+
output_path = process_video(
|
| 261 |
+
st.session_state.uploaded_video,
|
| 262 |
+
background,
|
| 263 |
+
bg_type=bg_type
|
| 264 |
+
)
|
| 265 |
+
|
| 266 |
+
if output_path and os.path.exists(output_path):
|
| 267 |
+
st.session_state.processed_video_path = output_path
|
| 268 |
+
process_status.success("β
Video processing complete!")
|
| 269 |
+
else:
|
| 270 |
+
process_status.error("β Failed to process video. Please check the logs for details.")
|
| 271 |
+
|
| 272 |
+
except Exception as e:
|
| 273 |
+
process_status.error(f"β An error occurred: {str(e)}")
|
| 274 |
+
logger.exception("Video processing failed")
|
| 275 |
+
finally:
|
| 276 |
+
st.session_state.processing = False
|
| 277 |
+
# ------- FORM WRAP END --------
|
| 278 |
+
|
| 279 |
+
# Show processed video if available (outside form, stable)
|
|
|
|
| 280 |
if 'processed_video_path' in st.session_state and st.session_state.processed_video_path:
|
| 281 |
st.markdown("### Processed Video")
|
|
|
|
| 282 |
try:
|
|
|
|
| 283 |
with open(st.session_state.processed_video_path, 'rb') as f:
|
| 284 |
video_bytes = f.read()
|
| 285 |
st.video(video_bytes)
|
|
|
|
|
|
|
| 286 |
st.download_button(
|
| 287 |
label="πΎ Download Processed Video",
|
| 288 |
data=video_bytes,
|
|
|
|
| 295 |
logger.error(f"Error displaying video: {str(e)}", exc_info=True)
|
| 296 |
|
| 297 |
if __name__ == "__main__":
|
| 298 |
+
main()
|