import cv2 from keras.models import load_model import gradio as gr import numpy as np from tensorflow.keras.preprocessing.image import ImageDataGenerator model = load_model('Chicken_Gizzard_Updated_model.h5',compile=True) class_names={0:'Normal Appearance', 1:'The proventriculusof infected chickens showing several ecchymotic hemorrhages on the tip of the proventricular glandsat 3 dpi', 2:'edema with increased number of solitary and coalesced ecchymotic hemorrhages on theproventricular glands at 4 dpi', 3:'and numerous hemorrhagic spots coalesced to form brush paintappearance on the entire mucosa at 5 dpi'} def Predict_Gizzard(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),(224,224)) class_no=model.predict(img.reshape(1,224,224,3)).argmax() name=class_names.get(class_no) return name interface=gr.Interface(fn=Predict_Gizzard,inputs='image',outputs=[gr.components.Textbox(label='Your Result')], examples=[['Class A.PNG'],['Class B.PNG'],['Class C.PNG'],['Class D.PNG']]) interface.launch(debug=True)