JoeTach Claude Opus 4.7 commited on
Commit
eafcb90
·
1 Parent(s): 3a63415

Move Gradio theme to launch() per Gradio 6.0 deprecation

Browse files

The build succeeded but the worker log carried:
UserWarning: The parameters have been moved from the Blocks
constructor to the launch() method in Gradio 6.0: theme.

Gradio 6.0 deprecates the Blocks(theme=...) form in favour of
launch(theme=...). Moved the theme accordingly:
* gradio_app.py: Blocks() no longer takes theme; the __main__ block
passes theme=gr.themes.Soft() to launch() for the local 'python
gradio_app.py' workflow.
* app.py: the HF Spaces entrypoint also passes theme=gr.themes.Soft()
to launch(), so the deployed Space gets the Soft theme too.

Locally: 'python gradio_app.py' still starts at http://127.0.0.1:7860
with the Soft theme.
On HF: next rebuild has zero deprecation warnings.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

Files changed (2) hide show
  1. app.py +28 -1
  2. gradio_app.py +6 -1
app.py CHANGED
@@ -1,4 +1,31 @@
 
 
 
 
 
 
 
 
1
  from gradio_app import demo
2
 
 
 
 
 
 
 
 
 
 
 
3
  if __name__ == "__main__":
4
- demo.launch()
 
 
 
 
 
 
 
 
 
 
1
+ """Hugging Face Space entrypoint --- imports the Gradio demo from
2
+ ``gradio_app.py`` and launches it.
3
+
4
+ HF Spaces reads ``app_file: app.py`` from the README YAML frontmatter
5
+ and runs ``python app.py`` at boot. Keeping this file tiny means the
6
+ entrypoint contract is stable; UI changes happen in ``gradio_app.py``.
7
+ """
8
+
9
  from gradio_app import demo
10
 
11
+ # Theme on launch() (Gradio 6.0 deprecation: theme moved off Blocks()).
12
+ # Lazy import keeps app.py importable without gradio when a tool only
13
+ # wants to introspect the module.
14
+ try:
15
+ import gradio as gr
16
+ _theme = gr.themes.Soft()
17
+ except Exception:
18
+ _theme = None
19
+
20
+
21
  if __name__ == "__main__":
22
+ # HF Spaces runs this. server_name=0.0.0.0 is required so the
23
+ # outer Node proxy can reach the Python worker. The launch options
24
+ # match what gradio_app.py does for local development; HF ignores
25
+ # any port we set and proxies its own.
26
+ demo.launch(
27
+ server_name="0.0.0.0",
28
+ server_port=7860,
29
+ show_error=True,
30
+ theme=_theme,
31
+ )
gradio_app.py CHANGED
@@ -355,9 +355,11 @@ def _compare_uploaded_csv(file_obj, epochs: int, rl_steps: int) -> tuple[str, li
355
  # ---------------------------------------------------------------------------
356
 
357
  def build_ui() -> gr.Blocks:
 
 
 
358
  with gr.Blocks(
359
  title="CDPR Simulator",
360
- theme=gr.themes.Soft(),
361
  analytics_enabled=False,
362
  ) as demo:
363
  gr.Markdown(
@@ -552,6 +554,9 @@ if __name__ == "__main__":
552
  server_name=os.environ.get("GRADIO_SERVER_NAME", "0.0.0.0"),
553
  server_port=int(os.environ.get("GRADIO_SERVER_PORT", "7860")),
554
  show_error=True,
 
 
 
555
  # share=True would give a temporary tunnel URL --- uncomment
556
  # if you need a public link without going through HF Spaces.
557
  # share=True,
 
355
  # ---------------------------------------------------------------------------
356
 
357
  def build_ui() -> gr.Blocks:
358
+ # Gradio 6.0 moved ``theme`` from the Blocks() constructor to
359
+ # ``launch(theme=...)``. We pass theme via launch() below; the
360
+ # Blocks-level params here are the ones that still work.
361
  with gr.Blocks(
362
  title="CDPR Simulator",
 
363
  analytics_enabled=False,
364
  ) as demo:
365
  gr.Markdown(
 
554
  server_name=os.environ.get("GRADIO_SERVER_NAME", "0.0.0.0"),
555
  server_port=int(os.environ.get("GRADIO_SERVER_PORT", "7860")),
556
  show_error=True,
557
+ # Gradio 6.0 expects theme here, not on Blocks().
558
+ # Soft is the closest match to the previous look.
559
+ theme=gr.themes.Soft(),
560
  # share=True would give a temporary tunnel URL --- uncomment
561
  # if you need a public link without going through HF Spaces.
562
  # share=True,