Get the appropriate processor for the file. Args: file_path: Path to the file Returns: Processor that can handle the file, or None if none found
(self, file_path: str)
| 304 | return "cloud" |
| 305 | |
| 306 | def _get_processor(self, file_path: str): |
| 307 | """Get the appropriate processor for the file. |
| 308 | |
| 309 | Args: |
| 310 | file_path: Path to the file |
| 311 | |
| 312 | Returns: |
| 313 | Processor that can handle the file, or None if none found |
| 314 | """ |
| 315 | # Define GPU-supported formats |
| 316 | gpu_supported_formats = ['.jpg', '.jpeg', '.png', '.bmp', '.tiff', '.webp', '.gif', '.pdf'] |
| 317 | |
| 318 | # Check file extension |
| 319 | _, ext = os.path.splitext(file_path.lower()) |
| 320 | |
| 321 | # Check if GPU processor should be used for this file type |
| 322 | gpu_available = should_use_gpu_processor() |
| 323 | |
| 324 | # Try GPU processor only if format is supported AND (gpu OR auto-gpu) |
| 325 | if ext in gpu_supported_formats and (self.gpu or (gpu_available and not self.gpu)): |
| 326 | for processor in self.processors: |
| 327 | if isinstance(processor, GPUProcessor): |
| 328 | if self.gpu: |
| 329 | logger.info(f"Using GPU processor with Nanonets OCR for {file_path} (GPU preference specified)") |
| 330 | else: |
| 331 | logger.info(f"Using GPU processor with Nanonets OCR for {file_path} (GPU available and format supported)") |
| 332 | return processor |
| 333 | |
| 334 | # Fallback to normal processor selection |
| 335 | for processor in self.processors: |
| 336 | if processor.can_process(file_path): |
| 337 | # Skip GPU processor in fallback mode to avoid infinite loops |
| 338 | if isinstance(processor, GPUProcessor): |
| 339 | continue |
| 340 | logger.info(f"Using {processor.__class__.__name__} for {file_path}") |
| 341 | return processor |
| 342 | return None |
| 343 | |
| 344 | def get_supported_formats(self) -> List[str]: |
| 345 | """Get list of supported file formats. |
no test coverage detected