AndrewRqy commited on
Commit ·
dd4200b
1
Parent(s): 7d8efb5
Add ORACLES_VISUAL_MODE toggle — lean default, full enabled via --full or env var
Browse filesFiles changed (3)
- Dockerfile+2-1
- app.py+101-49
- run.sh+21
28 unmodified lines29303132333428 unmodified linesENV GRADIO_SERVER_NAME=0.0.0.0 \GRADIO_SERVER_PORT=7860 \GRADIO_ANALYTICS_ENABLED=False \PYTHONUNBUFFERED=1CMD ["python", "app.py"]28 unmodified lines2930313233343528 unmodified linesENV GRADIO_SERVER_NAME=0.0.0.0 \GRADIO_SERVER_PORT=7860 \GRADIO_ANALYTICS_ENABLED=False \PYTHONUNBUFFERED=1 \ORACLES_VISUAL_MODE=leanCMD ["python", "app.py"]
74 unmodified lines757677787980217 unmodified lines298299300301302303304305306307308309310191 unmodified lines50250350450550650750850951051151232 unmodified lines545546547548549550551552553554555137 unmodified lines693694695696697698699700701702116 unmodified lines81982082182282382482582682782882983083183283383483583683774 unmodified lines9129139149159169179189199209219229239249252469 unmodified lines33953396339733983399340034013402340334043405340634073408340934103411341274 unmodified lines_GRIMOIRE_TEXTURE_PNG = _HERE / "assets" / "sprites" / "grimoire_page_texture.png"# ---------------------------------------------------------------------------# Pixel-art book frame: leather binding (via CSS border-image 9-slice), a# vertical spine with raised bands and stitching, and a red ribbon bookmark.217 unmodified linestexture as a background-image on .grimoire-page, if the PNG exists.Returns empty string otherwise (so the CSS-only gradients still apply).PERF: this currently returns "" unconditionally. The texture is ~70 KBbase64-inlined into the initial CSS. HF Space's slow egress made everycold load pay that cost. The PNG file stays on disk; re-enabling meansjust deleting the early return below."""return ""# ---- disabled — leaving the original implementation below ----if not _GRIMOIRE_TEXTURE_PNG.exists():return ""try:191 unmodified linesfor o in state.oracles:text = (o.text or "").strip() or blank_labelitems.append(f"<li><em>{_md_safe(text)}</em></li>")# PERF: skip the open-book illustration above the five-oracle summary.# The PNG was ~200-300 KB and added an extra slow HTTP fetch to the# closing-grimoire spread. The numbered list with the strong heading# carries the meaning on its own.book_img = ""header = _md_safe(_t("summary_five_sealed", lang))return ("<div class='grimoire-summary'>"32 unmodified lines# Pixel-art sprites + backdrop pre-loaded as data URIs. The# `_sprite_data_uri_app` helper caches per name, so reading the same# sprite twice in this function only hits disk once.# PERF: skip the demo card backdrop image. The PNG was the complex# painted background behind the wizard's three pipeline-mode dream# panels; ~200-400 KB. The panels still have their own CSS borders# and shading so the layout still reads.bg_style = ""tag_inscribes = _t("demo_tag_inscribes", lang)tag_meets = _t("demo_tag_meets", lang)tag_somehow = _t("demo_tag_somehow", lang)137 unmodified lines_sprite_data_uri_app(f"hero_{theme_key_for_sprites}")or _sprite_data_uri_app("hero"))# PERF: skip the wizard-desk backdrop image. The PNG is ~200-400 KB# and was being loaded behind the mentor/apprentice figures on the# front page. Replaced with a CSS gradient via empty desk_uri.desk_uri = ""if not wizard_uri or not hero_uri:fallback = ("<div class='oracle-inscribe-figs' style='text-align:center;"116 unmodified linesis_compact = mode in ("trial", "epilogue", "send_off")extra_cls = " oracle-banner-compact" if is_compact else ""# PERF: parallax PNG bypassed. The PNG is ~455 KB and was eating# 30+ seconds per first page-load over the HF Space's slow egress# bandwidth (~15 KB/s). Use the CSS-gradient fallback unconditionally.# The PNG file is left on disk so it can be restored later by removing# this hard-coded gradient branch.result = (f"<div class='oracle-banner{extra_cls}' style='background:""linear-gradient(180deg,var(--w-panel) 0%, var(--w-night) 100%);'>""<div class='oracle-banner-overlay'>"f"<div class='oracle-banner-title'>{title}</div>"f"<div class='oracle-banner-sub'>{subtitle}</div>""</div></div>")_BANNER_HTML_CACHE[cache_key] = resultreturn result74 unmodified linesdef _phase_backdrop_styles_html() -> str:"""One-time ``<style>`` block wiring per-phase pixel-art ambient textures.PERF: disabled. The four backdrop PNGs were 200-500 KB each and gotfetched on first paint of the matching phase. CSS gradients elsewherein the stylesheet still apply on the phase Groups. Sprites stay ondisk; re-enable by removing the early return."""return ""def _theme_style_overrides_html(state: Optional[GameState] = None) -> str:2469 unmodified linesreturn landscapereturn _sprite_data_uri_app(category) or ""# PERF: skip the env (landscape) backdrop. Each scene_<theme>_landscape# PNG is ~200-500 KB and triggers an extra HTTP request that's slow over# HF Space's egress. The hero + obstacle sprites still load (small,# narratively essential). The scene gets a CSS-gradient sky instead.env_uri = ""hero_uri = _theme_pick("hero")ob_uri = _theme_pick(ob_name) if ob_name else ""# No early bailout — we now always render the composed scene with a# CSS-gradient backdrop, even with env_uri empty. Hero + obstacle# carry the visual load.dragon_attr = ' data-dragon="true"' if is_dragon else ""hero_img = (f"<img class='scene-hero' src='{hero_uri}' alt='hero'/>"74 unmodified lines7576777879808182838485868788899091929394959697217 unmodified lines315316317318319320321322323324325326191 unmodified lines51851952052152252352452552652752852953053153253353453553632 unmodified lines569570571572573574575576577578579580581582137 unmodified lines720721722723724725726727728729116 unmodified lines84684784884985085185285385485585685785885986086186286386486586686786886987087187287374 unmodified lines9489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809812469 unmodified lines3451345234533454345534563457345834593460346134623463346474 unmodified lines_GRIMOIRE_TEXTURE_PNG = _HERE / "assets" / "sprites" / "grimoire_page_texture.png"def _full_visual_mode() -> bool:"""Visual-mode toggle. Read from $ORACLES_VISUAL_MODE on every call soit stays accurate across reloads.- ``lean`` (default, HF Space): skip heavy decorative PNGs — parallaxbanner, grimoire parchment, the four phase backdrops, the scenelandscapes, the wizard-desk backdrop, the open-book illustration,and the pipeline-demo card backdrop. Total saving: ~2-3 MB percold load on HF Space's slow egress bandwidth.- ``full``: enable everything. Use locally where bandwidth is fast.To run locally in full mode: ``ORACLES_VISUAL_MODE=full ./run.sh``or pass ``--full`` to ``run.sh`` (which sets the env var)."""return os.environ.get("ORACLES_VISUAL_MODE", "lean").strip().lower() == "full"# ---------------------------------------------------------------------------# Pixel-art book frame: leather binding (via CSS border-image 9-slice), a# vertical spine with raised bands and stitching, and a red ribbon bookmark.217 unmodified linestexture as a background-image on .grimoire-page, if the PNG exists.Returns empty string otherwise (so the CSS-only gradients still apply).Skipped entirely in lean mode (default) — the texture is ~70 KBbase64-inlined into the initial CSS, which on HF Space's slow egressadds noticeable cold-load time. Set ORACLES_VISUAL_MODE=full to enable."""if not _full_visual_mode():return ""if not _GRIMOIRE_TEXTURE_PNG.exists():return ""try:191 unmodified linesfor o in state.oracles:text = (o.text or "").strip() or blank_labelitems.append(f"<li><em>{_md_safe(text)}</em></li>")# Lean mode (default for HF Space): skip the open-book illustration —# the PNG was ~200-300 KB. The heading + numbered list carry the# meaning. Full mode restores the illustration above the list.if _full_visual_mode():book_uri = _sprite_data_uri_app("open_book_spread")alt_text = _t("alt_sealed_grimoire", lang)book_img = (f"<img class='grimoire-summary-book' src='{book_uri}' "f"alt='{_md_safe(alt_text)}'/>"if book_uri else "")else:book_img = ""header = _md_safe(_t("summary_five_sealed", lang))return ("<div class='grimoire-summary'>"32 unmodified lines# Pixel-art sprites + backdrop pre-loaded as data URIs. The# `_sprite_data_uri_app` helper caches per name, so reading the same# sprite twice in this function only hits disk once.# Lean mode (default for HF Space): skip the demo card painted# backdrop (~200-400 KB). Panels still have CSS borders + shading.# Full mode restores the painted background.if _full_visual_mode():bg = _sprite_data_uri_app("demo_card_backdrop")bg_style = f"background-image:url('{bg}');" if bg else ""else:bg_style = ""tag_inscribes = _t("demo_tag_inscribes", lang)tag_meets = _t("demo_tag_meets", lang)tag_somehow = _t("demo_tag_somehow", lang)137 unmodified lines_sprite_data_uri_app(f"hero_{theme_key_for_sprites}")or _sprite_data_uri_app("hero"))# Lean mode (default for HF Space): skip the wizard-desk backdrop —# the PNG is ~200-400 KB. Full mode restores it as a fade-behind# layer for the mentor/apprentice figures.desk_uri = _sprite_data_uri_app("wizard_desk_scene") if _full_visual_mode() else ""if not wizard_uri or not hero_uri:fallback = ("<div class='oracle-inscribe-figs' style='text-align:center;"116 unmodified linesis_compact = mode in ("trial", "epilogue", "send_off")extra_cls = " oracle-banner-compact" if is_compact else ""# Lean mode (default for HF Space): use a CSS gradient instead of the# ~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()}"result = (f"<div class='oracle-banner{extra_cls}'>"f"<img src='{src}' alt='banner'/>""<div class='oracle-banner-overlay'>"f"<div class='oracle-banner-title'>{title}</div>"f"<div class='oracle-banner-sub'>{subtitle}</div>""</div></div>")else:result = (f"<div class='oracle-banner{extra_cls}' style='background:""linear-gradient(180deg,var(--w-panel) 0%, var(--w-night) 100%);'>""<div class='oracle-banner-overlay'>"f"<div class='oracle-banner-title'>{title}</div>"f"<div class='oracle-banner-sub'>{subtitle}</div>""</div></div>")_BANNER_HTML_CACHE[cache_key] = resultreturn result74 unmodified linesdef _phase_backdrop_styles_html() -> str:"""One-time ``<style>`` block (built at app startup) that wires theper-phase pixel-art ambient textures onto the phase Group wrappers viatheir ``elem_id`` attributes. Returns an empty string if any expectedtexture is missing from disk OR if visual mode is lean.Mapping:#oracle-inscribe-grp ← grimoire_cover_texture#oracle-send-off-grp ← stormy_plain_texture#oracle-trial-grp ← night_sky_texture#oracle-epilogue-grp ← forest_dusk_texture"""if not _full_visual_mode():return ""mapping = {"oracle-inscribe-grp": "grimoire_cover_texture","oracle-send-off-grp": "stormy_plain_texture","oracle-trial-grp": "night_sky_texture","oracle-epilogue-grp": "forest_dusk_texture",}rules = []for elem_id, sprite_name in mapping.items():uri = _sprite_data_uri_app(sprite_name)if not uri:continuerules.append(f"#{elem_id} {{ background-image: url('{uri}') !important; }}")if not rules:return ""return "<style data-phase-backdrops>\n" + "\n".join(rules) + "\n</style>"def _theme_style_overrides_html(state: Optional[GameState] = None) -> str:2469 unmodified linesreturn landscapereturn _sprite_data_uri_app(category) or ""# Lean mode (default for HF Space): skip the env (landscape) backdrop# — each scene_<theme>_landscape PNG is ~200-500 KB and slow over HF's# egress. The hero + obstacle sprites still load and the panel uses a# CSS gradient sky. Full mode restores the landscape.env_uri = _theme_pick(env_name, is_env=True) if _full_visual_mode() else ""hero_uri = _theme_pick("hero")ob_uri = _theme_pick(ob_name) if ob_name else ""dragon_attr = ' data-dragon="true"' if is_dragon else ""hero_img = (f"<img class='scene-hero' src='{hero_uri}' alt='hero'/>"
18 unmodified lines1920212223242526272824 unmodified lines5354555657584 unmodified lines63646566676818 unmodified lines# under DIR (default: ./traces/). Drop the file into# an HF dataset repo for the Sharing-is-Caring badge.# --self-test Pass-through to app.py for the scripted walkthrough.## Env vars:# ORACLES_LLM_MODEL=llm request base model# ORACLES_LLM_MODEL=oracle-wizard-lora (default) request fine-tune# KEEP_LLM_WARM=1 keep Modal LLM running# ORACLES_GGUF_PATH=/path/to/model.gguf used in --local-llama mode# ORACLES_LOCAL_LLAMA_PORT=8080 (default) llama-server port24 unmodified lines--local-llama) USE_LOCAL_LLAMA="1" ;;--save-trace) SAVE_TRACE_DIR="./traces" ;;--save-trace=*) SAVE_TRACE_DIR="${arg#--save-trace=}" ;;*) APP_ARGS+=("$arg") ;;esacdone4 unmodified linesecho "[run.sh] --save-trace: appending LLM exchanges to $SAVE_TRACE_DIR/oracles-trace-<session>.jsonl"fi# -----------------------------------------------------------------------------# Load .env.local — look in both the project root and oracles_app/ so# shared credentials are picked up.18 unmodified lines192021222324252627282930313233343536373824 unmodified lines63646566676869704 unmodified lines75767778798081828384858687888918 unmodified lines# under DIR (default: ./traces/). Drop the file into# an HF dataset repo for the Sharing-is-Caring badge.# --self-test Pass-through to app.py for the scripted walkthrough.# --full Enable ALL decorative PNGs (parallax banner,# parchment, phase backdrops, scene landscapes,# wizard-desk, open-book, demo-card backdrop).# Recommended for local runs on fast connections.# --lean (default) Skip the heavy decorative PNGs. Used by# the HF Space deployment because its egress# bandwidth (~15 KB/s) makes the full set add# multi-megabytes to every cold load.## Env vars:# ORACLES_LLM_MODEL=llm request base model# ORACLES_LLM_MODEL=oracle-wizard-lora (default) request fine-tune# ORACLES_VISUAL_MODE=full same as --full# ORACLES_VISUAL_MODE=lean (default) same as --lean# KEEP_LLM_WARM=1 keep Modal LLM running# ORACLES_GGUF_PATH=/path/to/model.gguf used in --local-llama mode# ORACLES_LOCAL_LLAMA_PORT=8080 (default) llama-server port24 unmodified lines--local-llama) USE_LOCAL_LLAMA="1" ;;--save-trace) SAVE_TRACE_DIR="./traces" ;;--save-trace=*) SAVE_TRACE_DIR="${arg#--save-trace=}" ;;--full) export ORACLES_VISUAL_MODE="full" ;;--lean) export ORACLES_VISUAL_MODE="lean" ;;*) APP_ARGS+=("$arg") ;;esacdone4 unmodified linesecho "[run.sh] --save-trace: appending LLM exchanges to $SAVE_TRACE_DIR/oracles-trace-<session>.jsonl"fi# Visual-mode banner. The app defaults to lean; --full overrides for local# bandwidth-rich runs that want the parallax banner, parchment texture,# phase backdrops, scene landscapes, etc.if [ "${ORACLES_VISUAL_MODE:-lean}" = "full" ]; thenecho "[run.sh] --full: ORACLES_VISUAL_MODE=full (all PNGs / textures / backdrops enabled)"elseecho "[run.sh] lean mode (default) — pass --full to enable all visuals"fi# -----------------------------------------------------------------------------# Load .env.local — look in both the project root and oracles_app/ so# shared credentials are picked up.
Dockerfile+2-1
app.py+101-49
run.sh+21