Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
from keras.models import load_model
|
3 |
+
import gradio as gr
|
4 |
+
import numpy as np
|
5 |
+
from tensorflow.keras.preprocessing.image import ImageDataGenerator
|
6 |
+
|
7 |
+
model = load_model('/content/drive/MyDrive/Chicken_Gizzard_Updated_model.h5',compile=True)
|
8 |
+
class_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 |
+
|
13 |
+
def Predict_Gizzard(img):
|
14 |
+
img=cv2.imread(img)
|
15 |
+
img = img.reshape((1, img.shape[0], img.shape[1], img.shape[2]))
|
16 |
+
|
17 |
+
# Create the data generator with desired properties
|
18 |
+
datagen = ImageDataGenerator(
|
19 |
+
rotation_range=30,
|
20 |
+
width_shift_range=0.1,
|
21 |
+
height_shift_range=0.1,
|
22 |
+
shear_range=0.1,
|
23 |
+
zoom_range=0.1,
|
24 |
+
horizontal_flip=True,
|
25 |
+
fill_mode="nearest",
|
26 |
+
)
|
27 |
+
# Generate a batch of augmented images (contains only the single image)
|
28 |
+
augmented_images = datagen.flow(img, batch_size=1)
|
29 |
+
# Get the first (and only) augmented image from the batch
|
30 |
+
augmented_img = next(augmented_images)[0]
|
31 |
+
img=cv2.resize(augmented_img.astype(np.uint8),(224,224))
|
32 |
+
class_no=model.predict(img.reshape(1,224,224,3)).argmax()
|
33 |
+
name=class_names.get(class_no)
|
34 |
+
return name
|
35 |
+
|
36 |
+
|
37 |
+
interface=gr.Interface(fn=Predict_Gizzard,inputs='image',outputs=[gr.components.Textbox(label='Your Result')],
|
38 |
+
examples=[['Class A.PNG'],['Class B.PNG'],['Class C.PNG'],['Class D.PNG']])
|
39 |
+
|
40 |
+
interface.launch(debug=True)
|
41 |
+
|
42 |
+
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
|
50 |
+
|
51 |
+
|
52 |
+
|
53 |
+
|
54 |
+
|
55 |
+
|
56 |
+
|
57 |
+
|
58 |
+
|