Spaces:
Running
Running
Space: fix mixed-content fonts (upgrade-insecure-requests + proxy_headers) and self-style collapse/reopen buttons
Browse filesCustom domain served Gradio's theme.css over http:// (proxy didn't signal HTTPS),
blocked as mixed content -> theme font fell back to Arial. Add a CSP
upgrade-insecure-requests meta + uvicorn proxy_headers so assets load over https.
The collapse/reopen <button>s leaned on Gradio's leaked button styling for their
background; with theme.css blocked they rendered bare. Give them a self-contained
icon-button look in the shared sidebar.css, defended with !important against the
host button reset.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- app.py +11 -2
- web/shell/sidebar.css +19 -9
app.py
CHANGED
|
@@ -28,7 +28,13 @@ ANIMS = ["idle", "walk", "attack", "dmg", "die"]
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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"
|
|
@@ -106,4 +112,7 @@ app = gr.mount_gradio_app(fastapi_app, demo, path="/", head=HEAD, theme=gr.theme
|
|
| 106 |
|
| 107 |
|
| 108 |
if __name__ == "__main__":
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# `upgrade-insecure-requests`: behind HF's custom-domain proxy Gradio emits its
|
| 32 |
+
# theme.css link as http:// (the app doesn't see HTTPS), which the HTTPS page
|
| 33 |
+
# blocks as mixed content — so the theme font never loads. This CSP upgrades such
|
| 34 |
+
# same-host http subresources to https in the browser, fixing it deterministically
|
| 35 |
+
# regardless of proxy headers.
|
| 36 |
+
HEAD = ('<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">'
|
| 37 |
+
'<link rel="stylesheet" href="/web/shell/sidebar.css">'
|
| 38 |
'<script type="module" src="/web/tiny.js"></script>'
|
| 39 |
'<script src="/web/shell/sidebar.js"></script>')
|
| 40 |
STAGE = "height:56vh;border:1px solid #20262e;border-radius:12px;overflow:hidden;background:#0b0e12"
|
|
|
|
| 112 |
|
| 113 |
|
| 114 |
if __name__ == "__main__":
|
| 115 |
+
# proxy_headers + trusting forwarded IPs lets Gradio honour X-Forwarded-Proto
|
| 116 |
+
# from HF's edge, so it generates https (not http) asset URLs behind the proxy.
|
| 117 |
+
uvicorn.run(app, host="0.0.0.0", port=7860,
|
| 118 |
+
proxy_headers=True, forwarded_allow_ips="*")
|
web/shell/sidebar.css
CHANGED
|
@@ -38,11 +38,20 @@ body:not(.tac-collapsed) .gradio-container { margin-left: var(--tac-w); }
|
|
| 38 |
border-bottom: 1px solid var(--tac-border);
|
| 39 |
}
|
| 40 |
.tac-brand .tac-brand-icon { font-size: 18px; }
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
}
|
| 45 |
-
.tac-brand .tac-collapse:hover { background: var(--tac-bg-2); color: var(--tac-ink); }
|
| 46 |
|
| 47 |
.tac-section { padding: 10px 8px 0; }
|
| 48 |
.tac-section-title {
|
|
@@ -63,12 +72,13 @@ body:not(.tac-collapsed) .gradio-container { margin-left: var(--tac-w); }
|
|
| 63 |
.tac-sidebar .tac-nav-item.active { background: color-mix(in srgb, var(--tac-accent) 22%, transparent); }
|
| 64 |
.tac-sidebar .tac-nav-item .tac-ico { width: 18px; text-align: center; opacity: .9; }
|
| 65 |
|
| 66 |
-
/* Edge tab to reopen when collapsed. */
|
| 67 |
.tac-reopen {
|
| 68 |
-
position: fixed; top: 12px; left: 0; z-index: 1001;
|
| 69 |
-
|
| 70 |
-
border: 1px solid var(--tac-border); border-left: 0;
|
| 71 |
-
border-radius: 0 8px 8px 0; padding: 8px 10px
|
|
|
|
| 72 |
}
|
| 73 |
body.tac-collapsed .tac-reopen { display: block; }
|
| 74 |
|
|
|
|
| 38 |
border-bottom: 1px solid var(--tac-border);
|
| 39 |
}
|
| 40 |
.tac-brand .tac-brand-icon { font-size: 18px; }
|
| 41 |
+
/* The collapse/reopen controls are <button>s; a host button theme (Gradio's
|
| 42 |
+
* `.gradio-container button` reset) strips their padding/background. We define a
|
| 43 |
+
* self-contained icon-button look and defend the visual props with `!important`
|
| 44 |
+
* so it renders identically with or without the host theme. */
|
| 45 |
+
.tac-sidebar .tac-brand .tac-collapse {
|
| 46 |
+
margin-left: auto; cursor: pointer; line-height: 1; font-size: 16px;
|
| 47 |
+
display: inline-flex !important; align-items: center; justify-content: center;
|
| 48 |
+
width: 28px; height: 28px; padding: 0 !important;
|
| 49 |
+
background: var(--tac-bg-2) !important; color: var(--tac-muted) !important;
|
| 50 |
+
border: 1px solid var(--tac-border) !important; border-radius: 6px !important;
|
| 51 |
+
}
|
| 52 |
+
.tac-sidebar .tac-brand .tac-collapse:hover {
|
| 53 |
+
background: #1a2027 !important; color: var(--tac-ink) !important;
|
| 54 |
}
|
|
|
|
| 55 |
|
| 56 |
.tac-section { padding: 10px 8px 0; }
|
| 57 |
.tac-section-title {
|
|
|
|
| 72 |
.tac-sidebar .tac-nav-item.active { background: color-mix(in srgb, var(--tac-accent) 22%, transparent); }
|
| 73 |
.tac-sidebar .tac-nav-item .tac-ico { width: 18px; text-align: center; opacity: .9; }
|
| 74 |
|
| 75 |
+
/* Edge tab to reopen when collapsed. Same host-button defence as above. */
|
| 76 |
.tac-reopen {
|
| 77 |
+
position: fixed; top: 12px; left: 0; z-index: 1001; display: none;
|
| 78 |
+
background: var(--tac-bg) !important; color: var(--tac-ink) !important;
|
| 79 |
+
border: 1px solid var(--tac-border) !important; border-left: 0 !important;
|
| 80 |
+
border-radius: 0 8px 8px 0 !important; padding: 8px 10px !important;
|
| 81 |
+
cursor: pointer; font-size: 14px; line-height: 1;
|
| 82 |
}
|
| 83 |
body.tac-collapsed .tac-reopen { display: block; }
|
| 84 |
|