kanthimathi-vr/deeplearningLLJ_iris_recognition_system
0
1import gradio as gr2import tensorflow as tf3import numpy as np4from PIL import Image5 6# Load the trained model7model = tf.keras.models.load_model("iris_recognition_model.h5")8 9# Create class labels10num_classes = model.output_shape[-1]11class_names = [f"Class {i}" for i in range(num_classes)]12 13def predict_iris(image):14 # Resize image15 img = image.resize((224, 224))16 17 # Convert to array18 img = np.array(img) / 255.019 20 # Convert grayscale to RGB if needed21 if len(img.shape) == 2:22 img = np.stack((img,) * 3, axis=-1)23 24 # Expand dimensions25 img = np.expand_dims(img, axis=0)26 27 # Prediction28 prediction = model.predict(img)29 predicted_class = np.argmax(prediction)30 confidence = np.max(prediction)31 32 return f"Predicted: {class_names[predicted_class]}\nConfidence: {confidence:.2f}"33 34# Gradio interface35demo = gr.Interface(36 fn=predict_iris,37 inputs=gr.Image(type="pil"),38 outputs="text",39 title="Iris Recognition System",40 description="Upload an iris image to identify the class"41)42 43demo.launch()