Update ui/ui_components.py
Browse files- ui/ui_components.py +55 -3
ui/ui_components.py
CHANGED
|
@@ -10,6 +10,7 @@
|
|
| 10 |
from __future__ import annotations
|
| 11 |
import os
|
| 12 |
import gradio as gr
|
|
|
|
| 13 |
|
| 14 |
from ui.callbacks import (
|
| 15 |
cb_load_models,
|
|
@@ -22,6 +23,8 @@
|
|
| 22 |
cb_preset_bg_preview,
|
| 23 |
)
|
| 24 |
|
|
|
|
|
|
|
| 25 |
# Typography & UI polish: sharper text + cleaner cards
|
| 26 |
CSS = """
|
| 27 |
:root {
|
|
@@ -84,6 +87,30 @@
|
|
| 84 |
GRADIENT_COLOR_CHOICES = ["warm_gradient", "tech_dark"]
|
| 85 |
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
def create_interface() -> gr.Blocks:
|
| 88 |
with gr.Blocks(
|
| 89 |
title="🎬 BackgroundFX Pro",
|
|
@@ -235,6 +262,7 @@ def create_interface() -> gr.Blocks:
|
|
| 235 |
with gr.Column(scale=1):
|
| 236 |
out_video = gr.Video(label="Processed Output", interactive=False)
|
| 237 |
statusbox = gr.Textbox(label="Status", lines=8, elem_id="statusbox")
|
|
|
|
| 238 |
with gr.Row():
|
| 239 |
btn_refresh = gr.Button("🔍 Refresh Status", variant="secondary")
|
| 240 |
btn_clear = gr.Button("🧹 Clear", variant="secondary")
|
|
@@ -276,15 +304,36 @@ def _toggle_bg_sections(choice: str):
|
|
| 276 |
# Load models
|
| 277 |
btn_load.click(cb_load_models, outputs=statusbox)
|
| 278 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
# Tiny wrapper to set env for quality before calling the existing callback
|
| 280 |
def _run_with_quality(video_pth, bg_style_val, custom_bg_pth,
|
| 281 |
use_two_stage_state, chroma_p, key_mode,
|
| 282 |
-
prev_mask, prev_gs, quality_val
|
|
|
|
| 283 |
os.environ["BFX_QUALITY"] = (quality_val or "balanced")
|
| 284 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
video_pth, bg_style_val, custom_bg_pth,
|
| 286 |
use_two_stage_state, chroma_p, key_mode, prev_mask, prev_gs
|
| 287 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
|
| 289 |
# Always two-stage: pass use_two_stage=True to callback via State
|
| 290 |
btn_run.click(
|
|
@@ -299,6 +348,9 @@ def _run_with_quality(video_pth, bg_style_val, custom_bg_pth,
|
|
| 299 |
preview_mask,
|
| 300 |
preview_greenscreen,
|
| 301 |
quality, # <-- the new control
|
|
|
|
|
|
|
|
|
|
| 302 |
],
|
| 303 |
outputs=[out_video, statusbox],
|
| 304 |
)
|
|
@@ -343,4 +395,4 @@ def _run_with_quality(video_pth, bg_style_val, custom_bg_pth,
|
|
| 343 |
outputs=[custom_bg]
|
| 344 |
)
|
| 345 |
|
| 346 |
-
return demo
|
|
|
|
| 10 |
from __future__ import annotations
|
| 11 |
import os
|
| 12 |
import gradio as gr
|
| 13 |
+
import logging
|
| 14 |
|
| 15 |
from ui.callbacks import (
|
| 16 |
cb_load_models,
|
|
|
|
| 23 |
cb_preset_bg_preview,
|
| 24 |
)
|
| 25 |
|
| 26 |
+
logger = logging.getLogger(__name__)
|
| 27 |
+
|
| 28 |
# Typography & UI polish: sharper text + cleaner cards
|
| 29 |
CSS = """
|
| 30 |
:root {
|
|
|
|
| 87 |
GRADIENT_COLOR_CHOICES = ["warm_gradient", "tech_dark"]
|
| 88 |
|
| 89 |
|
| 90 |
+
def get_background_status(bg_method, bg_style, custom_bg_path=None, pro_image=None, gradient=None):
|
| 91 |
+
"""Get current background status text for display"""
|
| 92 |
+
if bg_method == "Upload file" and custom_bg_path:
|
| 93 |
+
filename = os.path.basename(custom_bg_path) if custom_bg_path else "none"
|
| 94 |
+
return f"Background: custom({filename})"
|
| 95 |
+
elif bg_method == "Pre-loaded professional images" and pro_image:
|
| 96 |
+
return f"Background: {pro_image}"
|
| 97 |
+
elif bg_method == "Pre-loaded Gradients / Colors" and gradient:
|
| 98 |
+
return f"Background: {gradient}"
|
| 99 |
+
elif bg_method == "AI generated background":
|
| 100 |
+
return f"Background: AI-generated"
|
| 101 |
+
elif bg_style:
|
| 102 |
+
return f"Background: {bg_style}"
|
| 103 |
+
else:
|
| 104 |
+
return "Background: none"
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def on_quality_change(quality_value):
|
| 108 |
+
"""Called when quality dropdown changes - sets environment variable"""
|
| 109 |
+
os.environ["BFX_QUALITY"] = quality_value.lower()
|
| 110 |
+
logger.info(f"UI: Quality preference set to {quality_value}")
|
| 111 |
+
return f"Quality mode: {quality_value} (refine_every={'1' if quality_value=='max' else '3' if quality_value=='balanced' else '10'} frames)"
|
| 112 |
+
|
| 113 |
+
|
| 114 |
def create_interface() -> gr.Blocks:
|
| 115 |
with gr.Blocks(
|
| 116 |
title="🎬 BackgroundFX Pro",
|
|
|
|
| 262 |
with gr.Column(scale=1):
|
| 263 |
out_video = gr.Video(label="Processed Output", interactive=False)
|
| 264 |
statusbox = gr.Textbox(label="Status", lines=8, elem_id="statusbox")
|
| 265 |
+
quality_status = gr.Textbox(label="Quality Settings", lines=1, value="Quality mode: balanced")
|
| 266 |
with gr.Row():
|
| 267 |
btn_refresh = gr.Button("🔍 Refresh Status", variant="secondary")
|
| 268 |
btn_clear = gr.Button("🧹 Clear", variant="secondary")
|
|
|
|
| 304 |
# Load models
|
| 305 |
btn_load.click(cb_load_models, outputs=statusbox)
|
| 306 |
|
| 307 |
+
# Quality dropdown handler - updates environment and status
|
| 308 |
+
quality.change(
|
| 309 |
+
on_quality_change,
|
| 310 |
+
inputs=[quality],
|
| 311 |
+
outputs=[quality_status]
|
| 312 |
+
)
|
| 313 |
+
|
| 314 |
# Tiny wrapper to set env for quality before calling the existing callback
|
| 315 |
def _run_with_quality(video_pth, bg_style_val, custom_bg_pth,
|
| 316 |
use_two_stage_state, chroma_p, key_mode,
|
| 317 |
+
prev_mask, prev_gs, quality_val, bg_method_val,
|
| 318 |
+
pro_image_val, gradient_val):
|
| 319 |
os.environ["BFX_QUALITY"] = (quality_val or "balanced")
|
| 320 |
+
|
| 321 |
+
# Update status with background info
|
| 322 |
+
bg_status = get_background_status(
|
| 323 |
+
bg_method_val, bg_style_val, custom_bg_pth,
|
| 324 |
+
pro_image_val, gradient_val
|
| 325 |
+
)
|
| 326 |
+
|
| 327 |
+
result = cb_process_video(
|
| 328 |
video_pth, bg_style_val, custom_bg_pth,
|
| 329 |
use_two_stage_state, chroma_p, key_mode, prev_mask, prev_gs
|
| 330 |
)
|
| 331 |
+
|
| 332 |
+
# Append background status to the result message
|
| 333 |
+
if isinstance(result, tuple) and len(result) >= 2:
|
| 334 |
+
video_out, msg = result[0], result[1]
|
| 335 |
+
return video_out, f"{msg}\n{bg_status}"
|
| 336 |
+
return result
|
| 337 |
|
| 338 |
# Always two-stage: pass use_two_stage=True to callback via State
|
| 339 |
btn_run.click(
|
|
|
|
| 348 |
preview_mask,
|
| 349 |
preview_greenscreen,
|
| 350 |
quality, # <-- the new control
|
| 351 |
+
bg_method, # Added for status
|
| 352 |
+
pro_image_dd, # Added for status
|
| 353 |
+
gradient_dd, # Added for status
|
| 354 |
],
|
| 355 |
outputs=[out_video, statusbox],
|
| 356 |
)
|
|
|
|
| 395 |
outputs=[custom_bg]
|
| 396 |
)
|
| 397 |
|
| 398 |
+
return demo
|