Update ui_components.py
Browse files- ui_components.py +48 -52
ui_components.py
CHANGED
|
@@ -153,17 +153,17 @@ def progress_callback(pct, desc):
|
|
| 153 |
# Enhanced success message
|
| 154 |
avg_time = ui_state.get_average_processing_time()
|
| 155 |
success_info = f"""
|
| 156 |
-
|
| 157 |
|
| 158 |
-
|
| 159 |
{result_message}
|
| 160 |
|
| 161 |
-
|
| 162 |
- Average processing time: {avg_time:.1f}s
|
| 163 |
- Two-stage mode: {'Enabled' if use_two_stage else 'Disabled'}
|
| 164 |
- Quality preset: {quality_preset or 'Default'}
|
| 165 |
|
| 166 |
-
|
| 167 |
- Try two-stage mode for better quality
|
| 168 |
- Use 'fast' preset for quicker processing
|
| 169 |
- Shorter videos process faster
|
|
@@ -196,17 +196,17 @@ def progress_callback(pct, desc):
|
|
| 196 |
if "SUCCESS" in result or "successful" in result.lower():
|
| 197 |
ui_state.models_loaded = True
|
| 198 |
enhanced_result = f"""
|
| 199 |
-
|
| 200 |
|
| 201 |
-
|
| 202 |
{result}
|
| 203 |
|
| 204 |
-
|
| 205 |
- High-quality segmentation (SAM2)
|
| 206 |
- Professional mask refinement (MatAnyone)
|
| 207 |
- {'Two-stage green screen mode available' if TWO_STAGE_AVAILABLE else 'Single-stage processing only'}
|
| 208 |
|
| 209 |
-
|
| 210 |
1. Upload your video
|
| 211 |
2. Choose background method
|
| 212 |
3. Click 'Process Video'
|
|
@@ -227,11 +227,11 @@ def get_enhanced_model_status():
|
|
| 227 |
status = get_model_status()
|
| 228 |
if isinstance(status, dict):
|
| 229 |
formatted_status = {
|
| 230 |
-
"SAM2 Segmentation": "
|
| 231 |
-
"MatAnyone Refinement": "
|
| 232 |
-
"Two-Stage Mode": "
|
| 233 |
"Device": status.get('device', 'Unknown'),
|
| 234 |
-
"Models Validated": "
|
| 235 |
}
|
| 236 |
if 'memory_usage' in status and status['memory_usage']:
|
| 237 |
memory = status['memory_usage']
|
|
@@ -249,7 +249,7 @@ def get_enhanced_cache_status():
|
|
| 249 |
status = get_cache_status()
|
| 250 |
if isinstance(status, dict):
|
| 251 |
return {
|
| 252 |
-
"Cache Status": "
|
| 253 |
"Processing Mode": "Two-Stage" if status.get('two_stage_available') else "Single-Stage",
|
| 254 |
"Configuration": status.get('config', {}),
|
| 255 |
"System Device": status.get('device', 'Unknown')
|
|
@@ -279,7 +279,7 @@ def get_enhanced_cache_status():
|
|
| 279 |
# Header
|
| 280 |
with gr.Row():
|
| 281 |
gr.Markdown("""
|
| 282 |
-
#
|
| 283 |
|
| 284 |
Professional-quality video background replacement using AI segmentation and advanced compositing techniques.
|
| 285 |
""", elem_classes=["main-header"])
|
|
@@ -289,11 +289,11 @@ def get_enhanced_cache_status():
|
|
| 289 |
with gr.Column(scale=1):
|
| 290 |
system_status = gr.HTML(f"""
|
| 291 |
<div class="status-box">
|
| 292 |
-
<h4
|
| 293 |
<ul>
|
| 294 |
-
<li>Core Functions: {'
|
| 295 |
-
<li>Utilities: {'
|
| 296 |
-
<li>Two-Stage Mode: {'
|
| 297 |
</ul>
|
| 298 |
</div>
|
| 299 |
""")
|
|
@@ -301,13 +301,13 @@ def get_enhanced_cache_status():
|
|
| 301 |
with gr.Row():
|
| 302 |
# Left column - Input and controls
|
| 303 |
with gr.Column(scale=1):
|
| 304 |
-
gr.Markdown("###
|
| 305 |
video_input = gr.Video(
|
| 306 |
label="Upload your video (MP4, AVI, MOV supported)",
|
| 307 |
height=300
|
| 308 |
)
|
| 309 |
|
| 310 |
-
with gr.Accordion("
|
| 311 |
gr.Markdown("""
|
| 312 |
**Supported Formats:** MP4, AVI, MOV, MKV
|
| 313 |
**Max Duration:** 5 minutes (300 seconds)
|
|
@@ -320,12 +320,11 @@ def get_enhanced_cache_status():
|
|
| 320 |
- Ensure good lighting and clear person visibility
|
| 321 |
""")
|
| 322 |
|
| 323 |
-
gr.Markdown("###
|
| 324 |
background_method = gr.Radio(
|
| 325 |
choices=["professional", "upload"],
|
| 326 |
value="professional",
|
| 327 |
-
label="Background Method"
|
| 328 |
-
info="Professional presets or upload your own image"
|
| 329 |
)
|
| 330 |
|
| 331 |
# Professional backgrounds
|
|
@@ -343,18 +342,17 @@ def get_enhanced_cache_status():
|
|
| 343 |
professional_choice = gr.Dropdown(
|
| 344 |
choices=choices,
|
| 345 |
value=default_choice,
|
| 346 |
-
label="Select Professional Background"
|
| 347 |
-
info="Each preset is optimized for different use cases"
|
| 348 |
)
|
| 349 |
|
| 350 |
-
# Custom upload
|
| 351 |
with gr.Group(visible=False) as upload_group:
|
| 352 |
gr.Markdown("**Upload Custom Background**")
|
| 353 |
custom_background = gr.Image(
|
| 354 |
label="Upload background image",
|
| 355 |
-
type="filepath"
|
| 356 |
-
info="JPG, PNG supported. Will be resized to match video resolution."
|
| 357 |
)
|
|
|
|
| 358 |
|
| 359 |
# Background method visibility control
|
| 360 |
def update_background_visibility(method):
|
|
@@ -369,7 +367,7 @@ def update_background_visibility(method):
|
|
| 369 |
outputs=[professional_group, upload_group]
|
| 370 |
)
|
| 371 |
|
| 372 |
-
gr.Markdown("###
|
| 373 |
|
| 374 |
with gr.Row():
|
| 375 |
quality_preset = gr.Dropdown(
|
|
@@ -379,17 +377,16 @@ def update_background_visibility(method):
|
|
| 379 |
("High - Best quality", "high")
|
| 380 |
],
|
| 381 |
value="balanced",
|
| 382 |
-
label="Quality Preset"
|
| 383 |
-
info="Higher quality takes longer but produces better results"
|
| 384 |
)
|
| 385 |
|
| 386 |
-
with gr.Accordion("
|
| 387 |
use_two_stage = gr.Checkbox(
|
| 388 |
label="Enable Two-Stage Processing",
|
| 389 |
value=False,
|
| 390 |
-
info="Cinema-quality green screen mode (slower but much better quality)",
|
| 391 |
interactive=TWO_STAGE_AVAILABLE
|
| 392 |
)
|
|
|
|
| 393 |
|
| 394 |
if TWO_STAGE_AVAILABLE:
|
| 395 |
chroma_preset = gr.Dropdown(
|
|
@@ -399,8 +396,7 @@ def update_background_visibility(method):
|
|
| 399 |
("Outdoor - Challenging lighting", "outdoor")
|
| 400 |
],
|
| 401 |
value="standard",
|
| 402 |
-
label="Chroma Key Preset"
|
| 403 |
-
info="Only used in two-stage mode"
|
| 404 |
)
|
| 405 |
else:
|
| 406 |
chroma_preset = gr.Dropdown(
|
|
@@ -410,16 +406,16 @@ def update_background_visibility(method):
|
|
| 410 |
interactive=False
|
| 411 |
)
|
| 412 |
|
| 413 |
-
gr.Markdown("###
|
| 414 |
|
| 415 |
with gr.Row():
|
| 416 |
load_models_btn = gr.Button(
|
| 417 |
-
"
|
| 418 |
variant="secondary",
|
| 419 |
size="lg"
|
| 420 |
)
|
| 421 |
process_btn = gr.Button(
|
| 422 |
-
"
|
| 423 |
variant="primary",
|
| 424 |
size="lg",
|
| 425 |
scale=2
|
|
@@ -427,7 +423,7 @@ def update_background_visibility(method):
|
|
| 427 |
|
| 428 |
# Status and feedback
|
| 429 |
status_text = gr.Textbox(
|
| 430 |
-
label="
|
| 431 |
value="Ready - Click 'Load Models' to begin",
|
| 432 |
interactive=False,
|
| 433 |
lines=6,
|
|
@@ -435,7 +431,7 @@ def update_background_visibility(method):
|
|
| 435 |
)
|
| 436 |
|
| 437 |
# System monitoring
|
| 438 |
-
with gr.Accordion("
|
| 439 |
with gr.Row():
|
| 440 |
model_status_btn = gr.Button("Check Models", variant="secondary")
|
| 441 |
cache_status_btn = gr.Button("Check Cache", variant="secondary")
|
|
@@ -445,7 +441,7 @@ def update_background_visibility(method):
|
|
| 445 |
|
| 446 |
# Right column - Output and results
|
| 447 |
with gr.Column(scale=1):
|
| 448 |
-
gr.Markdown("###
|
| 449 |
|
| 450 |
video_output = gr.Video(
|
| 451 |
label="Processed Video",
|
|
@@ -453,7 +449,7 @@ def update_background_visibility(method):
|
|
| 453 |
)
|
| 454 |
|
| 455 |
result_info = gr.Textbox(
|
| 456 |
-
label="
|
| 457 |
interactive=False,
|
| 458 |
lines=12,
|
| 459 |
max_lines=15,
|
|
@@ -461,7 +457,7 @@ def update_background_visibility(method):
|
|
| 461 |
)
|
| 462 |
|
| 463 |
debug_info = gr.Textbox(
|
| 464 |
-
label="
|
| 465 |
interactive=False,
|
| 466 |
lines=6,
|
| 467 |
max_lines=10,
|
|
@@ -525,9 +521,9 @@ def toggle_debug_visibility(current_visibility):
|
|
| 525 |
)
|
| 526 |
|
| 527 |
# Information and help section
|
| 528 |
-
with gr.Accordion("
|
| 529 |
gr.Markdown(f"""
|
| 530 |
-
###
|
| 531 |
|
| 532 |
1. **Load Models**: Click 'Load Models' and wait for completion (first-time setup)
|
| 533 |
2. **Upload Video**: Choose a video file (MP4 recommended, under 5 minutes)
|
|
@@ -535,7 +531,7 @@ def toggle_debug_visibility(current_visibility):
|
|
| 535 |
4. **Configure Quality**: Choose preset based on your speed/quality preference
|
| 536 |
5. **Process**: Click 'Process Video' and wait for completion
|
| 537 |
|
| 538 |
-
###
|
| 539 |
|
| 540 |
**Single-Stage (Default)**
|
| 541 |
- Direct background replacement
|
|
@@ -549,14 +545,14 @@ def toggle_debug_visibility(current_visibility):
|
|
| 549 |
- Advanced chroma key algorithms
|
| 550 |
- Recommended for: Professional content, broadcast, film
|
| 551 |
|
| 552 |
-
###
|
| 553 |
|
| 554 |
- **Fast Processing**: Use 'fast' preset, disable two-stage mode
|
| 555 |
- **Best Quality**: Use 'high' preset, enable two-stage mode
|
| 556 |
- **GPU Memory**: Processing automatically manages memory and provides fallbacks
|
| 557 |
- **Video Length**: Shorter videos (10-30s) process much faster
|
| 558 |
|
| 559 |
-
###
|
| 560 |
|
| 561 |
**Models Won't Load**
|
| 562 |
- Check internet connection (models download from Hugging Face)
|
|
@@ -575,11 +571,11 @@ def toggle_debug_visibility(current_visibility):
|
|
| 575 |
- Ensure good lighting in original video
|
| 576 |
- Try different professional backgrounds
|
| 577 |
|
| 578 |
-
###
|
| 579 |
|
| 580 |
-
- **Core Functions**: {'
|
| 581 |
-
- **Background Library**: {'
|
| 582 |
-
- **Two-Stage Processing**: {'
|
| 583 |
- **Professional Backgrounds**: {len(PROFESSIONAL_BACKGROUNDS)} presets available
|
| 584 |
""")
|
| 585 |
|
|
|
|
| 153 |
# Enhanced success message
|
| 154 |
avg_time = ui_state.get_average_processing_time()
|
| 155 |
success_info = f"""
|
| 156 |
+
Processing Complete!
|
| 157 |
|
| 158 |
+
Results:
|
| 159 |
{result_message}
|
| 160 |
|
| 161 |
+
Performance:
|
| 162 |
- Average processing time: {avg_time:.1f}s
|
| 163 |
- Two-stage mode: {'Enabled' if use_two_stage else 'Disabled'}
|
| 164 |
- Quality preset: {quality_preset or 'Default'}
|
| 165 |
|
| 166 |
+
Tips:
|
| 167 |
- Try two-stage mode for better quality
|
| 168 |
- Use 'fast' preset for quicker processing
|
| 169 |
- Shorter videos process faster
|
|
|
|
| 196 |
if "SUCCESS" in result or "successful" in result.lower():
|
| 197 |
ui_state.models_loaded = True
|
| 198 |
enhanced_result = f"""
|
| 199 |
+
Models Loaded Successfully!
|
| 200 |
|
| 201 |
+
Status:
|
| 202 |
{result}
|
| 203 |
|
| 204 |
+
Ready for Processing:
|
| 205 |
- High-quality segmentation (SAM2)
|
| 206 |
- Professional mask refinement (MatAnyone)
|
| 207 |
- {'Two-stage green screen mode available' if TWO_STAGE_AVAILABLE else 'Single-stage processing only'}
|
| 208 |
|
| 209 |
+
Next Steps:
|
| 210 |
1. Upload your video
|
| 211 |
2. Choose background method
|
| 212 |
3. Click 'Process Video'
|
|
|
|
| 227 |
status = get_model_status()
|
| 228 |
if isinstance(status, dict):
|
| 229 |
formatted_status = {
|
| 230 |
+
"SAM2 Segmentation": "Ready" if status.get('sam2_available') else "Not Loaded",
|
| 231 |
+
"MatAnyone Refinement": "Ready" if status.get('matanyone_available') else "Not Loaded",
|
| 232 |
+
"Two-Stage Mode": "Available" if status.get('two_stage_available') else "Not Available",
|
| 233 |
"Device": status.get('device', 'Unknown'),
|
| 234 |
+
"Models Validated": "Yes" if status.get('models_loaded') else "No"
|
| 235 |
}
|
| 236 |
if 'memory_usage' in status and status['memory_usage']:
|
| 237 |
memory = status['memory_usage']
|
|
|
|
| 249 |
status = get_cache_status()
|
| 250 |
if isinstance(status, dict):
|
| 251 |
return {
|
| 252 |
+
"Cache Status": "Active" if status.get('models_loaded') else "Inactive",
|
| 253 |
"Processing Mode": "Two-Stage" if status.get('two_stage_available') else "Single-Stage",
|
| 254 |
"Configuration": status.get('config', {}),
|
| 255 |
"System Device": status.get('device', 'Unknown')
|
|
|
|
| 279 |
# Header
|
| 280 |
with gr.Row():
|
| 281 |
gr.Markdown("""
|
| 282 |
+
# BackgroundFX Pro - Video Background Replacement
|
| 283 |
|
| 284 |
Professional-quality video background replacement using AI segmentation and advanced compositing techniques.
|
| 285 |
""", elem_classes=["main-header"])
|
|
|
|
| 289 |
with gr.Column(scale=1):
|
| 290 |
system_status = gr.HTML(f"""
|
| 291 |
<div class="status-box">
|
| 292 |
+
<h4>System Status</h4>
|
| 293 |
<ul>
|
| 294 |
+
<li>Core Functions: {'Available' if CORE_FUNCTIONS_AVAILABLE else 'Not Available'}</li>
|
| 295 |
+
<li>Utilities: {'Available' if UTILITIES_AVAILABLE else 'Not Available'}</li>
|
| 296 |
+
<li>Two-Stage Mode: {'Available' if TWO_STAGE_AVAILABLE else 'Not Available'}</li>
|
| 297 |
</ul>
|
| 298 |
</div>
|
| 299 |
""")
|
|
|
|
| 301 |
with gr.Row():
|
| 302 |
# Left column - Input and controls
|
| 303 |
with gr.Column(scale=1):
|
| 304 |
+
gr.Markdown("### Step 1: Upload Your Video")
|
| 305 |
video_input = gr.Video(
|
| 306 |
label="Upload your video (MP4, AVI, MOV supported)",
|
| 307 |
height=300
|
| 308 |
)
|
| 309 |
|
| 310 |
+
with gr.Accordion("Video Requirements", open=False):
|
| 311 |
gr.Markdown("""
|
| 312 |
**Supported Formats:** MP4, AVI, MOV, MKV
|
| 313 |
**Max Duration:** 5 minutes (300 seconds)
|
|
|
|
| 320 |
- Ensure good lighting and clear person visibility
|
| 321 |
""")
|
| 322 |
|
| 323 |
+
gr.Markdown("### Step 2: Choose Background")
|
| 324 |
background_method = gr.Radio(
|
| 325 |
choices=["professional", "upload"],
|
| 326 |
value="professional",
|
| 327 |
+
label="Background Method"
|
|
|
|
| 328 |
)
|
| 329 |
|
| 330 |
# Professional backgrounds
|
|
|
|
| 342 |
professional_choice = gr.Dropdown(
|
| 343 |
choices=choices,
|
| 344 |
value=default_choice,
|
| 345 |
+
label="Select Professional Background"
|
|
|
|
| 346 |
)
|
| 347 |
|
| 348 |
+
# Custom upload - FIXED: Removed 'info' parameter
|
| 349 |
with gr.Group(visible=False) as upload_group:
|
| 350 |
gr.Markdown("**Upload Custom Background**")
|
| 351 |
custom_background = gr.Image(
|
| 352 |
label="Upload background image",
|
| 353 |
+
type="filepath"
|
|
|
|
| 354 |
)
|
| 355 |
+
gr.Markdown("JPG, PNG supported. Will be resized to match video resolution.")
|
| 356 |
|
| 357 |
# Background method visibility control
|
| 358 |
def update_background_visibility(method):
|
|
|
|
| 367 |
outputs=[professional_group, upload_group]
|
| 368 |
)
|
| 369 |
|
| 370 |
+
gr.Markdown("### Step 3: Processing Options")
|
| 371 |
|
| 372 |
with gr.Row():
|
| 373 |
quality_preset = gr.Dropdown(
|
|
|
|
| 377 |
("High - Best quality", "high")
|
| 378 |
],
|
| 379 |
value="balanced",
|
| 380 |
+
label="Quality Preset"
|
|
|
|
| 381 |
)
|
| 382 |
|
| 383 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 384 |
use_two_stage = gr.Checkbox(
|
| 385 |
label="Enable Two-Stage Processing",
|
| 386 |
value=False,
|
|
|
|
| 387 |
interactive=TWO_STAGE_AVAILABLE
|
| 388 |
)
|
| 389 |
+
gr.Markdown("Cinema-quality green screen mode (slower but much better quality)")
|
| 390 |
|
| 391 |
if TWO_STAGE_AVAILABLE:
|
| 392 |
chroma_preset = gr.Dropdown(
|
|
|
|
| 396 |
("Outdoor - Challenging lighting", "outdoor")
|
| 397 |
],
|
| 398 |
value="standard",
|
| 399 |
+
label="Chroma Key Preset"
|
|
|
|
| 400 |
)
|
| 401 |
else:
|
| 402 |
chroma_preset = gr.Dropdown(
|
|
|
|
| 406 |
interactive=False
|
| 407 |
)
|
| 408 |
|
| 409 |
+
gr.Markdown("### Step 4: Process")
|
| 410 |
|
| 411 |
with gr.Row():
|
| 412 |
load_models_btn = gr.Button(
|
| 413 |
+
"Load Models",
|
| 414 |
variant="secondary",
|
| 415 |
size="lg"
|
| 416 |
)
|
| 417 |
process_btn = gr.Button(
|
| 418 |
+
"Process Video",
|
| 419 |
variant="primary",
|
| 420 |
size="lg",
|
| 421 |
scale=2
|
|
|
|
| 423 |
|
| 424 |
# Status and feedback
|
| 425 |
status_text = gr.Textbox(
|
| 426 |
+
label="Status Updates",
|
| 427 |
value="Ready - Click 'Load Models' to begin",
|
| 428 |
interactive=False,
|
| 429 |
lines=6,
|
|
|
|
| 431 |
)
|
| 432 |
|
| 433 |
# System monitoring
|
| 434 |
+
with gr.Accordion("System Monitoring", open=False):
|
| 435 |
with gr.Row():
|
| 436 |
model_status_btn = gr.Button("Check Models", variant="secondary")
|
| 437 |
cache_status_btn = gr.Button("Check Cache", variant="secondary")
|
|
|
|
| 441 |
|
| 442 |
# Right column - Output and results
|
| 443 |
with gr.Column(scale=1):
|
| 444 |
+
gr.Markdown("### Results")
|
| 445 |
|
| 446 |
video_output = gr.Video(
|
| 447 |
label="Processed Video",
|
|
|
|
| 449 |
)
|
| 450 |
|
| 451 |
result_info = gr.Textbox(
|
| 452 |
+
label="Processing Information",
|
| 453 |
interactive=False,
|
| 454 |
lines=12,
|
| 455 |
max_lines=15,
|
|
|
|
| 457 |
)
|
| 458 |
|
| 459 |
debug_info = gr.Textbox(
|
| 460 |
+
label="Debug Information",
|
| 461 |
interactive=False,
|
| 462 |
lines=6,
|
| 463 |
max_lines=10,
|
|
|
|
| 521 |
)
|
| 522 |
|
| 523 |
# Information and help section
|
| 524 |
+
with gr.Accordion("Help & Information", open=False):
|
| 525 |
gr.Markdown(f"""
|
| 526 |
+
### How to Use
|
| 527 |
|
| 528 |
1. **Load Models**: Click 'Load Models' and wait for completion (first-time setup)
|
| 529 |
2. **Upload Video**: Choose a video file (MP4 recommended, under 5 minutes)
|
|
|
|
| 531 |
4. **Configure Quality**: Choose preset based on your speed/quality preference
|
| 532 |
5. **Process**: Click 'Process Video' and wait for completion
|
| 533 |
|
| 534 |
+
### Processing Modes
|
| 535 |
|
| 536 |
**Single-Stage (Default)**
|
| 537 |
- Direct background replacement
|
|
|
|
| 545 |
- Advanced chroma key algorithms
|
| 546 |
- Recommended for: Professional content, broadcast, film
|
| 547 |
|
| 548 |
+
### Performance Tips
|
| 549 |
|
| 550 |
- **Fast Processing**: Use 'fast' preset, disable two-stage mode
|
| 551 |
- **Best Quality**: Use 'high' preset, enable two-stage mode
|
| 552 |
- **GPU Memory**: Processing automatically manages memory and provides fallbacks
|
| 553 |
- **Video Length**: Shorter videos (10-30s) process much faster
|
| 554 |
|
| 555 |
+
### Troubleshooting
|
| 556 |
|
| 557 |
**Models Won't Load**
|
| 558 |
- Check internet connection (models download from Hugging Face)
|
|
|
|
| 571 |
- Ensure good lighting in original video
|
| 572 |
- Try different professional backgrounds
|
| 573 |
|
| 574 |
+
### System Information
|
| 575 |
|
| 576 |
+
- **Core Functions**: {'Available' if CORE_FUNCTIONS_AVAILABLE else 'Not Available'}
|
| 577 |
+
- **Background Library**: {'Available' if UTILITIES_AVAILABLE else 'Not Available'}
|
| 578 |
+
- **Two-Stage Processing**: {'Available' if TWO_STAGE_AVAILABLE else 'Not Available'}
|
| 579 |
- **Professional Backgrounds**: {len(PROFESSIONAL_BACKGROUNDS)} presets available
|
| 580 |
""")
|
| 581 |
|