"""Hugging Face Spaces entrypoint for Pensieve.""" import logging import os import sys from pathlib import Path from dotenv import load_dotenv logging.basicConfig( level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s: %(message)s" ) # Load .env for local dev BEFORE importing config (which reads env at import time). # On Spaces there's no .env, so this is a no-op and the injected secrets are used. load_dotenv(Path(__file__).parent / ".env") # Make `pensieve` importable even when src/ isn't installed (e.g. on Spaces). sys.path.insert(0, str(Path(__file__).parent / "src")) from pensieve.theme import CSS, HEAD, THEME # noqa: E402 from pensieve.ui import build_app # noqa: E402 demo = build_app() # A PNG favicon makes Gradio's PWA manifest serve resized home-screen icons via /pwa_icon. _ICON = Path(__file__).parent / "assets" / "icon.png" if __name__ == "__main__": # Gradio 6 takes theme/css/head on launch(), not on Blocks. pwa=True emits a manifest + # service worker so the app installs to the home screen like a native iOS app. # server_name=0.0.0.0 binds all interfaces so other devices on the LAN can reach it # (Gradio otherwise defaults to localhost-only). # GRADIO_SHARE=1 opens a public *.gradio.live HTTPS tunnel — needed to test mic capture # on a phone, since getUserMedia requires a secure context (HTTPS or localhost) and the # LAN http:// URL isn't one. Off by default so it never affects the Spaces deploy. demo.launch( theme=THEME, css=CSS, head=HEAD, pwa=True, favicon_path=str(_ICON), # SSR (auto-enabled on Spaces because Node is present) renders the custom theme/CSS # incorrectly here: the record button loses its red and the segmented radios show as # raw inputs. Client-side rendering matches local exactly, so force SSR off. ssr_mode=False, server_name="0.0.0.0", # Explicit truthy parse: bool("0")/bool("false") are both True, so a plain # bool() of the env string would keep the public tunnel open on GRADIO_SHARE=0. share=os.environ.get("GRADIO_SHARE", "").strip().lower() in {"1", "true", "yes", "on"}, )