Update ui_components.py
Browse files- ui_components.py +126 -128
ui_components.py
CHANGED
|
@@ -1,9 +1,7 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
FIXED UI Components for Video Background Replacement
|
| 4 |
-
Updated
|
| 5 |
-
Now includes TWO-STAGE processing option
|
| 6 |
-
ENHANCED: Added debug logging and cancel functionality
|
| 7 |
"""
|
| 8 |
|
| 9 |
import gradio as gr
|
|
@@ -62,6 +60,7 @@ def add_debug_log(message):
|
|
| 62 |
if len(DEBUG_LOG) > MAX_DEBUG_LINES:
|
| 63 |
DEBUG_LOG = DEBUG_LOG[-MAX_DEBUG_LINES:]
|
| 64 |
logger.info(message)
|
|
|
|
| 65 |
return "\n".join(DEBUG_LOG)
|
| 66 |
|
| 67 |
def clear_debug_log():
|
|
@@ -77,24 +76,6 @@ def get_debug_log():
|
|
| 77 |
# ============================================================================ #
|
| 78 |
# UI HELPER FUNCTIONS
|
| 79 |
# ============================================================================ #
|
| 80 |
-
def generate_ai_background(prompt, style):
|
| 81 |
-
"""Generate AI background from prompt"""
|
| 82 |
-
if not prompt or not prompt.strip():
|
| 83 |
-
return None, "Please enter a prompt", get_debug_log()
|
| 84 |
-
try:
|
| 85 |
-
add_debug_log(f"Generating AI background: {prompt[:50]}...")
|
| 86 |
-
bg_image = create_procedural_background(prompt, style, 1920, 1080)
|
| 87 |
-
if bg_image is not None:
|
| 88 |
-
with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as tmp:
|
| 89 |
-
cv2.imwrite(tmp.name, bg_image)
|
| 90 |
-
add_debug_log(f"AI background saved to: {tmp.name}")
|
| 91 |
-
return tmp.name, f"Background generated: {prompt[:50]}...", get_debug_log()
|
| 92 |
-
return None, "Generation failed, try different prompt", get_debug_log()
|
| 93 |
-
except Exception as e:
|
| 94 |
-
error_msg = f"AI generation error: {str(e)}"
|
| 95 |
-
add_debug_log(error_msg)
|
| 96 |
-
return None, error_msg, get_debug_log()
|
| 97 |
-
|
| 98 |
def switch_background_method(method):
|
| 99 |
"""Switch between background method UI groups"""
|
| 100 |
add_debug_log(f"Switched to background method: {method}")
|
|
@@ -106,7 +87,7 @@ def switch_background_method(method):
|
|
| 106 |
)
|
| 107 |
|
| 108 |
def update_cache_status():
|
| 109 |
-
"""Update cache status display
|
| 110 |
try:
|
| 111 |
cache = get_cache_status()
|
| 112 |
two_stage_status = "✅ Available" if cache.get('two_stage_available', False) else "❌ Not available"
|
|
@@ -114,6 +95,11 @@ def update_cache_status():
|
|
| 114 |
except Exception as e:
|
| 115 |
return f"Status check error: {str(e)}"
|
| 116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
# ============================================================================ #
|
| 118 |
# PROGRESS WRAPPER
|
| 119 |
# ============================================================================ #
|
|
@@ -140,6 +126,15 @@ def process_video_enhanced_fixed(
|
|
| 140 |
add_debug_log("ERROR: No video file provided")
|
| 141 |
return None, "No video file provided.", get_debug_log()
|
| 142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
def progress_callback(pct, desc):
|
| 144 |
gradio_progress_wrapper(progress, pct, desc)
|
| 145 |
|
|
@@ -149,7 +144,8 @@ def progress_callback(pct, desc):
|
|
| 149 |
add_debug_log("Starting new video processing...")
|
| 150 |
add_debug_log(f"Video: {video_path}")
|
| 151 |
add_debug_log(f"Background method: {bg_method}")
|
| 152 |
-
add_debug_log(f"Two-stage mode: {use_two_stage}")
|
|
|
|
| 153 |
|
| 154 |
mode_msg = "TWO-STAGE Green Screen" if use_two_stage else "Single-Stage"
|
| 155 |
add_debug_log(f"Processing mode: {mode_msg}")
|
|
@@ -157,18 +153,24 @@ def progress_callback(pct, desc):
|
|
| 157 |
if bg_method == "upload":
|
| 158 |
if custom_img and os.path.exists(custom_img):
|
| 159 |
add_debug_log(f"Using uploaded image: {custom_img}")
|
| 160 |
-
result = process_video_fixed(
|
| 161 |
-
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
| 163 |
return result[0], result[1], get_debug_log()
|
| 164 |
return None, "No image uploaded. Please upload a background image.", get_debug_log()
|
| 165 |
|
| 166 |
elif bg_method == "professional":
|
| 167 |
if prof_choice and prof_choice in PROFESSIONAL_BACKGROUNDS:
|
| 168 |
add_debug_log(f"Using professional background: {prof_choice}")
|
| 169 |
-
result = process_video_fixed(
|
| 170 |
-
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
| 172 |
return result[0], result[1], get_debug_log()
|
| 173 |
return None, f"Invalid professional background: {prof_choice}", get_debug_log()
|
| 174 |
|
|
@@ -190,9 +192,12 @@ def progress_callback(pct, desc):
|
|
| 190 |
cv2.imwrite(temp_path, gradient_bg)
|
| 191 |
add_debug_log(f"Gradient saved to: {temp_path}")
|
| 192 |
|
| 193 |
-
result = process_video_fixed(
|
| 194 |
-
|
| 195 |
-
|
|
|
|
|
|
|
|
|
|
| 196 |
return result[0], result[1], get_debug_log()
|
| 197 |
except Exception as e:
|
| 198 |
error_msg = f"Error creating gradient: {str(e)}"
|
|
@@ -202,9 +207,12 @@ def progress_callback(pct, desc):
|
|
| 202 |
elif bg_method == "ai":
|
| 203 |
if ai_img and os.path.exists(ai_img):
|
| 204 |
add_debug_log(f"Using AI generated image: {ai_img}")
|
| 205 |
-
result = process_video_fixed(
|
| 206 |
-
|
| 207 |
-
|
|
|
|
|
|
|
|
|
|
| 208 |
return result[0], result[1], get_debug_log()
|
| 209 |
return None, "No AI background generated. Click 'Generate Background' first.", get_debug_log()
|
| 210 |
|
|
@@ -233,7 +241,7 @@ def create_interface():
|
|
| 233 |
"""Create the complete Gradio interface with debug capabilities"""
|
| 234 |
|
| 235 |
with gr.Blocks(
|
| 236 |
-
title="
|
| 237 |
theme=gr.themes.Soft(),
|
| 238 |
css="""
|
| 239 |
.gradio-container { max-width: 1200px !important; }
|
|
@@ -246,6 +254,8 @@ def create_interface():
|
|
| 246 |
font-size: 12px;
|
| 247 |
padding: 10px;
|
| 248 |
border-radius: 4px;
|
|
|
|
|
|
|
| 249 |
}
|
| 250 |
.two-stage-box {
|
| 251 |
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
@@ -256,15 +266,15 @@ def create_interface():
|
|
| 256 |
}
|
| 257 |
"""
|
| 258 |
) as demo:
|
| 259 |
-
gr.Markdown("#
|
| 260 |
-
gr.Markdown("
|
| 261 |
|
| 262 |
-
# Two-stage mode banner
|
| 263 |
if TWO_STAGE_AVAILABLE:
|
| 264 |
gr.HTML("""
|
| 265 |
<div class="two-stage-box">
|
| 266 |
-
<strong>🎬
|
| 267 |
-
|
| 268 |
</div>
|
| 269 |
""")
|
| 270 |
|
|
@@ -272,36 +282,36 @@ def create_interface():
|
|
| 272 |
|
| 273 |
with gr.Row():
|
| 274 |
with gr.Column(scale=1):
|
| 275 |
-
gr.Markdown("### Step 1: Upload Your Video")
|
| 276 |
-
gr.Markdown("*Supports MP4, MOV, AVI, and other common formats*")
|
| 277 |
video_input = gr.Video(label="Drop your video here", height=300)
|
| 278 |
|
| 279 |
-
gr.Markdown("### Step 2: Choose Background
|
| 280 |
-
gr.Markdown("*Select your preferred background creation method*")
|
| 281 |
background_method = gr.Radio(
|
| 282 |
choices=["upload", "professional", "colors", "ai"],
|
| 283 |
value="professional",
|
| 284 |
-
label="Background Method"
|
|
|
|
| 285 |
)
|
| 286 |
|
|
|
|
| 287 |
with gr.Group(visible=False) as upload_group:
|
| 288 |
-
gr.Markdown("**Upload
|
| 289 |
-
custom_background = gr.Image(label="
|
| 290 |
|
| 291 |
with gr.Group(visible=True) as professional_group:
|
| 292 |
-
gr.Markdown("**Professional
|
| 293 |
professional_choice = gr.Dropdown(
|
| 294 |
choices=list(PROFESSIONAL_BACKGROUNDS.keys()),
|
| 295 |
value="office_modern",
|
| 296 |
-
label="Select
|
| 297 |
)
|
| 298 |
|
| 299 |
with gr.Group(visible=False) as colors_group:
|
| 300 |
-
gr.Markdown("**Custom
|
| 301 |
gradient_type = gr.Dropdown(
|
| 302 |
-
choices=["solid", "vertical", "horizontal", "diagonal", "radial"
|
| 303 |
value="vertical",
|
| 304 |
-
label="
|
| 305 |
)
|
| 306 |
with gr.Row():
|
| 307 |
color1 = gr.ColorPicker(label="Color 1", value="#3498db")
|
|
@@ -311,127 +321,118 @@ def create_interface():
|
|
| 311 |
use_third_color = gr.Checkbox(label="Use 3rd color", value=False)
|
| 312 |
|
| 313 |
with gr.Group(visible=False) as ai_group:
|
| 314 |
-
gr.Markdown("**AI Generated
|
| 315 |
ai_prompt = gr.Textbox(
|
| 316 |
-
label="Describe
|
| 317 |
-
placeholder="e.g., 'modern office with plants'
|
| 318 |
lines=2
|
| 319 |
)
|
| 320 |
ai_style = gr.Dropdown(
|
| 321 |
-
choices=["photorealistic", "artistic", "abstract"
|
| 322 |
value="photorealistic",
|
| 323 |
label="Style"
|
| 324 |
)
|
| 325 |
with gr.Row():
|
| 326 |
-
generate_ai_btn = gr.Button("Generate
|
| 327 |
-
ai_generated_image = gr.Image(label="Generated
|
| 328 |
|
| 329 |
-
# Wire up background
|
| 330 |
background_method.change(
|
| 331 |
fn=switch_background_method,
|
| 332 |
inputs=background_method,
|
| 333 |
outputs=[upload_group, professional_group, colors_group, ai_group]
|
| 334 |
)
|
| 335 |
|
| 336 |
-
gr.Markdown("### Processing Options")
|
| 337 |
|
| 338 |
-
# Two-stage processing
|
| 339 |
-
with gr.Accordion("
|
| 340 |
use_two_stage = gr.Checkbox(
|
| 341 |
-
label="Enable Two-Stage Green Screen
|
| 342 |
value=False,
|
| 343 |
-
info="
|
| 344 |
)
|
|
|
|
| 345 |
chroma_preset = gr.Dropdown(
|
| 346 |
choices=list(CHROMA_PRESETS.keys()) if TWO_STAGE_AVAILABLE else ["standard"],
|
| 347 |
value="standard",
|
| 348 |
-
label="
|
| 349 |
-
info="
|
| 350 |
visible=False
|
| 351 |
)
|
| 352 |
|
|
|
|
| 353 |
use_two_stage.change(
|
| 354 |
-
fn=
|
| 355 |
inputs=use_two_stage,
|
| 356 |
outputs=chroma_preset
|
| 357 |
)
|
| 358 |
|
| 359 |
-
gr.Markdown("###
|
| 360 |
with gr.Row():
|
| 361 |
-
load_models_btn = gr.Button("
|
| 362 |
-
process_btn = gr.Button("
|
| 363 |
-
cancel_btn = gr.Button("Cancel", variant="stop")
|
| 364 |
|
| 365 |
status_text = gr.Textbox(
|
| 366 |
-
label="
|
| 367 |
-
value="Ready -
|
| 368 |
-
interactive=False,
|
| 369 |
-
lines=3,
|
| 370 |
-
elem_classes=["status-box"]
|
| 371 |
-
)
|
| 372 |
-
|
| 373 |
-
validation_status = gr.Textbox(
|
| 374 |
-
label="Processing Mode",
|
| 375 |
-
value=update_cache_status(),
|
| 376 |
interactive=False,
|
| 377 |
-
lines=
|
| 378 |
-
elem_classes=["status-box"]
|
| 379 |
)
|
| 380 |
|
| 381 |
with gr.Column(scale=1):
|
| 382 |
-
gr.Markdown("###
|
| 383 |
-
video_output = gr.Video(label="
|
|
|
|
| 384 |
result_text = gr.Textbox(
|
| 385 |
-
label="Processing
|
| 386 |
interactive=False,
|
| 387 |
-
lines=
|
| 388 |
-
placeholder="
|
| 389 |
-
elem_classes=["status-box"]
|
| 390 |
)
|
| 391 |
|
| 392 |
-
# Debug panel
|
| 393 |
-
with gr.Accordion("🔧 Debug Log", open=
|
| 394 |
debug_output = gr.Textbox(
|
| 395 |
label="Debug Output",
|
| 396 |
value=get_debug_log(),
|
| 397 |
-
lines=
|
| 398 |
max_lines=20,
|
| 399 |
interactive=False,
|
| 400 |
elem_classes=["debug-box"]
|
| 401 |
)
|
| 402 |
with gr.Row():
|
| 403 |
-
refresh_debug_btn = gr.Button("Refresh
|
| 404 |
-
clear_debug_btn = gr.Button("Clear
|
| 405 |
|
| 406 |
# Event handlers
|
| 407 |
-
|
| 408 |
fn=load_models_with_progress_fixed,
|
| 409 |
outputs=[status_text, debug_output]
|
| 410 |
)
|
| 411 |
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
inputs=[ai_prompt, ai_style],
|
| 415 |
-
outputs=[ai_generated_image, status_text, debug_output]
|
| 416 |
-
)
|
| 417 |
-
|
| 418 |
-
# Process with cancel capability
|
| 419 |
-
process_event = process_btn.click(
|
| 420 |
fn=process_video_enhanced_fixed,
|
| 421 |
-
inputs=[
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
outputs=[video_output, result_text, debug_output]
|
| 426 |
)
|
| 427 |
|
| 428 |
-
# Cancel button
|
| 429 |
-
cancel_btn.click(
|
| 430 |
-
fn=lambda: (add_debug_log("Processing cancelled by user"), "Processing cancelled")[1],
|
| 431 |
-
outputs=[status_text],
|
| 432 |
-
cancels=[process_event, load_event]
|
| 433 |
-
)
|
| 434 |
-
|
| 435 |
# Debug controls
|
| 436 |
refresh_debug_btn.click(
|
| 437 |
fn=get_debug_log,
|
|
@@ -443,20 +444,17 @@ def create_interface():
|
|
| 443 |
outputs=[debug_output]
|
| 444 |
)
|
| 445 |
|
| 446 |
-
#
|
| 447 |
-
|
| 448 |
-
fn=update_cache_status,
|
| 449 |
-
outputs=[validation_status]
|
| 450 |
-
)
|
| 451 |
-
|
| 452 |
-
with gr.Accordion("Quality & Features", open=False):
|
| 453 |
gr.Markdown("""
|
| 454 |
-
###
|
| 455 |
-
- Single-Stage
|
| 456 |
-
- Two-Stage
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
-
|
|
|
|
|
|
|
| 460 |
""")
|
| 461 |
|
| 462 |
return demo
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
FIXED UI Components for Video Background Replacement
|
| 4 |
+
Updated with enhanced debug logging for two-stage checkbox issue
|
|
|
|
|
|
|
| 5 |
"""
|
| 6 |
|
| 7 |
import gradio as gr
|
|
|
|
| 60 |
if len(DEBUG_LOG) > MAX_DEBUG_LINES:
|
| 61 |
DEBUG_LOG = DEBUG_LOG[-MAX_DEBUG_LINES:]
|
| 62 |
logger.info(message)
|
| 63 |
+
print(f"DEBUG: {log_entry}") # Also print to console
|
| 64 |
return "\n".join(DEBUG_LOG)
|
| 65 |
|
| 66 |
def clear_debug_log():
|
|
|
|
| 76 |
# ============================================================================ #
|
| 77 |
# UI HELPER FUNCTIONS
|
| 78 |
# ============================================================================ #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
def switch_background_method(method):
|
| 80 |
"""Switch between background method UI groups"""
|
| 81 |
add_debug_log(f"Switched to background method: {method}")
|
|
|
|
| 87 |
)
|
| 88 |
|
| 89 |
def update_cache_status():
|
| 90 |
+
"""Update cache status display"""
|
| 91 |
try:
|
| 92 |
cache = get_cache_status()
|
| 93 |
two_stage_status = "✅ Available" if cache.get('two_stage_available', False) else "❌ Not available"
|
|
|
|
| 95 |
except Exception as e:
|
| 96 |
return f"Status check error: {str(e)}"
|
| 97 |
|
| 98 |
+
def on_two_stage_change(value):
|
| 99 |
+
"""Debug handler for two-stage checkbox changes"""
|
| 100 |
+
add_debug_log(f"Two-stage checkbox changed to: {value} (type: {type(value)})")
|
| 101 |
+
return gr.update(visible=value)
|
| 102 |
+
|
| 103 |
# ============================================================================ #
|
| 104 |
# PROGRESS WRAPPER
|
| 105 |
# ============================================================================ #
|
|
|
|
| 126 |
add_debug_log("ERROR: No video file provided")
|
| 127 |
return None, "No video file provided.", get_debug_log()
|
| 128 |
|
| 129 |
+
# CRITICAL DEBUG: Log exact checkbox value received
|
| 130 |
+
add_debug_log(f"CHECKBOX RAW VALUE: use_two_stage = {use_two_stage}")
|
| 131 |
+
add_debug_log(f"CHECKBOX TYPE: {type(use_two_stage)}")
|
| 132 |
+
add_debug_log(f"CHECKBOX BOOL CONVERSION: {bool(use_two_stage)}")
|
| 133 |
+
|
| 134 |
+
# Force boolean conversion to be safe
|
| 135 |
+
use_two_stage = bool(use_two_stage)
|
| 136 |
+
add_debug_log(f"FINAL use_two_stage value: {use_two_stage}")
|
| 137 |
+
|
| 138 |
def progress_callback(pct, desc):
|
| 139 |
gradio_progress_wrapper(progress, pct, desc)
|
| 140 |
|
|
|
|
| 144 |
add_debug_log("Starting new video processing...")
|
| 145 |
add_debug_log(f"Video: {video_path}")
|
| 146 |
add_debug_log(f"Background method: {bg_method}")
|
| 147 |
+
add_debug_log(f"Two-stage mode requested: {use_two_stage}")
|
| 148 |
+
add_debug_log(f"Chroma preset: {chroma_preset}")
|
| 149 |
|
| 150 |
mode_msg = "TWO-STAGE Green Screen" if use_two_stage else "Single-Stage"
|
| 151 |
add_debug_log(f"Processing mode: {mode_msg}")
|
|
|
|
| 153 |
if bg_method == "upload":
|
| 154 |
if custom_img and os.path.exists(custom_img):
|
| 155 |
add_debug_log(f"Using uploaded image: {custom_img}")
|
| 156 |
+
result = process_video_fixed(
|
| 157 |
+
video_path, "custom", custom_img,
|
| 158 |
+
progress_callback,
|
| 159 |
+
use_two_stage=use_two_stage,
|
| 160 |
+
chroma_preset=chroma_preset
|
| 161 |
+
)
|
| 162 |
return result[0], result[1], get_debug_log()
|
| 163 |
return None, "No image uploaded. Please upload a background image.", get_debug_log()
|
| 164 |
|
| 165 |
elif bg_method == "professional":
|
| 166 |
if prof_choice and prof_choice in PROFESSIONAL_BACKGROUNDS:
|
| 167 |
add_debug_log(f"Using professional background: {prof_choice}")
|
| 168 |
+
result = process_video_fixed(
|
| 169 |
+
video_path, prof_choice, None,
|
| 170 |
+
progress_callback,
|
| 171 |
+
use_two_stage=use_two_stage,
|
| 172 |
+
chroma_preset=chroma_preset
|
| 173 |
+
)
|
| 174 |
return result[0], result[1], get_debug_log()
|
| 175 |
return None, f"Invalid professional background: {prof_choice}", get_debug_log()
|
| 176 |
|
|
|
|
| 192 |
cv2.imwrite(temp_path, gradient_bg)
|
| 193 |
add_debug_log(f"Gradient saved to: {temp_path}")
|
| 194 |
|
| 195 |
+
result = process_video_fixed(
|
| 196 |
+
video_path, "custom", temp_path,
|
| 197 |
+
progress_callback,
|
| 198 |
+
use_two_stage=use_two_stage,
|
| 199 |
+
chroma_preset=chroma_preset
|
| 200 |
+
)
|
| 201 |
return result[0], result[1], get_debug_log()
|
| 202 |
except Exception as e:
|
| 203 |
error_msg = f"Error creating gradient: {str(e)}"
|
|
|
|
| 207 |
elif bg_method == "ai":
|
| 208 |
if ai_img and os.path.exists(ai_img):
|
| 209 |
add_debug_log(f"Using AI generated image: {ai_img}")
|
| 210 |
+
result = process_video_fixed(
|
| 211 |
+
video_path, "custom", ai_img,
|
| 212 |
+
progress_callback,
|
| 213 |
+
use_two_stage=use_two_stage,
|
| 214 |
+
chroma_preset=chroma_preset
|
| 215 |
+
)
|
| 216 |
return result[0], result[1], get_debug_log()
|
| 217 |
return None, "No AI background generated. Click 'Generate Background' first.", get_debug_log()
|
| 218 |
|
|
|
|
| 241 |
"""Create the complete Gradio interface with debug capabilities"""
|
| 242 |
|
| 243 |
with gr.Blocks(
|
| 244 |
+
title="Video Background Replacement",
|
| 245 |
theme=gr.themes.Soft(),
|
| 246 |
css="""
|
| 247 |
.gradio-container { max-width: 1200px !important; }
|
|
|
|
| 254 |
font-size: 12px;
|
| 255 |
padding: 10px;
|
| 256 |
border-radius: 4px;
|
| 257 |
+
max-height: 400px;
|
| 258 |
+
overflow-y: auto;
|
| 259 |
}
|
| 260 |
.two-stage-box {
|
| 261 |
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
|
|
| 266 |
}
|
| 267 |
"""
|
| 268 |
) as demo:
|
| 269 |
+
gr.Markdown("# 🎬 Video Background Replacement")
|
| 270 |
+
gr.Markdown("Professional quality background replacement using AI segmentation")
|
| 271 |
|
| 272 |
+
# Two-stage mode banner
|
| 273 |
if TWO_STAGE_AVAILABLE:
|
| 274 |
gr.HTML("""
|
| 275 |
<div class="two-stage-box">
|
| 276 |
+
<strong>🎬 Two-Stage Green Screen Mode Available!</strong><br>
|
| 277 |
+
Cinema-grade processing with chroma key for perfect edges
|
| 278 |
</div>
|
| 279 |
""")
|
| 280 |
|
|
|
|
| 282 |
|
| 283 |
with gr.Row():
|
| 284 |
with gr.Column(scale=1):
|
| 285 |
+
gr.Markdown("### 📹 Step 1: Upload Your Video")
|
|
|
|
| 286 |
video_input = gr.Video(label="Drop your video here", height=300)
|
| 287 |
|
| 288 |
+
gr.Markdown("### 🎨 Step 2: Choose Background")
|
|
|
|
| 289 |
background_method = gr.Radio(
|
| 290 |
choices=["upload", "professional", "colors", "ai"],
|
| 291 |
value="professional",
|
| 292 |
+
label="Background Method",
|
| 293 |
+
info="Select how you want to create your background"
|
| 294 |
)
|
| 295 |
|
| 296 |
+
# Background method groups
|
| 297 |
with gr.Group(visible=False) as upload_group:
|
| 298 |
+
gr.Markdown("**Upload Custom Background**")
|
| 299 |
+
custom_background = gr.Image(label="Upload image", type="filepath")
|
| 300 |
|
| 301 |
with gr.Group(visible=True) as professional_group:
|
| 302 |
+
gr.Markdown("**Professional Presets**")
|
| 303 |
professional_choice = gr.Dropdown(
|
| 304 |
choices=list(PROFESSIONAL_BACKGROUNDS.keys()),
|
| 305 |
value="office_modern",
|
| 306 |
+
label="Select Background"
|
| 307 |
)
|
| 308 |
|
| 309 |
with gr.Group(visible=False) as colors_group:
|
| 310 |
+
gr.Markdown("**Custom Gradient**")
|
| 311 |
gradient_type = gr.Dropdown(
|
| 312 |
+
choices=["solid", "vertical", "horizontal", "diagonal", "radial"],
|
| 313 |
value="vertical",
|
| 314 |
+
label="Type"
|
| 315 |
)
|
| 316 |
with gr.Row():
|
| 317 |
color1 = gr.ColorPicker(label="Color 1", value="#3498db")
|
|
|
|
| 321 |
use_third_color = gr.Checkbox(label="Use 3rd color", value=False)
|
| 322 |
|
| 323 |
with gr.Group(visible=False) as ai_group:
|
| 324 |
+
gr.Markdown("**AI Generated (Experimental)**")
|
| 325 |
ai_prompt = gr.Textbox(
|
| 326 |
+
label="Describe background",
|
| 327 |
+
placeholder="e.g., 'modern office with plants'",
|
| 328 |
lines=2
|
| 329 |
)
|
| 330 |
ai_style = gr.Dropdown(
|
| 331 |
+
choices=["photorealistic", "artistic", "abstract"],
|
| 332 |
value="photorealistic",
|
| 333 |
label="Style"
|
| 334 |
)
|
| 335 |
with gr.Row():
|
| 336 |
+
generate_ai_btn = gr.Button("Generate", variant="secondary")
|
| 337 |
+
ai_generated_image = gr.Image(label="Generated", type="filepath", visible=False)
|
| 338 |
|
| 339 |
+
# Wire up background switching
|
| 340 |
background_method.change(
|
| 341 |
fn=switch_background_method,
|
| 342 |
inputs=background_method,
|
| 343 |
outputs=[upload_group, professional_group, colors_group, ai_group]
|
| 344 |
)
|
| 345 |
|
| 346 |
+
gr.Markdown("### ⚙️ Processing Options")
|
| 347 |
|
| 348 |
+
# Two-stage processing
|
| 349 |
+
with gr.Accordion("Advanced Settings", open=True):
|
| 350 |
use_two_stage = gr.Checkbox(
|
| 351 |
+
label="Enable Two-Stage Processing (Green Screen)",
|
| 352 |
value=False,
|
| 353 |
+
info="Better quality but slower - creates green screen intermediate"
|
| 354 |
)
|
| 355 |
+
|
| 356 |
chroma_preset = gr.Dropdown(
|
| 357 |
choices=list(CHROMA_PRESETS.keys()) if TWO_STAGE_AVAILABLE else ["standard"],
|
| 358 |
value="standard",
|
| 359 |
+
label="Edge Quality",
|
| 360 |
+
info="Standard=balanced, Tight=sharp edges, Soft=smooth blend",
|
| 361 |
visible=False
|
| 362 |
)
|
| 363 |
|
| 364 |
+
# Debug checkbox changes
|
| 365 |
use_two_stage.change(
|
| 366 |
+
fn=on_two_stage_change,
|
| 367 |
inputs=use_two_stage,
|
| 368 |
outputs=chroma_preset
|
| 369 |
)
|
| 370 |
|
| 371 |
+
gr.Markdown("### 🚀 Process Video")
|
| 372 |
with gr.Row():
|
| 373 |
+
load_models_btn = gr.Button("Load Models", variant="secondary")
|
| 374 |
+
process_btn = gr.Button("Process Video", variant="primary", scale=2)
|
|
|
|
| 375 |
|
| 376 |
status_text = gr.Textbox(
|
| 377 |
+
label="Status",
|
| 378 |
+
value="Ready - Click 'Load Models' first",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 379 |
interactive=False,
|
| 380 |
+
lines=2
|
|
|
|
| 381 |
)
|
| 382 |
|
| 383 |
with gr.Column(scale=1):
|
| 384 |
+
gr.Markdown("### 🎥 Result")
|
| 385 |
+
video_output = gr.Video(label="Processed Video", height=400)
|
| 386 |
+
|
| 387 |
result_text = gr.Textbox(
|
| 388 |
+
label="Processing Info",
|
| 389 |
interactive=False,
|
| 390 |
+
lines=6,
|
| 391 |
+
placeholder="Results will appear here..."
|
|
|
|
| 392 |
)
|
| 393 |
|
| 394 |
+
# Debug panel - OPEN by default for testing
|
| 395 |
+
with gr.Accordion("🔧 Debug Log", open=True):
|
| 396 |
debug_output = gr.Textbox(
|
| 397 |
label="Debug Output",
|
| 398 |
value=get_debug_log(),
|
| 399 |
+
lines=12,
|
| 400 |
max_lines=20,
|
| 401 |
interactive=False,
|
| 402 |
elem_classes=["debug-box"]
|
| 403 |
)
|
| 404 |
with gr.Row():
|
| 405 |
+
refresh_debug_btn = gr.Button("Refresh", size="sm")
|
| 406 |
+
clear_debug_btn = gr.Button("Clear", size="sm")
|
| 407 |
|
| 408 |
# Event handlers
|
| 409 |
+
load_models_btn.click(
|
| 410 |
fn=load_models_with_progress_fixed,
|
| 411 |
outputs=[status_text, debug_output]
|
| 412 |
)
|
| 413 |
|
| 414 |
+
# Main processing - ensure all inputs are connected
|
| 415 |
+
process_btn.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 416 |
fn=process_video_enhanced_fixed,
|
| 417 |
+
inputs=[
|
| 418 |
+
video_input, # video_path
|
| 419 |
+
background_method, # bg_method
|
| 420 |
+
custom_background, # custom_img
|
| 421 |
+
professional_choice, # prof_choice
|
| 422 |
+
gradient_type, # grad_type
|
| 423 |
+
color1, # color1
|
| 424 |
+
color2, # color2
|
| 425 |
+
color3, # color3
|
| 426 |
+
use_third_color, # use_third
|
| 427 |
+
ai_prompt, # ai_prompt
|
| 428 |
+
ai_style, # ai_style
|
| 429 |
+
ai_generated_image, # ai_img
|
| 430 |
+
use_two_stage, # use_two_stage - THIS IS THE KEY INPUT
|
| 431 |
+
chroma_preset # chroma_preset
|
| 432 |
+
],
|
| 433 |
outputs=[video_output, result_text, debug_output]
|
| 434 |
)
|
| 435 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 436 |
# Debug controls
|
| 437 |
refresh_debug_btn.click(
|
| 438 |
fn=get_debug_log,
|
|
|
|
| 444 |
outputs=[debug_output]
|
| 445 |
)
|
| 446 |
|
| 447 |
+
# Info section
|
| 448 |
+
with gr.Accordion("ℹ️ Information", open=False):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 449 |
gr.Markdown("""
|
| 450 |
+
### Processing Modes:
|
| 451 |
+
- **Single-Stage**: Fast, good quality for most videos
|
| 452 |
+
- **Two-Stage**: Slower but cinema-quality edges using green screen
|
| 453 |
+
|
| 454 |
+
### Tips:
|
| 455 |
+
- Start with 720p videos for testing
|
| 456 |
+
- Two-stage mode works best with clear subjects
|
| 457 |
+
- Processing takes 2-4 minutes for 1-minute videos
|
| 458 |
""")
|
| 459 |
|
| 460 |
return demo
|