File size: 1,552 Bytes
f589dab
f09b792
f589dab
b745981
e2e35f6
b745981
 
f589dab
 
f09b792
 
b745981
 
 
 
 
 
 
 
 
 
 
f09b792
 
b745981
 
f09b792
 
b745981
 
 
f09b792
 
b745981
f09b792
 
b745981
 
 
 
 
f09b792
b745981
f09b792
 
 
 
 
 
f589dab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
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,
    )