Update mdr_pdf_parser.py
Browse files- mdr_pdf_parser.py +9 -6
mdr_pdf_parser.py
CHANGED
@@ -47,7 +47,8 @@ from munch import Munch
|
|
47 |
from transformers import LayoutLMv3ForTokenClassification
|
48 |
import onnxruntime
|
49 |
# --- HUGGING FACE HUB IMPORT ONLY BECAUSE RUNNING IN SPACES NOT NECESSARY IN PROD ---
|
50 |
-
from huggingface_hub import hf_hub_download
|
|
|
51 |
import time # Added for example usage timing
|
52 |
|
53 |
# --- External Dependencies ---
|
@@ -1890,14 +1891,16 @@ class MDRExtractionEngine:
|
|
1890 |
self._yolo = YOLOv10(yolo_model_filepath)
|
1891 |
print("MDR YOLOv10 model loaded successfully.")
|
1892 |
|
1893 |
-
|
1894 |
-
|
|
|
1895 |
self._yolo = None
|
1896 |
-
except FileNotFoundError as e: # Catch if hf_hub_download fails finding file
|
1897 |
-
print(f"ERROR: YOLO model file not found
|
1898 |
self._yolo = None
|
1899 |
except Exception as e:
|
1900 |
-
|
|
|
1901 |
self._yolo = None
|
1902 |
|
1903 |
elif YOLOv10 is None:
|
|
|
47 |
from transformers import LayoutLMv3ForTokenClassification
|
48 |
import onnxruntime
|
49 |
# --- HUGGING FACE HUB IMPORT ONLY BECAUSE RUNNING IN SPACES NOT NECESSARY IN PROD ---
|
50 |
+
from huggingface_hub import hf_hub_download
|
51 |
+
from huggingface_hub.errors import HfHubHTTPError
|
52 |
import time # Added for example usage timing
|
53 |
|
54 |
# --- External Dependencies ---
|
|
|
1891 |
self._yolo = YOLOv10(yolo_model_filepath)
|
1892 |
print("MDR YOLOv10 model loaded successfully.")
|
1893 |
|
1894 |
+
# --- MODIFIED EXCEPTION HANDLING ---
|
1895 |
+
except HfHubHTTPError as e: # <-- CHANGED THIS LINE
|
1896 |
+
print(f"ERROR: Failed to download/access YOLO model via Hugging Face Hub: {e}") # Slightly updated message
|
1897 |
self._yolo = None
|
1898 |
+
except FileNotFoundError as e: # Catch if hf_hub_download fails finding file OR YOLOv10 constructor fails
|
1899 |
+
print(f"ERROR: YOLO model file not found or failed to load locally: {e}") # Slightly updated message
|
1900 |
self._yolo = None
|
1901 |
except Exception as e:
|
1902 |
+
# Keep the general exception catch, but make the message more specific
|
1903 |
+
print(f"ERROR: An unexpected issue occurred loading YOLOv10 model from {yolo_cache_dir}/{filename}: {e}")
|
1904 |
self._yolo = None
|
1905 |
|
1906 |
elif YOLOv10 is None:
|