Repository: QuivrHQ/MegaParse
File: libs/megaparse/src/megaparse/parser/strategy.py (Python)

Code before:
        providers = self._get_providers()
        engine_config = EngineConfig(
            session_options=general_options,
            providers=providers,
        )

        self.det_predictor = detection_predictor(
            arch=self.config.det_arch,
            assume_straight_pages=assume_straight_pages,
            preserve_aspect_ratio=preserve_aspect_ratio,
            symmetric_pad=symmetric_pad,
            batch_size=self.config.batch_size,
            load_in_8_bit=load_in_8_bit,
            engine_cfg=engine_config,
        )

    def _get_providers(self) -> List[str]:
        prov = rt.get_available_providers()
        logger.info("Available providers:", prov)
        if self.use_gpu:
            # TODO: support openvino, directml etc
            if "CUDAExecutionProvider" not in prov:
                raise ValueError(
                    "onnxruntime can't find CUDAExecutionProvider in list of available providers"
                )
            return ["CUDAExecutionProvider"]
        else:
            return ["CPUExecutionProvider"]

    def get_strategy_page(
        self, pdfium_page: PdfPage, onnxtr_page: PageLayout
    ) -> StrategyEnum:
        # assert (
        #     p_width == onnxtr_page.dimensions[1]
        #     and p_height == onnxtr_page.dimensions[0]
        # ), "Page dimensions do not match"
        text_coords = []
        # Get all the images in the page
        for obj in pdfium_page.get_objects():
            if obj.type == 1:
                text_coords.append(obj.get_pos())

        p_width, p_height = int(pdfium_page.get_width()), int(pdfium_page.get_height())

        pdfium_canva = np.zeros((int(p_height), int(p_width)))

        for coords in text_coords:
            # (left,bottom,right, top)
            # 0---l--------------R-> y
            # |
            # B   (x0,y0)

Review comment (suggestion):
```suggestion
            return ["TensorrtExecutionProvider","CUDAExecutionProvider"]
```

Code after:
        providers = self._get_providers()
        engine_config = EngineConfig(
            session_options=general_options,
            providers=providers,
        )

        self.det_predictor = detection_predictor(
            arch=text_det_config.det_arch,
            assume_straight_pages=text_det_config.assume_straight_pages,
            preserve_aspect_ratio=text_det_config.preserve_aspect_ratio,
            symmetric_pad=text_det_config.symmetric_pad,
            batch_size=text_det_config.batch_size,
            load_in_8_bit=text_det_config.load_in_8_bit,
            engine_cfg=engine_config,
        )

    def _get_providers(self) -> List[str]:
        prov = rt.get_available_providers()
        logger.info("Available providers:", prov)
        if self.device == DeviceEnum.CUDA:
            # TODO: support openvino, directml etc
            if "CUDAExecutionProvider" not in prov:
                raise ValueError(
                    "onnxruntime can't find CUDAExecutionProvider in list of available providers"
                )
            return ["TensorrtExecutionProvider", "CUDAExecutionProvider"]
        elif self.device == DeviceEnum.COREML:
            if "CoreMLExecutionProvider" not in prov:
                raise ValueError(
                    "onnxruntime can't find CoreMLExecutionProvider in list of available providers"
                )
            return ["CoreMLExecutionProvider"]
        elif self.device == DeviceEnum.CPU:
            return ["CPUExecutionProvider"]
        else:
            warnings.warn(
                "Device not supported, using CPU",
                UserWarning,
                stacklevel=2,
            )
            return ["CPUExecutionProvider"]

    def get_strategy_page(
        self, pdfium_page: PdfPage, onnxtr_page: PageLayout
    ) -> StrategyEnum:
        # assert (
        #     p_width == onnxtr_page.dimensions[1]
        #     and p_height == onnxtr_page.dimensions[0]
        # ), "Page dimensions do not match"
        text_coords = []
        # Get all the images in the page