luh1124 commited on
Commit
50bbead
·
1 Parent(s): ffb265b

fix(ui): pass Gradio 6 theme/css via launch() for HF Spaces

Browse files
Files changed (1) hide show
  1. app.py +18 -5
app.py CHANGED
@@ -860,18 +860,18 @@ main.gradio-container { max-width: 100% !important; }
860
  footer { display:none !important; }
861
  """
862
 
 
 
 
 
 
863
 
864
  # ---------------------------------------------------------------------------
865
  # UI
866
  # ---------------------------------------------------------------------------
867
  def build_app() -> gr.Blocks:
868
  with gr.Blocks(
869
- theme=gr.themes.Base(
870
- primary_hue=gr.themes.colors.blue,
871
- secondary_hue=gr.themes.colors.blue,
872
- ),
873
  title="NeAR",
874
- css=CUSTOM_CSS,
875
  # (600, 600) deletes Gradio /tmp/gradio uploads in ~10m while the UI may still reference paths.
876
  delete_cache=None,
877
  fill_width=True,
@@ -1209,6 +1209,19 @@ def build_app() -> gr.Blocks:
1209
 
1210
  demo = build_app()
1211
  demo.queue(max_size=8)
 
 
 
 
 
 
 
 
 
 
 
 
 
1212
  start_tmp_gradio_pruner()
1213
 
1214
  # ---------------------------------------------------------------------------
 
860
  footer { display:none !important; }
861
  """
862
 
863
+ NEAR_GRADIO_THEME = gr.themes.Base(
864
+ primary_hue=gr.themes.colors.blue,
865
+ secondary_hue=gr.themes.colors.blue,
866
+ )
867
+
868
 
869
  # ---------------------------------------------------------------------------
870
  # UI
871
  # ---------------------------------------------------------------------------
872
  def build_app() -> gr.Blocks:
873
  with gr.Blocks(
 
 
 
 
874
  title="NeAR",
 
875
  # (600, 600) deletes Gradio /tmp/gradio uploads in ~10m while the UI may still reference paths.
876
  delete_cache=None,
877
  fill_width=True,
 
1209
 
1210
  demo = build_app()
1211
  demo.queue(max_size=8)
1212
+
1213
+ # Gradio 6: theme/css must be passed to launch(); HF Spaces calls demo.launch() without our __main__ block.
1214
+ _orig_blocks_launch = demo.launch
1215
+
1216
+
1217
+ def _near_launch(*args: Any, **kwargs: Any):
1218
+ kwargs.setdefault("theme", NEAR_GRADIO_THEME)
1219
+ kwargs.setdefault("css", CUSTOM_CSS)
1220
+ return _orig_blocks_launch(*args, **kwargs)
1221
+
1222
+
1223
+ demo.launch = _near_launch # type: ignore[method-assign]
1224
+
1225
  start_tmp_gradio_pruner()
1226
 
1227
  # ---------------------------------------------------------------------------