BolyosCsaba commited on
Commit ยท
469018d
1
Parent(s): 2fa6c59
fix: use file-served iframe src instead of srcdoc
Browse filessrcdoc iframes inherit parent CSP which blocks CDN scripts on HF Spaces.
Now writes studio HTML to sandbox_cache/studio_<hash>.html and loads it
via iframe src=/gradio_api/file=... (same origin, no CSP issues).
- .gitignore +1 -0
- app.py +7 -5
.gitignore
CHANGED
|
@@ -3,3 +3,4 @@ __pycache__/
|
|
| 3 |
result/
|
| 4 |
*.pyc
|
| 5 |
.DS_Store
|
|
|
|
|
|
| 3 |
result/
|
| 4 |
*.pyc
|
| 5 |
.DS_Store
|
| 6 |
+
sandbox_cache/studio_*.html
|
app.py
CHANGED
|
@@ -87,13 +87,15 @@ BRIDGE_JS = """
|
|
| 87 |
|
| 88 |
|
| 89 |
def _wrap_in_iframe(studio_html: str) -> str:
|
| 90 |
-
"""
|
| 91 |
-
import
|
| 92 |
-
|
|
|
|
|
|
|
| 93 |
return (
|
| 94 |
-
f'<iframe id="ivds-studio-iframe"
|
| 95 |
f'style="width:100%;height:600px;border:none;border-radius:8px;background:#1a1a2e" '
|
| 96 |
-
f'allow="autoplay"
|
| 97 |
)
|
| 98 |
|
| 99 |
# โโ Background temp-dir cleanup daemon โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
|
|
| 87 |
|
| 88 |
|
| 89 |
def _wrap_in_iframe(studio_html: str) -> str:
|
| 90 |
+
"""Write studio HTML to a file and return an iframe loading it via src."""
|
| 91 |
+
import hashlib
|
| 92 |
+
key = hashlib.md5(studio_html[:200].encode()).hexdigest()[:8]
|
| 93 |
+
filename = f"sandbox_cache/studio_{key}.html"
|
| 94 |
+
Path(filename).write_text(studio_html)
|
| 95 |
return (
|
| 96 |
+
f'<iframe id="ivds-studio-iframe" src="/gradio_api/file={filename}" '
|
| 97 |
f'style="width:100%;height:600px;border:none;border-radius:8px;background:#1a1a2e" '
|
| 98 |
+
f'allow="autoplay"></iframe>'
|
| 99 |
)
|
| 100 |
|
| 101 |
# โโ Background temp-dir cleanup daemon โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|