MogensR commited on
Commit
26c51ac
·
1 Parent(s): 7060451

Update ui_components.py

Browse files
Files changed (1) hide show
  1. ui_components.py +24 -23
ui_components.py CHANGED
@@ -14,7 +14,7 @@
14
  from typing import Optional
15
 
16
  # Import core processing functions
17
- from app import load_models_with_validation, process_video_fixed, get_model_status, get_cache_status
18
  from utilities import PROFESSIONAL_BACKGROUNDS, create_procedural_background
19
 
20
  # Check if two-stage is available
@@ -34,19 +34,20 @@
34
  # ============================================================================ #
35
  # GRADIO MONKEY PATCH (BUG FIX for gradio>=4.44.0)
36
  # ============================================================================ #
37
- try:
38
- import gradio_client.utils as gc_utils
39
- original_get_type = gc_utils.get_type
40
- def patched_get_type(schema):
41
- if not isinstance(schema, dict):
42
- if isinstance(schema, bool):
43
- return "boolean"
44
- return "string"
45
- return original_get_type(schema)
46
- gc_utils.get_type = patched_get_type
47
- logger.info("Applied Gradio schema validation monkey patch.")
48
- except (ImportError, AttributeError) as e:
49
- logger.warning(f"Could not apply Gradio monkey patch: {e}")
 
50
 
51
  # ============================================================================ #
52
  # DEBUG LOGGING FUNCTIONS
@@ -96,8 +97,7 @@ def update_cache_status():
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
  # ============================================================================ #
@@ -125,14 +125,8 @@ def process_video_enhanced_fixed(
125
  add_debug_log("ERROR: No video file provided")
126
  return None, "No video file provided.", get_debug_log()
127
 
128
- # Log checkbox value for debugging
129
- add_debug_log(f"CHECKBOX RAW VALUE: use_two_stage = {use_two_stage}")
130
- add_debug_log(f"CHECKBOX TYPE: {type(use_two_stage)}")
131
- add_debug_log(f"CHECKBOX BOOL CONVERSION: {bool(use_two_stage)}")
132
-
133
  # Force boolean conversion to be safe
134
  use_two_stage = bool(use_two_stage)
135
- add_debug_log(f"FINAL use_two_stage value: {use_two_stage}")
136
 
137
  def progress_callback(pct, desc):
138
  # Update Gradio progress bar
@@ -394,7 +388,7 @@ def create_interface():
394
  visible=False
395
  )
396
 
397
- # Debug checkbox changes
398
  use_two_stage.change(
399
  fn=on_two_stage_change,
400
  inputs=use_two_stage,
@@ -405,6 +399,7 @@ def create_interface():
405
  with gr.Row():
406
  load_models_btn = gr.Button("Load Models", variant="secondary")
407
  process_btn = gr.Button("Process Video", variant="primary", scale=2)
 
408
 
409
  status_text = gr.Textbox(
410
  label="Status",
@@ -473,6 +468,12 @@ def create_interface():
473
  show_progress=True
474
  )
475
 
 
 
 
 
 
 
476
  # Refresh processing info manually
477
  refresh_info_btn.click(
478
  fn=refresh_processing_info,
 
14
  from typing import Optional
15
 
16
  # Import core processing functions
17
+ from app import load_models_with_validation, process_video_fixed, get_model_status, get_cache_status, PROCESS_CANCELLED
18
  from utilities import PROFESSIONAL_BACKGROUNDS, create_procedural_background
19
 
20
  # Check if two-stage is available
 
34
  # ============================================================================ #
35
  # GRADIO MONKEY PATCH (BUG FIX for gradio>=4.44.0)
36
  # ============================================================================ #
37
+ # Comment out if not needed in current Gradio version
38
+ # try:
39
+ # import gradio_client.utils as gc_utils
40
+ # original_get_type = gc_utils.get_type
41
+ # def patched_get_type(schema):
42
+ # if not isinstance(schema, dict):
43
+ # if isinstance(schema, bool):
44
+ # return "boolean"
45
+ # return "string"
46
+ # return original_get_type(schema)
47
+ # gc_utils.get_type = patched_get_type
48
+ # logger.info("Applied Gradio schema validation monkey patch.")
49
+ # except (ImportError, AttributeError) as e:
50
+ # logger.warning(f"Could not apply Gradio monkey patch: {e}")
51
 
52
  # ============================================================================ #
53
  # DEBUG LOGGING FUNCTIONS
 
97
  return f"Status check error: {str(e)}"
98
 
99
  def on_two_stage_change(value):
100
+ """Handler for two-stage checkbox changes"""
 
101
  return gr.update(visible=value)
102
 
103
  # ============================================================================ #
 
125
  add_debug_log("ERROR: No video file provided")
126
  return None, "No video file provided.", get_debug_log()
127
 
 
 
 
 
 
128
  # Force boolean conversion to be safe
129
  use_two_stage = bool(use_two_stage)
 
130
 
131
  def progress_callback(pct, desc):
132
  # Update Gradio progress bar
 
388
  visible=False
389
  )
390
 
391
+ # Handler for checkbox
392
  use_two_stage.change(
393
  fn=on_two_stage_change,
394
  inputs=use_two_stage,
 
399
  with gr.Row():
400
  load_models_btn = gr.Button("Load Models", variant="secondary")
401
  process_btn = gr.Button("Process Video", variant="primary", scale=2)
402
+ cancel_btn = gr.Button("Cancel Processing", variant="stop")
403
 
404
  status_text = gr.Textbox(
405
  label="Status",
 
468
  show_progress=True
469
  )
470
 
471
+ # Cancel processing
472
+ cancel_btn.click(
473
+ fn=lambda: (PROCESS_CANCELLED.set(), "Processing cancelled"),
474
+ outputs=[status_text]
475
+ )
476
+
477
  # Refresh processing info manually
478
  refresh_info_btn.click(
479
  fn=refresh_processing_info,