Spaces:
Sleeping
Sleeping
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: | |
# Step 1: Preprocess the image | |
image_tensor = preprocessor.process(image_file) | |
# Step 2: Perform inference | |
result = inferencer.predict(image_tensor) | |
return result | |
except ValueError as e: | |
# Handle specific errors like invalid images | |
return {"error": str(e)} | |
except Exception as e: | |
# Handle unexpected errors | |
print(f"An unexpected error occurred: {e}") | |
return {"error": "An internal error occurred during classification."} | |
controller = ClassificationController() | |