from tensorflow.keras.preprocessing import image
from tensorflow.keras.models import load_model
import numpy as np

# Load model and class indices
model = load_model('image_classifier.h5')
class_names = ['back', 'front', 'full', 'half']  # adjust based on actual order in generator.class_indices

def classify_image(img_path):
    img = image.load_img(img_path, target_size=(128, 128))
    img_array = image.img_to_array(img) / 255.0
    img_array = np.expand_dims(img_array, axis=0)

    prediction = model.predict(img_array)
    class_idx = np.argmax(prediction)
    print(f"Predicted class: {class_names[class_idx]}")

# Test it
classify_image("test.jpg")
