-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
60 lines (45 loc) · 1.3 KB
/
main.py
File metadata and controls
60 lines (45 loc) · 1.3 KB
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
52
53
54
55
56
57
58
59
60
"""Docling API - Document processing service."""
import logging
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.middleware.gzip import GZipMiddleware
from api.routes import router
from core.database import init_db
from core.error_handlers import init_error_handlers
from core.schemas import RootResponse
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s %(levelname)s [%(name)s] %(message)s",
)
logger = logging.getLogger("docling_api")
@asynccontextmanager
async def lifespan(app: FastAPI):
logger.info("Initializing database...")
await init_db()
logger.info("Database initialized")
yield
app = FastAPI(
title="Docling API",
description="Document processing API powered by Docling",
version="0.1.0",
lifespan=lifespan,
)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.add_middleware(GZipMiddleware, minimum_size=1024)
init_error_handlers(app)
app.include_router(router)
@app.get("/", response_model=RootResponse)
async def root():
"""API root endpoint with metadata."""
return RootResponse(
name="Docling API",
version="0.1.0",
docs="/docs",
)