from PIL import Image import tensorflow as tf import numpy as np #from google.colab import files #model_path = 'final_teath_classifier.h5' # Load the model model = tf.keras.models.load_model(model_path) def preprocess_image(image: Image.Image) -> np.ndarray: # Resize the image to match input size image = image.resize((256, 256)) # Convert image to array and preprocess input img_array = np.array(image) / 255.0 # Add batch dimension img_array = np.expand_dims(img_array, axis=0) return img_array def predict_image(image_path): img = Image.open(image_path) # Preprocess the image img_array = preprocess_image(img) predictions = model.predict(img_array) predicted_class = np.argmax(predictions) if predicted_class == 0: predict_label = "Clean" else: predict_label = "Carries" return predict_label,predictions.flatten() # Upload the image #uploaded = files.upload() # Get the uploaded image file name #image_path = list(uploaded.keys())[0] predict_label, logits = predict_image(image_path) print("Predicted class:", predict_label) print("Evaluate:", ', '.join(f"{logits*100:.4f}%" for logits in logits))