Spaces:
Sleeping
Sleeping
File size: 1,090 Bytes
bfb2e8a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
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()
|