Spaces:
Sleeping
Sleeping
Download features/ai_human_image_classifier/controller.py from can-org/Testing-AI-Contain: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/spaces/can-org/Testing-AI-Contain/resolve/refs%2Fpr%2F2/features/ai_human_image_classifier/controller.py
- Command line
-
hf download hf://spaces/can-org/Testing-AI-Contain@refs/pr/2/features/ai_human_image_classifier/controller.py
-
curl -L -o controller.py https://huggingface.co/spaces/can-org/Testing-AI-Contain/resolve/refs%2Fpr%2F2/features/ai_human_image_classifier/controller.py
1.09 kB
| 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() | |