from keras.models import load_model import cv2 from tensorflow.keras.preprocessing.image import ImageDataGenerator import gradio as gr import numpy as np heart_model=load_model('Chicken_Heart_model.h5',compile=True) class_name={0:'Dilation(eccentric)',1:'Hepatoma',2:'Hypertrophy(concentric)',3:'Hypertrophy(physiological)',4:'Infraction Damage',5:'Normal'} def Heart_Disease_prediction(img): img = img.reshape((1, img.shape[0], img.shape[1], img.shape[2])) # Create the data generator with desired properties datagen = ImageDataGenerator( rotation_range=30, width_shift_range=0.1, height_shift_range=0.1, shear_range=0.1, zoom_range=0.1, horizontal_flip=True, fill_mode="nearest", ) # Generate a batch of augmented images (contains only the single image) augmented_images = datagen.flow(img, batch_size=1) # Get the first (and only) augmented image from the batch augmented_img = next(augmented_images)[0] img=cv2.resize(augmented_img.astype(np.uint8),(128,128)) class_no=heart_model.predict(img.reshape(1,128,128,3)).argmax() name=class_name.get(class_no) return name interface=gr.Interface(fn=Heart_Disease_prediction,inputs='image',outputs=[gr.components.Textbox(label='Disease Name')], examples=[['Image1.PNG'],['Image2.PNG'],['Image3.PNG'],['Image4.PNG'], ['Image5.PNG'],['Image6.PNG'],['Image7.PNG'],['Image8.PNG'], ['Image9.PNG'],['Image10.PNG'],['Image11.PNG']]) interface.launch(debug=True)