""" app.py — Hugging Face Spaces entry point (Gradio SDK). Fixes: - strukctlog patched before main.py import (removes add_logger_name) - No gr.Blocks() wrapping needed — HF just needs app.py to bind port 7860 - FastAPI serves /demo, /ws, /analyze, /health directly """ from __future__ import annotations import os # Patch structlog BEFORE importing main.py (which calls structlog.configure) import structlog structlog.configure( processors=[ structlog.stdlib.add_log_level, structlog.processors.TimeStamper(fmt="iso"), structlog.dev.ConsoleRenderer(colors=False), ], wrapper_class=structlog.make_filtering_bound_logger(20), context_class=dict, logger_factory=structlog.PrintLoggerFactory(), ) # Import FastAPI app AFTER patching structlog from hf_main import app # noqa: E402 from fastapi.responses import RedirectResponse # Root → demo redirect @app.get("/", include_in_schema=False) async def _root(): return RedirectResponse(url="/demo") PORT = int(os.getenv("PORT", "7860")) if __name__ == "__main__": import uvicorn print(f"[fact-engine] Starting on :{PORT}") print(f"[fact-engine] Demo → http://0.0.0.0:{PORT}/demo") print(f"[fact-engine] WS → ws://0.0.0.0:{PORT}/ws/{{client_id}}") print(f"[fact-engine] Health → http://0.0.0.0:{PORT}/health") uvicorn.run( "app:app", host="0.0.0.0", port=PORT, log_level="info", ws_ping_interval=20, ws_ping_timeout=30, timeout_keep_alive=30, )