AndrewRqy commited on
Commit ·
a140b54
1
Parent(s): 49ded6b
URL-encode sprite paths so spaces in dev path don't truncate <img src>
Browse files16 unmodified lines171819202122367 unmodified lines390391392393394395396465 unmodified lines86286386486586686786816 unmodified linesimport base64import osimport sysfrom pathlib import Pathfrom typing import Optional367 unmodified lines# The /gradio_api/file= path works on 5+; legacy /file= works on 4.x.# _FILE_URL_PREFIX is computed once at module load based on# gr.__version__.uri = f"{_FILE_URL_PREFIX}{path.as_posix()}"cache[name] = urireturn uri465 unmodified lines# ~455 KB parallax PNG. Full mode loads the PNG via Gradio's file# route so the browser caches it after the first request.if _full_visual_mode() and _PARALLAX_PNG.exists():src = f"{_FILE_URL_PREFIX}{_PARALLAX_PNG.as_posix()}"result = (f"<div class='oracle-banner{extra_cls}'>"f"<img src='{src}' alt='banner'/>"16 unmodified lines17181920212223367 unmodified lines391392393394395396397398399400401402465 unmodified lines86886987087187287387416 unmodified linesimport base64import osimport sysfrom urllib.parse import quote as _url_quotefrom pathlib import Pathfrom typing import Optional367 unmodified lines# The /gradio_api/file= path works on 5+; legacy /file= works on 4.x.# _FILE_URL_PREFIX is computed once at module load based on# gr.__version__.## URL-encode the path so any spaces or special chars (e.g. the# "CHAI Project" path on the dev machine) survive the trip through# an HTML <img src=…> attribute. safe="/" preserves the path# separators which browsers + Gradio's route both need verbatim.uri = f"{_FILE_URL_PREFIX}{_url_quote(path.as_posix(), safe='/')}"cache[name] = urireturn uri465 unmodified lines# ~455 KB parallax PNG. Full mode loads the PNG via Gradio's file# route so the browser caches it after the first request.if _full_visual_mode() and _PARALLAX_PNG.exists():src = f"{_FILE_URL_PREFIX}{_url_quote(_PARALLAX_PNG.as_posix(), safe='/')}"result = (f"<div class='oracle-banner{extra_cls}'>"f"<img src='{src}' alt='banner'/>"
app.py+8-2