@@ -119,7 +119,7 @@ def convert_to_markdown_vlm(pdf_bytes, backend="vlm-sglang-engine", server_url=N
119119 return vlm_union_make (pdf_info , MakeMode .MM_MD , "images" )
120120
121121
122- def _convert_to_markdown_via_aio (
122+ async def _convert_to_markdown_via_aio (
123123 pdf_bytes : bytes ,
124124 filename : str ,
125125 * ,
@@ -147,30 +147,26 @@ def _convert_to_markdown_via_aio(
147147 raise Exception ("Invalid max_pages value; must be an integer" )
148148
149149 with tempfile .TemporaryDirectory () as output_dir :
150- # Run async parse
151- async def _run ():
152- await aio_do_parse (
153- output_dir = output_dir ,
154- pdf_file_names = [filename ],
155- pdf_bytes_list = [pdf_bytes ],
156- p_lang_list = [lang ],
157- backend = backend ,
158- parse_method = parse_method ,
159- formula_enable = formula_enable ,
160- table_enable = table_enable ,
161- server_url = server_url ,
162- f_draw_layout_bbox = False ,
163- f_draw_span_bbox = False ,
164- f_dump_md = True ,
165- f_dump_middle_json = False ,
166- f_dump_model_output = False ,
167- f_dump_orig_pdf = False ,
168- f_dump_content_list = False ,
169- start_page_id = start_page_id ,
170- end_page_id = end_page_id ,
171- )
172-
173- asyncio .run (_run ())
150+ await aio_do_parse (
151+ output_dir = output_dir ,
152+ pdf_file_names = [filename ],
153+ pdf_bytes_list = [pdf_bytes ],
154+ p_lang_list = [lang ],
155+ backend = backend ,
156+ parse_method = parse_method ,
157+ formula_enable = formula_enable ,
158+ table_enable = table_enable ,
159+ server_url = server_url ,
160+ f_draw_layout_bbox = False ,
161+ f_draw_span_bbox = False ,
162+ f_dump_md = True ,
163+ f_dump_middle_json = False ,
164+ f_dump_model_output = False ,
165+ f_dump_orig_pdf = False ,
166+ f_dump_content_list = False ,
167+ start_page_id = start_page_id ,
168+ end_page_id = end_page_id ,
169+ )
174170
175171 # Locate markdown file
176172 parse_subdir = parse_method if backend .startswith ("pipeline" ) else "vlm"
@@ -182,7 +178,7 @@ async def _run():
182178 return f .read ()
183179
184180
185- def convert_to_markdown_dispatch (pdf_bytes , filename = None , ** kwargs ):
181+ async def convert_to_markdown_dispatch (pdf_bytes , filename = None , ** kwargs ):
186182 """Dispatch to pipeline or VLM engine based on env MINERU_BACKEND.
187183
188184 Prefer using aio_do_parse to match official MinerU entrypoints.
@@ -202,7 +198,7 @@ def convert_to_markdown_dispatch(pdf_bytes, filename=None, **kwargs):
202198 if backend_env .startswith ("vlm" ):
203199 parse_method = "vlm"
204200 backend_for_aio = backend_env
205- return _convert_to_markdown_via_aio (
201+ return await _convert_to_markdown_via_aio (
206202 pdf_bytes ,
207203 filename ,
208204 lang = lang ,
@@ -216,7 +212,7 @@ def convert_to_markdown_dispatch(pdf_bytes, filename=None, **kwargs):
216212
217213
218214
219- def handler (event ):
215+ async def handler (event ):
220216 try :
221217 input_data = event .get ("input" , {})
222218 base64_content = input_data .get ("file_content" )
@@ -250,7 +246,7 @@ def handler(event):
250246 # Process PDF
251247 pdf_bytes = base64 .b64decode (base64_content )
252248
253- md_content = convert_to_markdown_dispatch (
249+ md_content = await convert_to_markdown_dispatch (
254250 pdf_bytes = pdf_bytes ,
255251 filename = os .path .splitext (os .path .basename (filename ))[0 ] if filename else "document" ,
256252 lang = lang ,
0 commit comments