Spaces:
Sleeping
Sleeping
Update app/services/predictor.py
Browse files- app/services/predictor.py +4 -12
app/services/predictor.py
CHANGED
|
@@ -1,30 +1,25 @@
|
|
| 1 |
# app/services/predictor.py
|
| 2 |
import numpy as np
|
| 3 |
import tensorflow as tf
|
| 4 |
-
from typing import Tuple
|
| 5 |
|
| 6 |
from app.configs import (
|
| 7 |
get_classification_model,
|
| 8 |
sigmoid_to_class,
|
| 9 |
-
CLASSIFIER_URI,
|
| 10 |
)
|
| 11 |
from app.core.preprocessing import preprocess_image
|
| 12 |
from app.core.validation import is_valid_image
|
| 13 |
|
| 14 |
|
| 15 |
-
def classify_image(
|
| 16 |
-
image_bytes: bytes,
|
| 17 |
-
model_version: Optional[str] = None,
|
| 18 |
-
) -> Tuple[str, float, str]:
|
| 19 |
"""
|
| 20 |
Classify image using the classification model.
|
| 21 |
|
| 22 |
Args:
|
| 23 |
image_bytes: Raw image bytes
|
| 24 |
-
model_version: Optional model version (for A/B testing)
|
| 25 |
|
| 26 |
Returns:
|
| 27 |
-
Tuple of (prediction, confidence
|
| 28 |
"""
|
| 29 |
# Validate image
|
| 30 |
if not is_valid_image(image_bytes):
|
|
@@ -49,10 +44,7 @@ def classify_image(
|
|
| 49 |
# Sigmoid output -> binary classification
|
| 50 |
confidence = float(predictions[0][0])
|
| 51 |
prediction = sigmoid_to_class(confidence)
|
| 52 |
-
|
| 53 |
-
# Use provided version or default
|
| 54 |
-
actual_version = model_version or CLASSIFIER_URI
|
| 55 |
|
| 56 |
print(f"🔍 CLASSIFICATION: {prediction} (confidence={confidence:.3f})")
|
| 57 |
|
| 58 |
-
return prediction, confidence
|
|
|
|
| 1 |
# app/services/predictor.py
|
| 2 |
import numpy as np
|
| 3 |
import tensorflow as tf
|
| 4 |
+
from typing import Tuple
|
| 5 |
|
| 6 |
from app.configs import (
|
| 7 |
get_classification_model,
|
| 8 |
sigmoid_to_class,
|
|
|
|
| 9 |
)
|
| 10 |
from app.core.preprocessing import preprocess_image
|
| 11 |
from app.core.validation import is_valid_image
|
| 12 |
|
| 13 |
|
| 14 |
+
def classify_image(image_bytes: bytes) -> Tuple[str, float]:
|
|
|
|
|
|
|
|
|
|
| 15 |
"""
|
| 16 |
Classify image using the classification model.
|
| 17 |
|
| 18 |
Args:
|
| 19 |
image_bytes: Raw image bytes
|
|
|
|
| 20 |
|
| 21 |
Returns:
|
| 22 |
+
Tuple of (prediction, confidence)
|
| 23 |
"""
|
| 24 |
# Validate image
|
| 25 |
if not is_valid_image(image_bytes):
|
|
|
|
| 44 |
# Sigmoid output -> binary classification
|
| 45 |
confidence = float(predictions[0][0])
|
| 46 |
prediction = sigmoid_to_class(confidence)
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
print(f"🔍 CLASSIFICATION: {prediction} (confidence={confidence:.3f})")
|
| 49 |
|
| 50 |
+
return prediction, confidence
|