moro23 commited on
Commit
a8ce70c
·
1 Parent(s): cda9d4e

Create app.py

Browse files

created an app file

Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## libraries for data preprocessing
2
+ import numpy as np
3
+ import pandas as pd
4
+
5
+ ## libraries for training dl models
6
+ import tensorflow as tf
7
+ from tensorflow import keras
8
+
9
+ ## libraries for pre-trained neural network
10
+ from tensorflow.keras.applications.xception import preprocess_input
11
+
12
+ ## libraries for loading batch images
13
+ from tensorflow.keras.preprocessing.image import load_img
14
+
15
+ import gradio as gr
16
+
17
+ def get_y(o):
18
+ return [parent_label(o)]
19
+
20
+ ## lets load the model
21
+ model = keras.models.load_model('xception_v1_15_0.812.h5')
22
+
23
+
24
+
25
+ def maize_disease_classifier(image):
26
+ x = np.array(image)
27
+ X = np.array([x])
28
+ X = preprocess_input(X)
29
+ pred = model.predict(X)
30
+ result = pred[0].argmax()
31
+ ## lets create our labels
32
+ labels = {
33
+ 0: 'maize ear rot',
34
+ 1: 'maize fall armyworm',
35
+ 2: 'maize stem borer'
36
+ }
37
+
38
+ label = labels[pred[0].argmax()]
39
+ return pred, result, label
40
+
41
+
42
+ iface = gr.Interface(fn=maize_disease_classifier, inputs=gr.inputs.Image(shape=(224, 224)), \
43
+ outputs=["number", "number", "text"])
44
+
45
+ iface.launch(inline=False)