| """ |
| 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 |
|
|
| |
| 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(), |
| ) |
|
|
| |
| from hf_main import app |
| from fastapi.responses import RedirectResponse |
|
|
| |
| @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, |
| ) |
|
|