mirror of
https://github.com/docling-project/docling-serve.git
synced 2025-11-29 08:33:50 +00:00
feat: display version in fastapi docs (#78)
Signed-off-by: Eugene <fogaprod@gmail.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import importlib
|
import importlib.metadata
|
||||||
import logging
|
import logging
|
||||||
import platform
|
import platform
|
||||||
import sys
|
import sys
|
||||||
@@ -51,9 +51,7 @@ def version_callback(value: bool) -> None:
|
|||||||
def callback(
|
def callback(
|
||||||
version: Annotated[
|
version: Annotated[
|
||||||
Union[bool, None],
|
Union[bool, None],
|
||||||
typer.Option(
|
typer.Option(help="Show the version and exit.", callback=version_callback),
|
||||||
"--version", help="Show the version and exit.", callback=version_callback
|
|
||||||
),
|
|
||||||
] = None,
|
] = None,
|
||||||
verbose: Annotated[
|
verbose: Annotated[
|
||||||
int,
|
int,
|
||||||
@@ -298,5 +296,4 @@ def main() -> None:
|
|||||||
|
|
||||||
# Launch the CLI when calling python -m docling_serve
|
# Launch the CLI when calling python -m docling_serve
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import importlib.metadata
|
||||||
import logging
|
import logging
|
||||||
import tempfile
|
import tempfile
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
@@ -60,7 +61,6 @@ _log = logging.getLogger(__name__)
|
|||||||
# Context manager to initialize and clean up the lifespan of the FastAPI app
|
# Context manager to initialize and clean up the lifespan of the FastAPI app
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def lifespan(app: FastAPI):
|
async def lifespan(app: FastAPI):
|
||||||
|
|
||||||
# Converter with default options
|
# Converter with default options
|
||||||
pdf_format_option, options_hash = get_pdf_pipeline_opts(ConvertDocumentsOptions())
|
pdf_format_option, options_hash = get_pdf_pipeline_opts(ConvertDocumentsOptions())
|
||||||
converters[options_hash] = DocumentConverter(
|
converters[options_hash] = DocumentConverter(
|
||||||
@@ -85,9 +85,17 @@ async def lifespan(app: FastAPI):
|
|||||||
|
|
||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
|
try:
|
||||||
|
version = importlib.metadata.version("docling_serve")
|
||||||
|
except importlib.metadata.PackageNotFoundError:
|
||||||
|
_log.warning("Unable to get docling_serve version, falling back to 0.0.0")
|
||||||
|
|
||||||
|
version = "0.0.0"
|
||||||
|
|
||||||
app = FastAPI(
|
app = FastAPI(
|
||||||
title="Docling Serve",
|
title="Docling Serve",
|
||||||
lifespan=lifespan,
|
lifespan=lifespan,
|
||||||
|
version=version,
|
||||||
)
|
)
|
||||||
|
|
||||||
origins = ["*"]
|
origins = ["*"]
|
||||||
@@ -104,7 +112,6 @@ def create_app():
|
|||||||
|
|
||||||
# Mount the Gradio app
|
# Mount the Gradio app
|
||||||
if docling_serve_settings.enable_ui:
|
if docling_serve_settings.enable_ui:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import gradio as gr
|
import gradio as gr
|
||||||
|
|
||||||
@@ -207,7 +214,6 @@ def create_app():
|
|||||||
ConvertDocumentsOptions, FormDepends(ConvertDocumentsOptions)
|
ConvertDocumentsOptions, FormDepends(ConvertDocumentsOptions)
|
||||||
],
|
],
|
||||||
):
|
):
|
||||||
|
|
||||||
_log.info(f"Received {len(files)} files for processing.")
|
_log.info(f"Received {len(files)} files for processing.")
|
||||||
|
|
||||||
# Load the uploaded files to Docling DocumentStream
|
# Load the uploaded files to Docling DocumentStream
|
||||||
|
|||||||
2
uv.lock
generated
2
uv.lock
generated
@@ -535,7 +535,7 @@ wheels = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "docling-serve"
|
name = "docling-serve"
|
||||||
version = "0.3.0"
|
version = "0.4.0"
|
||||||
source = { editable = "." }
|
source = { editable = "." }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "docling" },
|
{ name = "docling" },
|
||||||
|
|||||||
Reference in New Issue
Block a user