""" Root app.py – HuggingFace Spaces entry point. Delegates directly to visualization/app.py. Run locally : streamlit run app.py HF Spaces : set "app_file: app.py" in README.md front-matter (default) """ import sys import importlib.util from pathlib import Path import streamlit as st ROOT = Path(__file__).resolve().parent APP_DIR = ROOT / "visualization" # ── Page config (must be the very first Streamlit call) ──────────────────────── st.set_page_config( page_title="Musora Sentiment Analysis", page_icon="📊", layout="wide", initial_sidebar_state="expanded", ) # Prevent visualization/app.py's module-level st.set_page_config() call from # raising an error – patch it to a no-op on the shared streamlit module object. import streamlit as _st_mod _st_mod.set_page_config = lambda *a, **kw: None # ── Ensure sub-app packages are importable ───────────────────────────────────── app_dir_str = str(APP_DIR) if app_dir_str not in sys.path: sys.path.insert(0, app_dir_str) # ── Load and run visualization/app.py ───────────────────────────────────────── spec = importlib.util.spec_from_file_location("_subapp", APP_DIR / "app.py") mod = importlib.util.module_from_spec(spec) try: spec.loader.exec_module(mod) # runs module-level code (config, auth, etc.) if hasattr(mod, "main"): mod.main() # renders the full dashboard except Exception as exc: if "Stop" in type(exc).__name__: # re-raise st.stop() for Streamlit's runner raise st.error(f"Dashboard error: {exc}") st.exception(exc)