MogensR commited on
Commit
68bff62
·
verified ·
1 Parent(s): 8da2aa3

Update ui.py

Browse files
Files changed (1) hide show
  1. ui.py +20 -18
ui.py CHANGED
@@ -4,6 +4,7 @@
4
  - Clean, responsive layout with Streamlit
5
  - File uploaders, previews, and processing controls
6
  - Log viewer and download buttons
 
7
  """
8
  import streamlit as st
9
  import os
@@ -13,6 +14,7 @@
13
  import logging
14
  from datetime import datetime
15
  import time
 
16
  logger = logging.getLogger("Advanced Video Background Replacer")
17
 
18
  # --- UI Helpers ---
@@ -44,8 +46,6 @@ def render_ui(process_video_func):
44
  with st.sidebar:
45
  st.subheader("System Status")
46
  st.markdown("**Log file:** `/tmp/app.log`")
47
- # (log-level selector has been REMOVED, handled in streamlit_app.py)
48
-
49
  if st.session_state.get('gpu_available', False):
50
  try:
51
  import torch
@@ -55,10 +55,8 @@ def render_ui(process_video_func):
55
  st.success(f"GPU: {dev}")
56
  else:
57
  st.error("GPU: Not Available")
58
- # Log viewer controls
59
  st.checkbox("Auto-refresh log tail (every 2s)", key="auto_refresh_logs")
60
  st.number_input("Tail last N lines", min_value=50, max_value=5000, step=50, key="log_tail_lines")
61
- # Download logs button
62
  log_bytes = read_file_bytes("/tmp/app.log")
63
  st.download_button(
64
  "Download Logs",
@@ -68,7 +66,6 @@ def render_ui(process_video_func):
68
  use_container_width=True,
69
  disabled=not bool(log_bytes)
70
  )
71
- # Log tail viewer
72
  with st.expander("View Log Tail", expanded=True):
73
  if st.session_state.get('auto_refresh_logs', False):
74
  time.sleep(2)
@@ -107,7 +104,8 @@ def render_ui(process_video_func):
107
  horizontal=True,
108
  key="bg_type_radio"
109
  )
110
- # Background Image Upload
 
111
  if bg_type == "Image":
112
  bg_image = st.file_uploader(
113
  "Upload Background Image",
@@ -115,17 +113,21 @@ def render_ui(process_video_func):
115
  key="bg_image_uploader"
116
  )
117
  bg_preview_placeholder = st.empty()
 
118
  if bg_image is not None:
119
  try:
120
- bg_image_pil = Image.open(bg_image)
 
121
  with bg_preview_placeholder.container():
122
- st.image(bg_image_pil, caption="Selected Background", use_column_width=True)
123
  except Exception as e:
124
  logger.error(f"[UI] Background image error: {e}", exc_info=True)
125
  bg_preview_placeholder.error(f"Cannot display image: {e}")
 
126
  else:
127
  bg_preview_placeholder.empty()
128
- # Background Color Picker
 
129
  else:
130
  selected_color = st.color_picker(
131
  "Choose Background Color",
@@ -145,22 +147,22 @@ def render_ui(process_video_func):
145
  st.image(st.session_state.color_display_cache, caption="Selected Color", width=200)
146
  else:
147
  color_preview_placeholder.empty()
 
148
  # --- Process Button ---
149
  st.header("3. Process Video")
150
- can_process = (uploaded_video is not None and not st.session_state.get('processing', False))
151
  if st.button("Process Video", disabled=not can_process, use_container_width=True):
152
  try:
153
  logger.info("Process Video button clicked")
154
- if bg_type == "Image" and bg_image is None:
155
  st.error("Please upload a background image")
 
 
 
 
 
156
  else:
157
- background = bg_image if bg_type == "Image" else st.session_state.get('bg_color')
158
- with st.spinner("Processing video..."):
159
- success = process_video_func(uploaded_video, bg_image, background, bg_type)
160
- if success:
161
- st.success("Video processing complete!")
162
- else:
163
- st.error("Video processing failed. Check logs for details.")
164
  except Exception as e:
165
  logger.error(f"[UI] Process video error: {e}", exc_info=True)
166
  st.error(f"Processing error: {str(e)}. Check logs for details.")
 
4
  - Clean, responsive layout with Streamlit
5
  - File uploaders, previews, and processing controls
6
  - Log viewer and download buttons
7
+ - Passes proper PIL.Image or color string into pipeline
8
  """
