polats Claude Opus 4.8 (1M context) commited on
Commit
2a6b00d
·
1 Parent(s): f29c07a

Space: link shared sidebar.css unscoped via head (Gradio css_paths scopes selectors)

Browse files

Gradio prefixes css_paths/css= selectors with .gradio-container .contain, which
breaks body.tac-collapsed and .gradio-container rules (the slide + content-push).
Inject the shared stylesheet as a plain <link> in head instead — applied
verbatim, identical to the React app's source.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -23,9 +23,14 @@ _manifest = json.load(open(os.path.join(WEB, "assets", "characters.json")))
23
  CHARACTERS = [(c["name"], c["slug"]) for p in _manifest["packs"] for c in p["characters"]]
24
  ANIMS = ["idle", "walk", "attack", "dmg", "die"]
25
 
26
- HEAD = ('<script type="module" src="/web/tiny.js"></script>'
 
 
 
 
 
 
27
  '<script src="/web/shell/sidebar.js"></script>')
28
- SIDEBAR_CSS = os.path.join(WEB, "shell", "sidebar.css")
29
  STAGE = "height:56vh;border:1px solid #20262e;border-radius:12px;overflow:hidden;background:#0b0e12"
30
 
31
 
@@ -97,8 +102,7 @@ fastapi_app.mount("/web", StaticFiles(directory=WEB), name="web")
97
  # NOTE: serve sprite assets at /sprites, NOT /assets — Gradio serves its own UI
98
  # bundle from /assets, and mounting there shadows it (breaks the whole UI).
99
  fastapi_app.mount("/sprites", StaticFiles(directory=os.path.join(WEB, "assets")), name="sprites")
100
- app = gr.mount_gradio_app(fastapi_app, demo, path="/", head=HEAD,
101
- css_paths=[SIDEBAR_CSS], theme=gr.themes.Soft())
102
 
103
 
104
  if __name__ == "__main__":
 
23
  CHARACTERS = [(c["name"], c["slug"]) for p in _manifest["packs"] for c in p["characters"]]
24
  ANIMS = ["idle", "walk", "attack", "dmg", "die"]
25
 
26
+ # NOTE: link sidebar.css here (head) rather than via mount's css_paths — Gradio
27
+ # auto-scopes css_paths/css= selectors with a `.gradio-container .contain` prefix,
28
+ # which breaks rules that target <body> or .gradio-container itself (our slide +
29
+ # content-push). A plain <link> is injected unscoped, so the shared file applies
30
+ # verbatim — same stylesheet the React app uses.
31
+ HEAD = ('<link rel="stylesheet" href="/web/shell/sidebar.css">'
32
+ '<script type="module" src="/web/tiny.js"></script>'
33
  '<script src="/web/shell/sidebar.js"></script>')
 
34
  STAGE = "height:56vh;border:1px solid #20262e;border-radius:12px;overflow:hidden;background:#0b0e12"
35
 
36
 
 
102
  # NOTE: serve sprite assets at /sprites, NOT /assets — Gradio serves its own UI
103
  # bundle from /assets, and mounting there shadows it (breaks the whole UI).
104
  fastapi_app.mount("/sprites", StaticFiles(directory=os.path.join(WEB, "assets")), name="sprites")
105
+ app = gr.mount_gradio_app(fastapi_app, demo, path="/", head=HEAD, theme=gr.themes.Soft())
 
106
 
107
 
108
  if __name__ == "__main__":