AndrewRqy commited on
Commit ·
49ded6b
1
Parent(s): 26f70c8
Version-aware Gradio file route — /file= on 4.x, /gradio_api/file= on 5+
Browse files355 unmodified lines35635735835936036136236336436536636736836937037137213 unmodified lines386387388378379380381389390391392393394395396465 unmodified lines862863864853865866867868355 unmodified lines_ROMAN = {1: "I", 2: "II", 3: "III", 4: "IV", 5: "V"}
# Gradio file-route URL prefix. Differs between major versions:# - Gradio 4.x → "/file="# - Gradio 5.x and 6.x → "/gradio_api/file="# Computed once at module load; cheap to read.try: _GRADIO_MAJOR = int(gr.__version__.split(".", 1)[0])except Exception: _GRADIO_MAJOR = 5_FILE_URL_PREFIX = "/file=" if _GRADIO_MAJOR < 5 else "/gradio_api/file="
def _sprite_data_uri_app(name: str) -> str: """Return a URL to the sprite. Used everywhere a CSS ``url(...)`` or ``<img src=...>`` needs the sprite. Originally returned a base64 data13 unmodified lines if not path.exists(): cache[name] = "" return "" # Gradio 5 serves static files at /gradio_api/file=<absolute-path>. # This works because we call gr.set_static_paths(assets) at module # scope below — the file route checks against that allowlist. uri = f"/gradio_api/file={path.as_posix()}" # Gradio's file route prefix depends on the running major version. # 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] = uri return uri
465 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"/gradio_api/file={_PARALLAX_PNG.as_posix()}" src = f"{_FILE_URL_PREFIX}{_PARALLAX_PNG.as_posix()}" result = ( f"<div class='oracle-banner{extra_cls}'>" f"<img src='{src}' alt='banner'/>"app.py+17-5