- 新增 app/core/cache_paths.py:HF_HOME / tiktoken 缓存统一指向 <repo>/.cache, 本地与 Docker 路径一致,离线部署打包 .cache 即可 - Dockerfile.backend 的 tiktoken 词表改用官方 SHA 文件名,避免运行时回退重建 - 修复 layout_hybrid 路径不运行 detect_pdf_document_noise 的缺陷: needs_pdf_noise 不再与 needs_layout_raw 互斥,PDF 智能预处理在版面切分下也生效 - 新增 layout_noise.py:识别跨页重复的页眉表格标签组并按行剔除, 解决 docling layout 模型把中文企业 PDF 页眉识别成普通 Table 导致清不掉的问题 - 回收 HybridChunker 丢弃的末尾孤立标题,找回章节标题内容
49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
import asyncio
|
|
from contextlib import suppress
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.core.cache_paths import setup_local_caches
|
|
|
|
# 在任何 docling / tiktoken 模块被实例化之前设置缓存路径,避免首调用走到 ~/.cache。
|
|
setup_local_caches()
|
|
|
|
from app.api.v1.router import api_router # noqa: E402
|
|
from app.core.config import docs_kwargs, get_settings # noqa: E402
|
|
from app.core.logging import configure_logging, setup_request_logging # noqa: E402
|
|
from app.workers.compute_poller import run_compute_poller # noqa: E402
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
settings = get_settings()
|
|
configure_logging(settings)
|
|
|
|
app = FastAPI(title=settings.app_name, **docs_kwargs(settings.enable_docs))
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.cors_allow_origins,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
setup_request_logging(app)
|
|
app.include_router(api_router, prefix=settings.route_prefix)
|
|
|
|
@app.on_event("startup")
|
|
async def start_workers() -> None:
|
|
app.state.compute_poller_task = asyncio.create_task(run_compute_poller())
|
|
|
|
@app.on_event("shutdown")
|
|
async def stop_workers() -> None:
|
|
task = getattr(app.state, "compute_poller_task", None)
|
|
if task:
|
|
task.cancel()
|
|
with suppress(asyncio.CancelledError):
|
|
await task
|
|
|
|
return app
|
|
|
|
|
|
app = create_app()
|