Update ui.py
Browse files
ui.py
CHANGED
|
@@ -12,14 +12,12 @@
|
|
| 12 |
from PIL import Image
|
| 13 |
import numpy as np
|
| 14 |
import logging
|
| 15 |
-
from datetime import datetime
|
| 16 |
import time
|
| 17 |
|
| 18 |
logger = logging.getLogger("Advanced Video Background Replacer")
|
| 19 |
|
| 20 |
# --- UI Helpers ---
|
| 21 |
def tail_file(path: str, lines: int = 400) -> str:
|
| 22 |
-
"""Read last N lines from a text file efficiently."""
|
| 23 |
if not os.path.exists(path):
|
| 24 |
return "(log file not found)"
|
| 25 |
try:
|
|
@@ -30,7 +28,6 @@ def tail_file(path: str, lines: int = 400) -> str:
|
|
| 30 |
return f"(failed to read log: {e})"
|
| 31 |
|
| 32 |
def read_file_bytes(path: str) -> bytes:
|
| 33 |
-
"""Read a file as bytes; return b'' if missing/error."""
|
| 34 |
try:
|
| 35 |
if not os.path.exists(path):
|
| 36 |
return b""
|
|
@@ -39,7 +36,6 @@ def read_file_bytes(path: str) -> bytes:
|
|
| 39 |
except Exception:
|
| 40 |
return b""
|
| 41 |
|
| 42 |
-
# --- Render UI ---
|
| 43 |
def render_ui(process_video_func):
|
| 44 |
try:
|
| 45 |
# --- Sidebar: System Status & Logs ---
|
|
@@ -127,7 +123,6 @@ def render_ui(process_video_func):
|
|
| 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",
|
|
@@ -158,7 +153,8 @@ def render_ui(process_video_func):
|
|
| 158 |
st.error("Please upload a background image")
|
| 159 |
return
|
| 160 |
with st.spinner("Processing video..."):
|
| 161 |
-
|
|
|
|
| 162 |
if success:
|
| 163 |
st.success("Video processing complete!")
|
| 164 |
else:
|
|
|
|
| 12 |
from PIL import Image
|
| 13 |
import numpy as np
|
| 14 |
import logging
|
|
|
|
| 15 |
import time
|
| 16 |
|
| 17 |
logger = logging.getLogger("Advanced Video Background Replacer")
|
| 18 |
|
| 19 |
# --- UI Helpers ---
|
| 20 |
def tail_file(path: str, lines: int = 400) -> str:
|
|
|
|
| 21 |
if not os.path.exists(path):
|
| 22 |
return "(log file not found)"
|
| 23 |
try:
|
|
|
|
| 28 |
return f"(failed to read log: {e})"
|
| 29 |
|
| 30 |
def read_file_bytes(path: str) -> bytes:
|
|
|
|
| 31 |
try:
|
| 32 |
if not os.path.exists(path):
|
| 33 |
return b""
|
|
|
|
| 36 |
except Exception:
|
| 37 |
return b""
|
| 38 |
|
|
|
|
| 39 |
def render_ui(process_video_func):
|
| 40 |
try:
|
| 41 |
# --- Sidebar: System Status & Logs ---
|
|
|
|
| 123 |
else:
|
| 124 |
bg_preview_placeholder.empty()
|
| 125 |
background = background_pil
|
|
|
|
| 126 |
else:
|
| 127 |
selected_color = st.color_picker(
|
| 128 |
"Choose Background Color",
|
|
|
|
| 153 |
st.error("Please upload a background image")
|
| 154 |
return
|
| 155 |
with st.spinner("Processing video..."):
|
| 156 |
+
# NOTE: Always pass lowercased bg_type!
|
| 157 |
+
success = process_video_func(uploaded_video, background, bg_type.lower())
|
| 158 |
if success:
|
| 159 |
st.success("Video processing complete!")
|
| 160 |
else:
|