| from typing import IO |
| from preprocessor import preprocessor |
| from inferencer import inferencer |
|
|
| class ClassificationController: |
| """ |
| Controller to handle the image classification logic. |
| """ |
| def classify_image(self, image_file: IO) -> dict: |
| """ |
| Orchestrates the classification of a single image file. |
| |
| Args: |
| image_file (IO): The image file to classify. |
| |
| Returns: |
| dict: The classification result. |
| """ |
| try: |
| |
| image_tensor = preprocessor.process(image_file) |
|
|
| |
| result = inferencer.predict(image_tensor) |
|
|
| return result |
| except ValueError as e: |
| |
| return {"error": str(e)} |
| except Exception as e: |
| |
| print(f"An unexpected error occurred: {e}") |
| return {"error": "An internal error occurred during classification."} |
|
|
| controller = ClassificationController() |
|
|