MogensR commited on
Commit
c74f6ba
·
1 Parent(s): 62ed502

Update ui/ui_components.py

Browse files
Files changed (1) hide show
  1. ui/ui_components.py +14 -21
ui/ui_components.py CHANGED
@@ -6,7 +6,7 @@
6
  * All callbacks live in ui/callbacks.py
7
  * Adds live previews for the first frame of the uploaded video
8
  and for the custom background image
9
- * FIXED: Background preview NOT touched by process button
10
  """
11
 
12
  from __future__ import annotations
@@ -21,8 +21,7 @@
21
  cb_generate_bg,
22
  cb_use_gen_bg,
23
  cb_video_changed,
24
- cb_custom_bg_preview,
25
- cb_preset_bg_preview, # Added import for preset preview
26
  )
27
 
28
  CSS = """
@@ -92,15 +91,11 @@ def create_interface() -> gr.Blocks:
92
  info="Matches keys in PROFESSIONAL_BACKGROUNDS"
93
  )
94
 
95
- custom_bg = gr.File(
 
96
  label="Custom Background (optional)",
97
- file_types=["image"],
98
- interactive=True
99
- )
100
-
101
- custom_bg_preview_img = gr.Image(
102
- label="Custom Background Preview",
103
- interactive=False,
104
  elem_classes=["preview-img"]
105
  )
106
 
@@ -201,29 +196,28 @@ def create_interface() -> gr.Blocks:
201
  # ------------------------------------------------------------------
202
  btn_load.click(cb_load_models, outputs=statusbox)
203
 
204
- # FIXED: Process button only updates what needs to change
205
  btn_run.click(
206
  cb_process_video,
207
  inputs=[
208
  video,
209
  bg_style,
210
- custom_bg,
211
  use_two_stage,
212
  chroma_preset,
213
  key_color_mode,
214
  preview_mask,
215
  preview_greenscreen,
216
  ],
217
- outputs=[out_video, statusbox], # Only 2 outputs - NOT touching preview!
218
  )
219
 
220
  btn_cancel.click(cb_cancel, outputs=statusbox)
221
  btn_refresh.click(cb_status, outputs=[model_status, cache_status])
222
 
223
- # Clear button - only clears what it needs to
224
  btn_clear.click(
225
  cb_clear,
226
- outputs=[out_video, statusbox, gen_preview, gen_path, custom_bg_preview_img]
227
  )
228
 
229
  # AI background generation
@@ -235,22 +229,21 @@ def create_interface() -> gr.Blocks:
235
 
236
  use_gen_as_custom.click(cb_use_gen_bg, inputs=[gen_path], outputs=[custom_bg])
237
 
238
- # Live previews - only update when actually changing backgrounds
239
  video.change(cb_video_changed, inputs=[video], outputs=[video_preview])
240
- custom_bg.change(cb_custom_bg_preview, inputs=[custom_bg], outputs=[custom_bg_preview_img])
241
 
242
- # Update preview when background style dropdown changes
243
  bg_style.change(
244
  cb_preset_bg_preview,
245
  inputs=[bg_style],
246
- outputs=[custom_bg_preview_img]
247
  )
248
 
249
  # Initialize with default background preview on load
250
  demo.load(
251
  cb_preset_bg_preview,
252
  inputs=[bg_style],
253
- outputs=[custom_bg_preview_img]
254
  )
255
 
256
  return demo
 
6
  * All callbacks live in ui/callbacks.py
7
  * Adds live previews for the first frame of the uploaded video
8
  and for the custom background image
9
+ * SIMPLIFIED: Background uses gr.Image like video uses gr.Video
10
  """
11
 
12
  from __future__ import annotations
 
21
  cb_generate_bg,
22
  cb_use_gen_bg,
23
  cb_video_changed,
24
+ cb_preset_bg_preview,
 
25
  )
26
 
27
  CSS = """
 
91
  info="Matches keys in PROFESSIONAL_BACKGROUNDS"
92
  )
93
 
94
+ # SIMPLIFIED: Use gr.Image for both upload AND preview
95
+ custom_bg = gr.Image(
96
  label="Custom Background (optional)",
97
+ interactive=True,
98
+ type="filepath", # Returns file path like gr.File did
 
 
 
 
 
99
  elem_classes=["preview-img"]
100
  )
101
 
 
196
  # ------------------------------------------------------------------
197
  btn_load.click(cb_load_models, outputs=statusbox)
198
 
 
199
  btn_run.click(
200
  cb_process_video,
201
  inputs=[
202
  video,
203
  bg_style,
204
+ custom_bg, # Now gr.Image that returns filepath
205
  use_two_stage,
206
  chroma_preset,
207
  key_color_mode,
208
  preview_mask,
209
  preview_greenscreen,
210
  ],
211
+ outputs=[out_video, statusbox],
212
  )
213
 
214
  btn_cancel.click(cb_cancel, outputs=statusbox)
215
  btn_refresh.click(cb_status, outputs=[model_status, cache_status])
216
 
217
+ # Clear button - simplified
218
  btn_clear.click(
219
  cb_clear,
220
+ outputs=[out_video, statusbox, gen_preview, gen_path, custom_bg]
221
  )
222
 
223
  # AI background generation
 
229
 
230
  use_gen_as_custom.click(cb_use_gen_bg, inputs=[gen_path], outputs=[custom_bg])
231
 
232
+ # Live previews
233
  video.change(cb_video_changed, inputs=[video], outputs=[video_preview])
 
234
 
235
+ # Update custom_bg preview when background style dropdown changes
236
  bg_style.change(
237
  cb_preset_bg_preview,
238
  inputs=[bg_style],
239
+ outputs=[custom_bg]
240
  )
241
 
242
  # Initialize with default background preview on load
243
  demo.load(
244
  cb_preset_bg_preview,
245
  inputs=[bg_style],
246
+ outputs=[custom_bg]
247
  )
248
 
249
  return demo