adelekedaniel21/eye_disease_detection
0
1import gradio as gr2from tensorflow.keras.models import load_model3from skimage.transform import resize4import numpy as np5 6 7# Load the trained model8model = load_model("eye_model.h5")9 10# Define a function to process the image and make predictions11def classify_image(image):12 # Resize image to model's input shape13 resized_image = resize(image, (224, 224, 3)) # Resize to (224, 224, 3)14 resized_image = np.expand_dims(resized_image, axis=0) # Add batch dimension15 predictions = model.predict(resized_image) # Make prediction16 class_probabilities = predictions[0] # Probabilities for each class17 # Get the top prediction indices and map them to class names18 list_index = np.argsort(class_probabilities)[::-1] # Sort indices by probability (descending)19 data_dir_list = ['cataract', 'diabetes', 'glaucoma', 'normal', 'others']20 top_predictions = {21 data_dir_list[i]: round(class_probabilities[i], 2)22 for i in list_index[:5]23 }24 25 # Return top predictions26 return top_predictions27 28# Set up the Gradio interface29interface = gr.Interface(30 fn=classify_image, # Function to run for predictions31 inputs=gr.Image(type="numpy"), # Accept image input and return as NumPy array32 outputs=gr.Label(num_top_classes=3), # Display top 3 predictions33 title="Eye Condition Classification",34 description="Upload an eye image to classify its condition."35)36 37# Launch the interface38if __name__ == "__main__":39 interface.launch()40 