Update server.py
Browse files
server.py
CHANGED
|
@@ -4,10 +4,12 @@ from marker.convert import convert_single_pdf
|
|
| 4 |
from marker.models import load_all_models
|
| 5 |
from marker.settings import Settings
|
| 6 |
import gradio as gr
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
model_list = load_all_models()
|
| 10 |
|
|
|
|
| 11 |
def parse_pdf_and_return_markdown(pdf_file: bytes , extract_images: bool):
|
| 12 |
full_text, images, out_meta = convert_single_pdf(pdf_file, model_list)
|
| 13 |
image_data = {}
|
|
@@ -27,35 +29,6 @@ def parse_pdf_and_return_markdown(pdf_file: bytes , extract_images: bool):
|
|
| 27 |
return full_text, out_meta, image_data
|
| 28 |
|
| 29 |
|
| 30 |
-
# @app.post("/convert")
|
| 31 |
-
# async def convert_pdf_to_markdown(pdf_file: UploadFile = File(...), extract_images: bool = True):
|
| 32 |
-
# if extract_images == False:
|
| 33 |
-
# Settings.EXTRACT_IMAGES = False
|
| 34 |
-
# print("Print EXTRACT_IMAGES set to False")
|
| 35 |
-
# else:
|
| 36 |
-
# Settings.EXTRACT_IMAGES = True
|
| 37 |
-
# if pdf_file.content_type != "application/pdf":
|
| 38 |
-
# raise HTTPException(
|
| 39 |
-
# status_code=status.HTTP_415_UNSUPPORTED_MEDIA_TYPE,
|
| 40 |
-
# detail=f'File {pdf_file.filename} has unsupported extension type',
|
| 41 |
-
# )
|
| 42 |
-
# markdown_text, metadata, image_data = parse_pdf_and_return_markdown(await pdf_file.read(), extract_images=extract_images)
|
| 43 |
-
# return {"markdown": markdown_text, "metadata": metadata, "images": image_data }
|
| 44 |
-
|
| 45 |
-
# def main():
|
| 46 |
-
# # Parse command-line arguments
|
| 47 |
-
# parser = argparse.ArgumentParser(description="Run the marker-api server.")
|
| 48 |
-
# parser.add_argument("--host", default="127.0.0.1", help="Host IP address")
|
| 49 |
-
# parser.add_argument("--port", type=int, default=8000, help="Port number")
|
| 50 |
-
# args = parser.parse_args()
|
| 51 |
-
|
| 52 |
-
# # Load all models before starting the server
|
| 53 |
-
# configure_logging() # Assuming this function initializes logging
|
| 54 |
-
|
| 55 |
-
# # Start the server
|
| 56 |
-
# import uvicorn
|
| 57 |
-
# uvicorn.run(app, host=args.host, port=args.port)
|
| 58 |
-
|
| 59 |
with gr.Blocks() as server:
|
| 60 |
gr.Markdown("Upload a PDF file to convert to markdown.")
|
| 61 |
gr.Interface(
|
|
|
|
| 4 |
from marker.models import load_all_models
|
| 5 |
from marker.settings import Settings
|
| 6 |
import gradio as gr
|
| 7 |
+
import spaces
|
| 8 |
|
| 9 |
|
| 10 |
model_list = load_all_models()
|
| 11 |
|
| 12 |
+
@spaces.GPU(duration=300)
|
| 13 |
def parse_pdf_and_return_markdown(pdf_file: bytes , extract_images: bool):
|
| 14 |
full_text, images, out_meta = convert_single_pdf(pdf_file, model_list)
|
| 15 |
image_data = {}
|
|
|
|
| 29 |
return full_text, out_meta, image_data
|
| 30 |
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
with gr.Blocks() as server:
|
| 33 |
gr.Markdown("Upload a PDF file to convert to markdown.")
|
| 34 |
gr.Interface(
|