AndrewRqy commited on
Commit ·
9233b44
1
Parent(s): 7c97976
Define demo at module scope so HF Space's hot-reload launcher applies theme+css
Browse files4407 unmodified lines4408440944104411441244134414441544164417441844194420442144224423558 unmodified lines498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950104407 unmodified linesinput_background_fill="#251d2e",)with gr.Blocks(title="The Apprentice",analytics_enabled=False,) as demo:# Gradio 6 moved theme + css from Blocks() to launch() (verified by the# boot warning + TypeError chain on 2026-06-15). We stash both on the# demo object so main() can hand them to launch() without threading# extra positional args through.demo._apprentice_theme = _apprentice_themedemo._apprentice_css = composed_cssstate = gr.State(initial_state)trial_substate = gr.State(TRIAL_STATE_AWAIT)558 unmodified lines# ---------------------------------------------------------------------------# Entry point# ---------------------------------------------------------------------------def main() -> int:if "--self-test" in sys.argv:return run_self_test()demo = build_app()# Off-Brand sweep: suppress the "Use via API" sidebar + analytics# so the rendered page doesn't leak Gradio chrome. ``quiet=True``# would suppress the "Running on http://..." console banner, which# is useful info — leave it on.demo.launch(server_name="0.0.0.0",server_port=7860,# BISECT 1: theme + css temporarily disabled to see if the custom# theme or the 2000 lines of bespoke CSS is what's breaking Gradio 6's# iframe rendering. If the page renders without these, we know which# layer to fix. Once we find it, restore both.# theme=getattr(demo, "_apprentice_theme", None),# css=getattr(demo, "_apprentice_css", None),# Gradio 6 enables SSR by default (a Node.js proxy in front of the# Python ASGI app). SSR hydration fails inside HF's Space iframe and# leaves the App tab blank — same symptom that hit us on Gradio 5.# Force classic client-rendering so the iframe loads cleanly.ssr_mode=False,allowed_paths=[str(_HERE / "assets")],show_error=True,4407 unmodified lines44084409441044114412441344144415441644174418441944204421442244234424558 unmodified lines49834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250134407 unmodified linesinput_background_fill="#251d2e",)# Gradio 6 prefers theme + css on launch(), but HF Space's launcher# imports the module and runs its own launch() with defaults — anything# we set on our own launch() call is bypassed there. So we pass these# to gr.Blocks() despite the deprecation warning; that's the only path# Gradio actually reads on HF Space.with gr.Blocks(theme=_apprentice_theme,css=composed_css,title="The Apprentice",analytics_enabled=False,) as demo:state = gr.State(initial_state)trial_substate = gr.State(TRIAL_STATE_AWAIT)558 unmodified lines# ---------------------------------------------------------------------------# Entry point# ---------------------------------------------------------------------------## On HF Spaces, Gradio's launcher imports app.py as a module and looks for a# top-level ``demo`` variable to serve. If it doesn't find one, it falls back# to its own ``.launch()`` with DEFAULT settings — which means everything we# pass to ``demo.launch(...)`` below would be ignored (no theme, no css, no# ssr_mode=False, no allowed_paths). So we build the demo at module scope.## To keep --self-test fast (it doesn't need a Blocks instance, and building# one base64-encodes ~30 sprites), we skip the eager build when the flag is# present.if "--self-test" in sys.argv:demo = Noneelse:demo = build_app()def main() -> int:if "--self-test" in sys.argv:return run_self_test()# Local entry point — uses the module-level ``demo`` so the local run# matches the HF Space behavior exactly.demo.launch(server_name="0.0.0.0",server_port=7860,ssr_mode=False,allowed_paths=[str(_HERE / "assets")],show_error=True,
app.py+24-21