Pārlūkot izejas kodu

fix: handle exceptions in parsing and return None on failure

myhloli 4 mēneši atpakaļ
vecāks
revīzija
fc5f330c53
1 mainītis faili ar 17 papildinājumiem un 0 dzēšanām
  1. 17 0
      mineru/cli/gradio_app.py

+ 17 - 0
mineru/cli/gradio_app.py

@@ -28,6 +28,7 @@ async def parse_pdf(doc_path, output_dir, end_page_id, is_ocr, formula_enable, t
 
         if backend.startswith("vlm"):
             parse_method = "vlm"
+            url = None
         local_image_dir, local_md_dir = prepare_env(output_dir, file_name, parse_method)
         await aio_do_parse(
             output_dir=output_dir,
@@ -44,6 +45,7 @@ async def parse_pdf(doc_path, output_dir, end_page_id, is_ocr, formula_enable, t
         return local_md_dir, file_name
     except Exception as e:
         logger.exception(e)
+        return None
 
 
 def compress_directory_to_zip(directory_path, output_zip_path):
@@ -175,6 +177,21 @@ def to_pdf(file_path):
 def main():
     example_enable = False
 
+    # try:
+    #     print("Start init SgLang engine...")
+    #     from mineru.backend.vlm.vlm_analyze import ModelSingleton
+    #     modelsingleton = ModelSingleton()
+    #     predictor = modelsingleton.get_model(
+    #         "sglang-engine",
+    #         None,
+    #         None,
+    #         mem_fraction_static=0.5,
+    #         enable_torch_compile=True,
+    #     )
+    #     print("SgLang engine init successfully.")
+    # except Exception as e:
+    #     logger.exception(e)
+
     with gr.Blocks() as demo:
         gr.HTML(header)
         with gr.Row():