Skip to content

Commit

Permalink
Make toc asynchronous
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-piles committed Jul 16, 2024
1 parent b47e90c commit 0425c8e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pdf_layout_analysis.run_pdf_layout_analysis import analyze_pdf
from pdf_layout_analysis.run_pdf_layout_analysis_fast import analyze_pdf_fast
from toc.extract_table_of_contents import extract_table_of_contents
from toc.get_toc import get_toc

service_logger.info(f"Is PyTorch using GPU: {torch.cuda.is_available()}")

Expand Down Expand Up @@ -52,8 +53,5 @@ async def run_fast(file: UploadFile = File(...)):

@app.post("/toc")
@catch_exceptions
async def get_toc(file: UploadFile = File(...), fast: bool = Form(False)):
file_content = file.file.read()
if fast:
return extract_table_of_contents(file_content, analyze_pdf_fast(file_content))
return extract_table_of_contents(file_content, analyze_pdf(file_content))
async def get_toc_endpoint(file: UploadFile = File(...), fast: bool = Form(False)):
return await run_in_threadpool(get_toc, file, fast)
12 changes: 12 additions & 0 deletions src/toc/get_toc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from fastapi import UploadFile

from pdf_layout_analysis.run_pdf_layout_analysis import analyze_pdf
from pdf_layout_analysis.run_pdf_layout_analysis_fast import analyze_pdf_fast
from toc.extract_table_of_contents import extract_table_of_contents


def get_toc(file: UploadFile, fast: bool):
file_content = file.file.read()
if fast:
return extract_table_of_contents(file_content, analyze_pdf_fast(file_content))
return extract_table_of_contents(file_content, analyze_pdf(file_content, ""))

0 comments on commit 0425c8e

Please sign in to comment.