AndrewRqy commited on
Commit ·
a140b54
1
Parent(s): 49ded6b
URL-encode sprite paths so spaces in dev path don't truncate <img src>
Browse files
app.py
CHANGED
|
@@ -17,6 +17,7 @@ from __future__ import annotations
|
|
| 17 |
import base64
|
| 18 |
import os
|
| 19 |
import sys
|
|
|
|
| 20 |
from pathlib import Path
|
| 21 |
from typing import Optional
|
| 22 |
|
|
@@ -390,7 +391,12 @@ def _sprite_data_uri_app(name: str) -> str:
|
|
| 390 |
# The /gradio_api/file= path works on 5+; legacy /file= works on 4.x.
|
| 391 |
# _FILE_URL_PREFIX is computed once at module load based on
|
| 392 |
# gr.__version__.
|
| 393 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 394 |
cache[name] = uri
|
| 395 |
return uri
|
| 396 |
|
|
@@ -862,7 +868,7 @@ def _banner_html(state: Optional[GameState] = None) -> str:
|
|
| 862 |
# ~455 KB parallax PNG. Full mode loads the PNG via Gradio's file
|
| 863 |
# route so the browser caches it after the first request.
|
| 864 |
if _full_visual_mode() and _PARALLAX_PNG.exists():
|
| 865 |
-
src = f"{_FILE_URL_PREFIX}{_PARALLAX_PNG.as_posix()}"
|
| 866 |
result = (
|
| 867 |
f"<div class='oracle-banner{extra_cls}'>"
|
| 868 |
f"<img src='{src}' alt='banner'/>"
|
|
|
|
| 17 |
import base64
|
| 18 |
import os
|
| 19 |
import sys
|
| 20 |
+
from urllib.parse import quote as _url_quote
|
| 21 |
from pathlib import Path
|
| 22 |
from typing import Optional
|
| 23 |
|
|
|
|
| 391 |
# The /gradio_api/file= path works on 5+; legacy /file= works on 4.x.
|
| 392 |
# _FILE_URL_PREFIX is computed once at module load based on
|
| 393 |
# gr.__version__.
|
| 394 |
+
#
|
| 395 |
+
# URL-encode the path so any spaces or special chars (e.g. the
|
| 396 |
+
# "CHAI Project" path on the dev machine) survive the trip through
|
| 397 |
+
# an HTML <img src=…> attribute. safe="/" preserves the path
|
| 398 |
+
# separators which browsers + Gradio's route both need verbatim.
|
| 399 |
+
uri = f"{_FILE_URL_PREFIX}{_url_quote(path.as_posix(), safe='/')}"
|
| 400 |
cache[name] = uri
|
| 401 |
return uri
|
| 402 |
|
|
|
|
| 868 |
# ~455 KB parallax PNG. Full mode loads the PNG via Gradio's file
|
| 869 |
# route so the browser caches it after the first request.
|
| 870 |
if _full_visual_mode() and _PARALLAX_PNG.exists():
|
| 871 |
+
src = f"{_FILE_URL_PREFIX}{_url_quote(_PARALLAX_PNG.as_posix(), safe='/')}"
|
| 872 |
result = (
|
| 873 |
f"<div class='oracle-banner{extra_cls}'>"
|
| 874 |
f"<img src='{src}' alt='banner'/>"
|