Skip to content

Commit

Permalink
Cleanup server
Browse files Browse the repository at this point in the history
  • Loading branch information
VikParuchuri committed Oct 31, 2024
1 parent 185d299 commit c34cf8f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,20 @@ marker_server --port 8001 --api_key API_KEY

Note: This is not the recommended way to use the Datalab API - it's only provided as a convenience for people wrapping the marker repo. The recommended way is to make a post request to the endpoint directly from your code vs proxying through this server.

You can send requests like this:

```
import requests
import json
post_data = {
'filepath': 'FILEPATH',
# Add other params here
}
requests.post("http://localhost:8001/local", data=json.dumps(post_data)).json() # Change to /remote if using Datalab API
```

# Troubleshooting

There are some settings that you may find useful if things aren't working the way you expect:
Expand Down
41 changes: 25 additions & 16 deletions marker_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from typing import Optional
import io

from fastapi import FastAPI, Form
from fastapi import FastAPI, Body
from marker.convert import convert_single_pdf
from marker.models import load_all_models

Expand Down Expand Up @@ -48,25 +48,32 @@ async def root():

@app.post("/remote")
async def convert_pdf_remote(
filepath: str = Form(
filepath: str = Body(
...,
description="The path to the PDF file, word document, or powerpoint to convert."
),
max_pages: Optional[int] = Form(
max_pages: Optional[int] = Body(
None,
description="The maximum number of pages in the document to convert."
description="The maximum number of pages in the document to convert.",
example=None
),
langs: Optional[str] = Form(
langs: Optional[str] = Body(
None,
description="The optional languages to use if OCR is needed, comma separated. Must be either the names or codes from https://github.com/VikParuchuri/surya/blob/master/surya/languages.py."
description="The optional languages to use if OCR is needed, comma separated. Must be either the names or codes from https://github.com/VikParuchuri/surya/blob/master/surya/languages.py.",
example=None
),
force_ocr: bool = Form(
force_ocr: bool = Body(
False,
description="Force OCR on all pages of the PDF. Defaults to False. This can lead to worse results if you have good text in your PDFs (which is true in most cases)."
),
paginate: bool = Form(False,
description="Whether to paginate the output. Defaults to False. If set to True, each page of the output will be separated by a horizontal rule that contains the page number (2 newlines, {PAGE_NUMBER}, 48 - characters, 2 newlines)."),
extract_images: bool = Form(True, description="Whether to extract images from the PDF. Defaults to True. If set to False, no images will be extracted from the PDF."),
paginate: bool = Body(
False,
description="Whether to paginate the output. Defaults to False. If set to True, each page of the output will be separated by a horizontal rule that contains the page number (2 newlines, {PAGE_NUMBER}, 48 - characters, 2 newlines)."
),
extract_images: bool = Body(
True,
description="Whether to extract images from the PDF. Defaults to True. If set to False, no images will be extracted from the PDF."
),
):
with open(filepath, "rb") as f:
filedata = f.read()
Expand Down Expand Up @@ -101,19 +108,21 @@ async def convert_pdf_remote(

@app.post("/local")
async def convert_pdf_local(
filepath: str = Form(
filepath: str = Body(
...,
description="The path to the PDF file to convert."
),
max_pages: Optional[int] = Form(
max_pages: Optional[int] = Body(
None,
description="The maximum number of pages in the PDF to convert."
description="The maximum number of pages in the PDF to convert.",
example=None
),
langs: Optional[str] = Form(
langs: Optional[str] = Body(
None,
description="The optional languages to use if OCR is needed, comma separated. Must be either the names or codes from https://github.com/VikParuchuri/surya/blob/master/surya/languages.py."
description="The optional languages to use if OCR is needed, comma separated. Must be either the names or codes from https://github.com/VikParuchuri/surya/blob/master/surya/languages.py.",
example=None
),
force_ocr: bool = Form(
force_ocr: bool = Body(
False,
description="Force OCR on all pages of the PDF. Defaults to False. This can lead to worse results if you have good text in your PDFs (which is true in most cases)."
)
Expand Down

0 comments on commit c34cf8f

Please sign in to comment.