MogensR commited on
Commit
e7b3257
·
1 Parent(s): 7b9fcf8

Update ui/ui_components.py

Browse files
Files changed (1) hide show
  1. ui/ui_components.py +65 -10
ui/ui_components.py CHANGED
@@ -2,12 +2,13 @@
2
  """
3
  UI Components for BackgroundFX Pro (forced Two-Stage)
4
  -----------------------------------------------------
5
- * Pure layout: no heavy logic
6
- * All callbacks live in ui/callbacks.py
7
  * Two-stage mode is always active (checkbox removed)
8
  """
9
 
10
  from __future__ import annotations
 
11
  import gradio as gr
12
 
13
  from ui.callbacks import (
@@ -21,17 +22,52 @@
21
  cb_preset_bg_preview,
22
  )
23
 
 
24
  CSS = """
25
- :root { --radius: 16px; }
26
- .gradio-container { max-width: 1080px !important; margin: auto !important; }
27
- #hero .prose { font-size: 15px; }
28
- .card { border-radius: var(--radius); border: 1px solid rgba(0,0,0,.08); padding: 16px;
29
- background: linear-gradient(180deg, rgba(255,255,255,.9), rgba(248,250,252,.9));
30
- box-shadow: 0 10px 30px rgba(0,0,0,.06); }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  .footer-note { opacity: 0.7; font-size: 12px; }
32
  .sm { font-size: 13px; opacity: 0.85; }
33
  #statusbox { min-height: 120px; }
34
  .preview-img { border-radius: var(--radius); border: 1px solid rgba(0,0,0,.08); }
 
 
 
 
 
35
  """
36
 
37
  # Keep in sync with utils/cv_processing.PROFESSIONAL_BACKGROUNDS
@@ -178,6 +214,13 @@ def create_interface() -> gr.Blocks:
178
  label="Preview Green-screen only (mute audio)",
179
  value=False
180
  )
 
 
 
 
 
 
 
181
 
182
  with gr.Row():
183
  btn_load = gr.Button("🔄 Load Models", variant="secondary")
@@ -229,9 +272,19 @@ def _toggle_bg_sections(choice: str):
229
  # Load models
230
  btn_load.click(cb_load_models, outputs=statusbox)
231
 
232
- # Always two-stage: pass use_two_stage=True to callback
 
 
 
 
 
 
 
 
 
 
233
  btn_run.click(
234
- cb_process_video,
235
  inputs=[
236
  video,
237
  bg_style,
@@ -241,6 +294,7 @@ def _toggle_bg_sections(choice: str):
241
  key_color_mode,
242
  preview_mask,
243
  preview_greenscreen,
 
244
  ],
245
  outputs=[out_video, statusbox],
246
  )
@@ -286,3 +340,4 @@ def _toggle_bg_sections(choice: str):
286
  )
287
 
288
  return demo
 
 
2
  """
3
  UI Components for BackgroundFX Pro (forced Two-Stage)
4
  -----------------------------------------------------
5
+ * Pure layout (tiny wrapper to set env for quality)
6
+ * All heavy logic stays in ui/callbacks.py
7
  * Two-stage mode is always active (checkbox removed)
8
  """
9
 
10
  from __future__ import annotations
11
+ import os
12
  import gradio as gr
13
 
14
  from ui.callbacks import (
 
22
  cb_preset_bg_preview,
23
  )
24
 
25
+ # Typography & UI polish: sharper text + cleaner cards
26
  CSS = """
27
+ :root {
28
+ --radius: 16px;
29
+ --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto,
30
+ 'Helvetica Neue', Arial, sans-serif;
31
+ }
32
+
33
+ /* Global crisp text */
34
+ html, body, .gradio-container, .gradio-container * {
35
+ font-family: var(--font-sans) !important;
36
+ -webkit-font-smoothing: antialiased !important;
37
+ -moz-osx-font-smoothing: grayscale !important;
38
+ text-rendering: optimizeLegibility !important;
39
+ font-synthesis-weight: none;
40
+ }
41
+
42
+ /* Headings tighter & bolder */
43
+ .gradio-container h1, .gradio-container h2, .gradio-container h3 {
44
+ letter-spacing: -0.01em;
45
+ font-weight: 700;
46
+ }
47
+
48
+ /* Body copy slightly tighter */
49
+ #hero .prose, .gr-markdown, .gr-text {
50
+ letter-spacing: -0.003em;
51
+ }
52
+
53
+ /* Card look */
54
+ .card {
55
+ border-radius: var(--radius);
56
+ border: 1px solid rgba(0,0,0,.08);
57
+ padding: 16px;
58
+ background: linear-gradient(180deg, rgba(255,255,255,.94), rgba(248,250,252,.94));
59
+ box-shadow: 0 10px 30px rgba(0,0,0,.06);
60
+ }
61
+
62
  .footer-note { opacity: 0.7; font-size: 12px; }
63
  .sm { font-size: 13px; opacity: 0.85; }
64
  #statusbox { min-height: 120px; }
65
  .preview-img { border-radius: var(--radius); border: 1px solid rgba(0,0,0,.08); }
66
+
67
+ /* Buttons get a tiny weight bump for clarity */
68
+ button, .gr-button {
69
+ font-weight: 600;
70
+ }
71
  """
72
 
73
  # Keep in sync with utils/cv_processing.PROFESSIONAL_BACKGROUNDS
 
214
  label="Preview Green-screen only (mute audio)",
215
  value=False
216
  )
217
+ # NEW: Quality control (Speed / Balanced / Max)
218
+ quality = gr.Dropdown(
219
+ label="Quality",
220
+ choices=["speed", "balanced", "max"],
221
+ value=os.getenv("BFX_QUALITY", "balanced"),
222
+ info="Speed = fastest; Max = best edges & spill control."
223
+ )
224
 
225
  with gr.Row():
226
  btn_load = gr.Button("🔄 Load Models", variant="secondary")
 
272
  # Load models
273
  btn_load.click(cb_load_models, outputs=statusbox)
274
 
275
+ # Tiny wrapper to set env for quality before calling the existing callback
276
+ def _run_with_quality(video_pth, bg_style_val, custom_bg_pth,
277
+ use_two_stage_state, chroma_p, key_mode,
278
+ prev_mask, prev_gs, quality_val):
279
+ os.environ["BFX_QUALITY"] = (quality_val or "balanced")
280
+ return cb_process_video(
281
+ video_pth, bg_style_val, custom_bg_pth,
282
+ use_two_stage_state, chroma_p, key_mode, prev_mask, prev_gs
283
+ )
284
+
285
+ # Always two-stage: pass use_two_stage=True to callback via State
286
  btn_run.click(
287
+ _run_with_quality,
288
  inputs=[
289
  video,
290
  bg_style,
 
294
  key_color_mode,
295
  preview_mask,
296
  preview_greenscreen,
297
+ quality, # NEW
298
  ],
299
  outputs=[out_video, statusbox],
300
  )
 
340
  )
341
 
342
  return demo
343
+