import gradio as gr import tensorflow as tf import numpy as np from PIL import Image # Load the saved model model = tf.keras.models.load_model("saved_model_cnn.keras") # Define the classes classes = ['Caries','Gingivitis' ] # Prediction function def predict(image): image = Image.fromarray(np.uint8(image)).convert("RGB") image = image.resize((224, 224)) # Assuming the model expects 224x224 images image_array = np.array(image) / 255.0 # Normalize to [0, 1] image_array = np.expand_dims(image_array, axis=0) # Add batch dimension prediction = model.predict(image_array) predicted_class = classes[np.argmax(prediction)] confidence = np.max(prediction) return f"Class: {predicted_class}, Confidence: {confidence:.2f}" # Gradio interface interface = gr.Interface( fn=predict, inputs=gr.Image(type="numpy", label="Upload Image"), outputs=gr.Textbox(label="Prediction"), title="Dental Health Predictor", description="Upload an image to predict between Gingivitis and Caries." ) # Launch the app if __name__ == "__main__": interface.launch()