2025-12-29 17:34:58 +08:00
|
|
|
"""FastAPI application entry point."""
|
|
|
|
|
|
|
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
|
|
|
|
|
|
from fastapi import FastAPI
|
|
|
|
|
|
|
|
|
|
from app.api.v1.router import api_router
|
|
|
|
|
from app.core.config import get_settings
|
|
|
|
|
from app.core.dependencies import init_layout_detector
|
|
|
|
|
|
|
|
|
|
settings = get_settings()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@asynccontextmanager
|
|
|
|
|
async def lifespan(app: FastAPI):
|
|
|
|
|
"""Application lifespan handler for startup/shutdown."""
|
|
|
|
|
# Startup: Load models
|
2025-12-31 17:38:32 +08:00
|
|
|
init_layout_detector()
|
2025-12-29 17:34:58 +08:00
|
|
|
|
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
|
# Shutdown: Cleanup happens automatically
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app = FastAPI(
|
|
|
|
|
title="DocProcesser API",
|
|
|
|
|
description="Document processing API - Image to LaTeX/Markdown/MathML and Markdown to DOCX",
|
|
|
|
|
version="0.1.0",
|
|
|
|
|
lifespan=lifespan,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Include API router
|
|
|
|
|
app.include_router(api_router, prefix=settings.api_prefix)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/health")
|
|
|
|
|
async def health_check():
|
|
|
|
|
"""Health check endpoint."""
|
|
|
|
|
return {"status": "healthy"}
|
2025-12-31 17:38:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
import uvicorn
|
|
|
|
|
uvicorn.run(app, host="0.0.0.0", port=8053)
|