9
  import streamlit as st
10
  import os
 
14
  import logging
15
  from datetime import datetime
16
  import time
17
+
18
  logger = logging.getLogger("Advanced Video Background Replacer")
19
 
20
  # --- UI Helpers ---
 
46
  with st.sidebar:
47
  st.subheader("System Status")
48
  st.markdown("**Log file:** `/tmp/app.log`")
 
 
49
  if st.session_state.get('gpu_available', False):
50
  try:
51
  import torch
 
55
  st.success(f"GPU: {dev}")
56
  else:
57
  st.error("GPU: Not Available")
 
58
  st.checkbox("Auto-refresh log tail (every 2s)", key="auto_refresh_logs")
59
  st.number_input("Tail last N lines", min_value=50, max_value=5000, step=50, key="log_tail_lines")
 
60
  log_bytes = read_file_bytes("/tmp/app.log")
61
  st.download_button(
62
  "Download Logs",
 
66
  use_container_width=True,
67
  disabled=not bool(log_bytes)
68
  )
 
69
  with st.expander("View Log Tail", expanded=True):
70
  if st.session_state.get('auto_refresh_logs', False):
71
  time.sleep(2)
 
104
  horizontal=True,
105
  key="bg_type_radio"
106
  )
107
+ background = None
108
+ # --- Background Image Upload ---
109
  if bg_type == "Image":
110
  bg_image = st.file_uploader(
111
  "Upload Background Image",
 
113
  key="bg_image_uploader"
114
  )
115
  bg_preview_placeholder = st.empty()
116
+ background_pil = None
117
  if bg_image is not None:
118
  try:
119
+ bg_image.seek(0)
120
+ background_pil = Image.open(bg_image).convert("RGB")
121
  with bg_preview_placeholder.container():
122
+ st.image(background_pil, caption="Selected Background", use_column_width=True)
123
  except Exception as e:
124
  logger.error(f"[UI] Background image error: {e}", exc_info=True)
125
  bg_preview_placeholder.error(f"Cannot display image: {e}")
126
+ background_pil = None
127
  else:
128
  bg_preview_placeholder.empty()
129
+ background = background_pil
130
+ # --- Background Color Picker ---
131
  else:
132
  selected_color = st.color_picker(
133
  "Choose Background Color",
 
147
  st.image(st.session_state.color_display_cache, caption="Selected Color", width=200)
148
  else:
149
  color_preview_placeholder.empty()
150
+ background = selected_color # "#RRGGBB"
151
  # --- Process Button ---
152
  st.header("3. Process Video")
153
+ can_process = (uploaded_video is not None and not st.session_state.get('processing', False) and (background is not None))
154
  if st.button("Process Video", disabled=not can_process, use_container_width=True):
155
  try:
156
  logger.info("Process Video button clicked")
157
+ if bg_type == "Image" and background is None:
158
  st.error("Please upload a background image")
159
+ return
160
+ with st.spinner("Processing video..."):
161
+ success = process_video_func(uploaded_video, background, bg_type)
162
+ if success:
163
+ st.success("Video processing complete!")
164
  else:
165
+ st.error("Video processing failed. Check logs for details.")
 
 
 
 
 
 
166
  except Exception as e:
167
  logger.error(f"[UI] Process video error: {e}", exc_info=True)
168
  st.error(f"Processing error: {str(e)}. Check logs for details.")