Update ui_components.py
Browse files- ui_components.py +32 -26
ui_components.py
CHANGED
|
@@ -70,9 +70,7 @@ def create_interface():
|
|
| 70 |
|
| 71 |
# Safe processing function
|
| 72 |
def safe_process_video(video_path, bg_method, custom_img, prof_choice,
|
| 73 |
-
|
| 74 |
-
ai_prompt, ai_style, ai_img, use_two_stage, chroma_preset,
|
| 75 |
-
progress: Optional[gr.Progress] = None):
|
| 76 |
"""Safe wrapper for video processing"""
|
| 77 |
if not CORE_FUNCTIONS_AVAILABLE:
|
| 78 |
return None, "Core processing functions not available", "Error: Core functions not loaded"
|
|
@@ -83,6 +81,7 @@ def progress_callback(pct, desc):
|
|
| 83 |
if progress:
|
| 84 |
progress(pct)
|
| 85 |
print(f"Progress: {pct:.1%} - {desc}")
|
|
|
|
| 86 |
|
| 87 |
# Call the main processing function
|
| 88 |
if bg_method == "professional" and prof_choice:
|
|
@@ -90,14 +89,18 @@ def progress_callback(pct, desc):
|
|
| 90 |
video_path, prof_choice, None,
|
| 91 |
progress_callback,
|
| 92 |
use_two_stage=bool(use_two_stage),
|
| 93 |
-
chroma_preset=chroma_preset or "standard"
|
|
|
|
|
|
|
| 94 |
)
|
| 95 |
elif bg_method == "upload" and custom_img:
|
| 96 |
result = process_video_fixed(
|
| 97 |
video_path, "custom", custom_img,
|
| 98 |
progress_callback,
|
| 99 |
use_two_stage=bool(use_two_stage),
|
| 100 |
-
chroma_preset=chroma_preset or "standard"
|
|
|
|
|
|
|
| 101 |
)
|
| 102 |
else:
|
| 103 |
return None, "Please select a valid background method", "Error: Invalid background selection"
|
|
@@ -105,9 +108,8 @@ def progress_callback(pct, desc):
|
|
| 105 |
return result[0], result[1], f"Processing completed successfully"
|
| 106 |
|
| 107 |
except Exception as e:
|
| 108 |
-
error_msg = f"Processing error: {str(e)}"
|
| 109 |
print(f"Error in safe_process_video: {error_msg}")
|
| 110 |
-
traceback.print_exc()
|
| 111 |
return None, error_msg, f"Error: {error_msg}"
|
| 112 |
|
| 113 |
# Safe model loading function
|
|
@@ -121,12 +123,13 @@ def progress_callback(pct, desc):
|
|
| 121 |
if progress:
|
| 122 |
progress(pct)
|
| 123 |
print(f"Model loading: {pct:.1%} - {desc}")
|
|
|
|
| 124 |
|
| 125 |
result = load_models_with_validation(progress_callback)
|
| 126 |
return result, f"Model loading completed"
|
| 127 |
|
| 128 |
except Exception as e:
|
| 129 |
-
error_msg = f"Model loading error: {str(e)}"
|
| 130 |
print(f"Error in safe_load_models: {error_msg}")
|
| 131 |
return error_msg, error_msg
|
| 132 |
|
|
@@ -220,6 +223,14 @@ def update_visibility(method):
|
|
| 220 |
interactive=False,
|
| 221 |
lines=3
|
| 222 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
|
| 224 |
with gr.Column(scale=1):
|
| 225 |
gr.Markdown("### 🎥 Result")
|
|
@@ -253,14 +264,6 @@ def update_visibility(method):
|
|
| 253 |
background_method,
|
| 254 |
custom_background,
|
| 255 |
professional_choice,
|
| 256 |
-
gr.State("vertical"), # grad_type placeholder
|
| 257 |
-
gr.State("#3498db"), # color1 placeholder
|
| 258 |
-
gr.State("#2ecc71"), # color2 placeholder
|
| 259 |
-
gr.State("#e74c3c"), # color3 placeholder
|
| 260 |
-
gr.State(False), # use_third placeholder
|
| 261 |
-
gr.State(""), # ai_prompt placeholder
|
| 262 |
-
gr.State("photorealistic"), # ai_style placeholder
|
| 263 |
-
gr.State(None), # ai_img placeholder
|
| 264 |
use_two_stage,
|
| 265 |
chroma_preset
|
| 266 |
],
|
|
@@ -268,6 +271,18 @@ def update_visibility(method):
|
|
| 268 |
show_progress=True
|
| 269 |
)
|
| 270 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
# Info section
|
| 272 |
with gr.Accordion("ℹ️ Information", open=False):
|
| 273 |
gr.Markdown(f"""
|
|
@@ -282,13 +297,4 @@ def update_visibility(method):
|
|
| 282 |
- Professional backgrounds are optimized for best results
|
| 283 |
""")
|
| 284 |
|
| 285 |
-
return demo
|
| 286 |
-
|
| 287 |
-
if __name__ == "__main__":
|
| 288 |
-
# Test the interface creation
|
| 289 |
-
try:
|
| 290 |
-
demo = create_interface()
|
| 291 |
-
demo.launch(share=True)
|
| 292 |
-
except Exception as e:
|
| 293 |
-
print(f"Failed to create interface: {e}")
|
| 294 |
-
traceback.print_exc()
|
|
|
|
| 70 |
|
| 71 |
# Safe processing function
|
| 72 |
def safe_process_video(video_path, bg_method, custom_img, prof_choice,
|
| 73 |
+
use_two_stage, chroma_preset, progress: Optional[gr.Progress] = None):
|
|
|
|
|
|
|
| 74 |
"""Safe wrapper for video processing"""
|
| 75 |
if not CORE_FUNCTIONS_AVAILABLE:
|
| 76 |
return None, "Core processing functions not available", "Error: Core functions not loaded"
|
|
|
|
| 81 |
if progress:
|
| 82 |
progress(pct)
|
| 83 |
print(f"Progress: {pct:.1%} - {desc}")
|
| 84 |
+
return desc # Match app.py's expectation
|
| 85 |
|
| 86 |
# Call the main processing function
|
| 87 |
if bg_method == "professional" and prof_choice:
|
|
|
|
| 89 |
video_path, prof_choice, None,
|
| 90 |
progress_callback,
|
| 91 |
use_two_stage=bool(use_two_stage),
|
| 92 |
+
chroma_preset=chroma_preset or "standard",
|
| 93 |
+
preview_mask=False,
|
| 94 |
+
preview_greenscreen=False
|
| 95 |
)
|
| 96 |
elif bg_method == "upload" and custom_img:
|
| 97 |
result = process_video_fixed(
|
| 98 |
video_path, "custom", custom_img,
|
| 99 |
progress_callback,
|
| 100 |
use_two_stage=bool(use_two_stage),
|
| 101 |
+
chroma_preset=chroma_preset or "standard",
|
| 102 |
+
preview_mask=False,
|
| 103 |
+
preview_greenscreen=False
|
| 104 |
)
|
| 105 |
else:
|
| 106 |
return None, "Please select a valid background method", "Error: Invalid background selection"
|
|
|
|
| 108 |
return result[0], result[1], f"Processing completed successfully"
|
| 109 |
|
| 110 |
except Exception as e:
|
| 111 |
+
error_msg = f"Processing error: {str(e)}\n{traceback.format_exc()}"
|
| 112 |
print(f"Error in safe_process_video: {error_msg}")
|
|
|
|
| 113 |
return None, error_msg, f"Error: {error_msg}"
|
| 114 |
|
| 115 |
# Safe model loading function
|
|
|
|
| 123 |
if progress:
|
| 124 |
progress(pct)
|
| 125 |
print(f"Model loading: {pct:.1%} - {desc}")
|
| 126 |
+
return desc # Match app.py's expectation
|
| 127 |
|
| 128 |
result = load_models_with_validation(progress_callback)
|
| 129 |
return result, f"Model loading completed"
|
| 130 |
|
| 131 |
except Exception as e:
|
| 132 |
+
error_msg = f"Model loading error: {str(e)}\n{traceback.format_exc()}"
|
| 133 |
print(f"Error in safe_load_models: {error_msg}")
|
| 134 |
return error_msg, error_msg
|
| 135 |
|
|
|
|
| 223 |
interactive=False,
|
| 224 |
lines=3
|
| 225 |
)
|
| 226 |
+
|
| 227 |
+
# Add model and cache status buttons
|
| 228 |
+
with gr.Row():
|
| 229 |
+
model_status_btn = gr.Button("Check Model Status", variant="secondary")
|
| 230 |
+
cache_status_btn = gr.Button("Check Cache Status", variant="secondary")
|
| 231 |
+
|
| 232 |
+
model_status = gr.JSON(label="Model Status", interactive=False)
|
| 233 |
+
cache_status = gr.JSON(label="Cache Status", interactive=False)
|
| 234 |
|
| 235 |
with gr.Column(scale=1):
|
| 236 |
gr.Markdown("### 🎥 Result")
|
|
|
|
| 264 |
background_method,
|
| 265 |
custom_background,
|
| 266 |
professional_choice,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
use_two_stage,
|
| 268 |
chroma_preset
|
| 269 |
],
|
|
|
|
| 271 |
show_progress=True
|
| 272 |
)
|
| 273 |
|
| 274 |
+
model_status_btn.click(
|
| 275 |
+
fn=get_model_status,
|
| 276 |
+
outputs=[model_status],
|
| 277 |
+
show_progress=False
|
| 278 |
+
)
|
| 279 |
+
|
| 280 |
+
cache_status_btn.click(
|
| 281 |
+
fn=get_cache_status,
|
| 282 |
+
outputs=[cache_status],
|
| 283 |
+
show_progress=False
|
| 284 |
+
)
|
| 285 |
+
|
| 286 |
# Info section
|
| 287 |
with gr.Accordion("ℹ️ Information", open=False):
|
| 288 |
gr.Markdown(f"""
|
|
|
|
| 297 |
- Professional backgrounds are optimized for best results
|
| 298 |
""")
|
| 299 |
|
| 300 |
+
return demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|