class ImageAnalysisAgent: """ Lazy image-analysis router. It loads each computer-vision model only when that image type is requested, so the API can start even if a heavy model has not been downloaded yet. """ def __init__(self, config): self.config = config self._classifier = None self._chest_xray_agent = None self._skin_lesion_agent = None @property def image_classifier(self): if self._classifier is None: from .image_classifier import ImageClassifier self._classifier = ImageClassifier(vision_model=self.config.medical_cv.llm) return self._classifier @property def chest_xray_agent(self): if self._chest_xray_agent is None: from .chest_xray_agent.covid_chest_xray_inference import ChestXRayClassification self._chest_xray_agent = ChestXRayClassification( model_path=self.config.medical_cv.chest_xray_model_path ) return self._chest_xray_agent @property def skin_lesion_agent(self): if self._skin_lesion_agent is None: from .skin_lesion_agent.skin_lesion_inference import SkinLesionSegmentation self._skin_lesion_agent = SkinLesionSegmentation( model_path=self.config.medical_cv.skin_lesion_model_path ) return self._skin_lesion_agent def analyze_image(self, image_path: str) -> str: return self.image_classifier.classify_image(image_path) def classify_chest_xray(self, image_path: str) -> str: return self.chest_xray_agent.predict(image_path) def segment_skin_lesion(self, image_path: str) -> str: return self.skin_lesion_agent.predict( image_path, self.config.medical_cv.skin_lesion_segmentation_output_path, )