53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
# SPDX-FileCopyrightText: 2026 James R. Barlow
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
"""Launch the OCRmyPDF batch web interface.
|
|
|
|
Usage::
|
|
|
|
python -m webui
|
|
|
|
Configuration is read from ``OCRMYPDF_WEBUI_*`` environment variables; see
|
|
``webui/README.md``.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
|
|
|
|
def main() -> int:
|
|
"""Run the ASGI server until interrupted."""
|
|
try:
|
|
import uvicorn
|
|
except ImportError:
|
|
sys.stderr.write(
|
|
"The web interface needs its extra dependencies:\n"
|
|
" uv sync --extra webui\n"
|
|
" # or: pip install 'fastapi' 'uvicorn[standard]' 'python-multipart'\n"
|
|
)
|
|
return 1
|
|
|
|
host = os.environ.get("OCRMYPDF_WEBUI_HOST", "0.0.0.0") # noqa: S104
|
|
port = int(os.environ.get("OCRMYPDF_WEBUI_PORT", "8000"))
|
|
|
|
# Deliberately single-process: batch state lives in this process's memory,
|
|
# so a second worker would not see batches created by the first. Scale by
|
|
# raising OCRMYPDF_WEBUI_WORKERS (OCR worker threads), not server workers.
|
|
uvicorn.run(
|
|
"webui.app:app",
|
|
host=host,
|
|
port=port,
|
|
workers=1,
|
|
access_log=False,
|
|
proxy_headers=True,
|
|
forwarded_allow_ips=os.environ.get("OCRMYPDF_WEBUI_FORWARDED_ALLOW_IPS", ""),
|
|
timeout_keep_alive=75,
|
|
)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|