Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/gradio demo #25

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions marker_api/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ marker-pdf = "^0.2.17"
pynvml = "^11.5.3"
art = "^6.3"
gradio = "^5.1.0"
transformers = "4.45.2"



Expand Down
5 changes: 2 additions & 3 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
"""
Expand Down Expand Up @@ -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():
Expand Down