Update streamlit_app.py
Browse files- streamlit_app.py +17 -8
streamlit_app.py
CHANGED
|
@@ -102,6 +102,8 @@ def process_video(uploaded_video, bg_image, bg_color, bg_type):
|
|
| 102 |
run_id = uuid.uuid4().hex[:8]
|
| 103 |
logger.info("=" * 80)
|
| 104 |
logger.info(f"[RUN {run_id}] VIDEO PROCESSING STARTED at {datetime.utcnow().isoformat()}Z")
|
|
|
|
|
|
|
| 105 |
logger.info("=" * 80)
|
| 106 |
st.session_state.processing = True
|
| 107 |
st.session_state.processed_video_bytes = None
|
|
@@ -114,15 +116,18 @@ def process_video(uploaded_video, bg_image, bg_color, bg_type):
|
|
| 114 |
uploaded_video.seek(0)
|
| 115 |
tmp_vid.write(uploaded_video.read())
|
| 116 |
tmp_vid_path = tmp_vid.name
|
|
|
|
| 117 |
# Stage 1: Create transparent video and extract audio
|
| 118 |
transparent_path, audio_path = stage1_create_transparent_video(tmp_vid_path)
|
| 119 |
if not transparent_path or not os.path.exists(transparent_path):
|
| 120 |
raise RuntimeError("Stage 1 failed: Transparent video not created")
|
|
|
|
| 121 |
# Stage 2: Composite with background and restore audio
|
| 122 |
background = bg_image.convert("RGB") if bg_type == "Image" else bg_color
|
| 123 |
final_path = stage2_composite_background(transparent_path, audio_path, background, bg_type.lower())
|
| 124 |
if not final_path or not os.path.exists(final_path):
|
| 125 |
raise RuntimeError("Stage 2 failed: Final video not created")
|
|
|
|
| 126 |
# Load final video into memory for download
|
| 127 |
with open(final_path, 'rb') as f:
|
| 128 |
st.session_state.processed_video_bytes = f.read()
|
|
@@ -141,14 +146,18 @@ def process_video(uploaded_video, bg_image, bg_color, bg_type):
|
|
| 141 |
logger.info(f"[RUN {run_id}] Processing finished")
|
| 142 |
# --- Main App Entry Point ---
|
| 143 |
def main():
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
if __name__ == "__main__":
|
| 153 |
setup_t4_environment()
|
| 154 |
main()
|
|
|
|
| 102 |
run_id = uuid.uuid4().hex[:8]
|
| 103 |
logger.info("=" * 80)
|
| 104 |
logger.info(f"[RUN {run_id}] VIDEO PROCESSING STARTED at {datetime.utcnow().isoformat()}Z")
|
| 105 |
+
logger.info(f"[RUN {run_id}] Video size={len(uploaded_video.read()) / 1e6:.2f}MB, BG type={bg_type}")
|
| 106 |
+
uploaded_video.seek(0) # Reset for later read
|
| 107 |
logger.info("=" * 80)
|
| 108 |
st.session_state.processing = True
|
| 109 |
st.session_state.processed_video_bytes = None
|
|
|
|
| 116 |
uploaded_video.seek(0)
|
| 117 |
tmp_vid.write(uploaded_video.read())
|
| 118 |
tmp_vid_path = tmp_vid.name
|
| 119 |
+
logger.info(f"[RUN {run_id}] Temporary video path: {tmp_vid_path}")
|
| 120 |
# Stage 1: Create transparent video and extract audio
|
| 121 |
transparent_path, audio_path = stage1_create_transparent_video(tmp_vid_path)
|
| 122 |
if not transparent_path or not os.path.exists(transparent_path):
|
| 123 |
raise RuntimeError("Stage 1 failed: Transparent video not created")
|
| 124 |
+
logger.info(f"[RUN {run_id}] Stage 1 completed: Transparent path={transparent_path}, Audio path={audio_path}")
|
| 125 |
# Stage 2: Composite with background and restore audio
|
| 126 |
background = bg_image.convert("RGB") if bg_type == "Image" else bg_color
|
| 127 |
final_path = stage2_composite_background(transparent_path, audio_path, background, bg_type.lower())
|
| 128 |
if not final_path or not os.path.exists(final_path):
|
| 129 |
raise RuntimeError("Stage 2 failed: Final video not created")
|
| 130 |
+
logger.info(f"[RUN {run_id}] Stage 2 completed: Final path={final_path}")
|
| 131 |
# Load final video into memory for download
|
| 132 |
with open(final_path, 'rb') as f:
|
| 133 |
st.session_state.processed_video_bytes = f.read()
|
|
|
|
| 146 |
logger.info(f"[RUN {run_id}] Processing finished")
|
| 147 |
# --- Main App Entry Point ---
|
| 148 |
def main():
|
| 149 |
+
try:
|
| 150 |
+
st.set_page_config(
|
| 151 |
+
page_title=APP_NAME,
|
| 152 |
+
page_icon="🎥",
|
| 153 |
+
layout="wide",
|
| 154 |
+
initial_sidebar_state="expanded"
|
| 155 |
+
)
|
| 156 |
+
initialize_session_state()
|
| 157 |
+
render_ui(process_video)
|
| 158 |
+
except Exception as e:
|
| 159 |
+
logger.error(f"Main app error: {e}", exc_info=True)
|
| 160 |
+
st.error(f"App startup failed: {str(e)}. Check logs for details.")
|
| 161 |
if __name__ == "__main__":
|
| 162 |
setup_t4_environment()
|
| 163 |
main()
|