From 42b340555406e6128c139e620b8b3953fd44d830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Schr=C3=B6der?= Date: Wed, 5 Feb 2025 10:34:21 +0100 Subject: [PATCH 1/3] fix gradio app shadowing other FastAPI endpoints --- server.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server.py b/server.py index 81cd9df..4883503 100644 --- a/server.py +++ b/server.py @@ -52,9 +52,6 @@ async def lifespan(app: FastAPI): allow_credentials=True, ) -app = gr.mount_gradio_app(app, demo_ui, path="") - - @app.get("/health", response_model=HealthResponse) def server(): """ @@ -97,6 +94,8 @@ async def process_files(files): responses = await process_files(pdf_files) return BatchConversionResponse(results=responses) +# Mount the Gradio app last as the other routes are unavailable otherwise +gr.mount_gradio_app(app, demo_ui, path="") # Main function to run the server def main(): From f449af7cf19dfc87aff84ec23e2477c2fa23d757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Schr=C3=B6der?= Date: Wed, 5 Feb 2025 10:40:47 +0100 Subject: [PATCH 2/3] fix gradio demo --- marker_api/demo.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/marker_api/demo.py b/marker_api/demo.py index 12409fe..2990595 100644 --- a/marker_api/demo.py +++ b/marker_api/demo.py @@ -53,24 +53,23 @@ def parse_document(input_file_path, parameters, request: gr.Request): mime_type = "application/octet-stream" # Default MIME type if not found with open(input_file_path, "rb") as f: - files = {"file": (input_file_path, f, mime_type)} + files = {"pdf_file": (input_file_path, f, mime_type)} response = requests.post( post_url, files=files, headers={"accept": "application/json"} ) document_response = response.json() - - images = document_response.get("images", []) - + result = document_response.get("result", {}) + markdown_text = str(result.get("markdown", "")) + images = result.get("images", {}) + # Decode each base64-encoded image to a PIL image - pil_images = [ - decode_base64_to_pil(image_dict["image"]) for image_dict in images - ] - + pil_images = [decode_base64_to_pil(img) for img in images.values()] + return ( - str(document_response["text"]), + markdown_text, gr.Gallery(value=pil_images, visible=True), - str(document_response["text"]), + markdown_text, gr.JSON(value=document_response, visible=True), ) From 9df5dabd661e77c66bf5ab8ccdb6f47d8d30a0b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Schr=C3=B6der?= Date: Wed, 5 Feb 2025 10:42:40 +0100 Subject: [PATCH 3/3] fix container build for maker-pdf 0.2.17 --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 8d19e0e..787fcbb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ marker-pdf = "^0.2.17" pynvml = "^11.5.3" art = "^6.3" gradio = "^5.1.0" +transformers = "4.45.2"