Rehman1603/Chicken_Gizzard_Disease_Classification
0
1import cv22from keras.models import load_model3import gradio as gr4import numpy as np5from tensorflow.keras.preprocessing.image import ImageDataGenerator6 7model = load_model('Chicken_Gizzard_Updated_model.h5',compile=True)8class_names={0:'Normal Appearance',9 1:'The proventriculusof infected chickens showing several ecchymotic hemorrhages on the tip of the proventricular glandsat 3 dpi',10 2:'edema with increased number of solitary and coalesced ecchymotic hemorrhages on theproventricular glands at 4 dpi',11 3:'and numerous hemorrhagic spots coalesced to form brush paintappearance on the entire mucosa at 5 dpi'}12 13def Predict_Gizzard(img):14 img = img.reshape((1, img.shape[0], img.shape[1], img.shape[2]))15 16 # Create the data generator with desired properties17 datagen = ImageDataGenerator(18 rotation_range=30,19 width_shift_range=0.1,20 height_shift_range=0.1,21 shear_range=0.1,22 zoom_range=0.1,23 horizontal_flip=True,24 fill_mode="nearest",25 )26 # Generate a batch of augmented images (contains only the single image)27 augmented_images = datagen.flow(img, batch_size=1)28 # Get the first (and only) augmented image from the batch29 augmented_img = next(augmented_images)[0]30 img=cv2.resize(augmented_img.astype(np.uint8),(224,224))31 class_no=model.predict(img.reshape(1,224,224,3)).argmax()32 name=class_names.get(class_no)33 return name34 35 36interface=gr.Interface(fn=Predict_Gizzard,inputs='image',outputs=[gr.components.Textbox(label='Your Result')],37 examples=[['Class A.PNG'],['Class B.PNG'],['Class C.PNG'],['Class D.PNG']])38 39interface.launch(debug=True)40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 