CasualTomes commited on
Commit
4579668
·
verified ·
1 Parent(s): 0776098

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -12
app.py CHANGED
@@ -1,21 +1,33 @@
1
- import os
2
- import numpy as np
3
  import gradio as gr
4
-
5
  import tensorflow as tf
6
  from tensorflow.keras.models import load_model
 
 
 
7
 
8
  #CloudDeploymentTest/
9
- model = load_model('model.keras')
10
- labels = ["bird", "cat", "deer", "dog"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- def pred(input_img):
13
- prediction = model.predict(np.array([input_img])/255) #/255 to normalize (rgb)
14
  prediction = np.argmax(prediction)
15
- prediction = labels[prediction]
16
- return prediction
17
 
18
- demo = gr.Interface(pred, gr.Image(), "text")
 
19
 
20
- if __name__ == "__main__":
21
- demo.launch()
 
 
 
1
  import gradio as gr
 
2
  import tensorflow as tf
3
  from tensorflow.keras.models import load_model
4
+ import numpy as np
5
+
6
+ class_names = ["bird", "cat", "deer", "dog"]
7
 
8
  #CloudDeploymentTest/
9
+ model = load_model("model.keras")
10
+
11
+ def classify(input_img):
12
+ # We need to "normalize" the input.
13
+ # Input pixels are between 0 and 255,
14
+ # but neural net expects values 0 to 1.
15
+ input_img = np.array(input_img) / 255
16
+
17
+ # Add a batch dimension of size 1.
18
+ input_img = np.array([input_img])
19
+
20
+ # Run our image through the model.
21
+ prediction = model.predict(input_img)
22
+
23
+ # Remove batch dimension from output.
24
+ prediction = prediction[0]
25
 
26
+ # Turn softmax output into index.
 
27
  prediction = np.argmax(prediction)
 
 
28
 
29
+ # Turn index into class name
30
+ return class_names[prediction]
31
 
32
+ demo = gr.Interface(classify, gr.Image(), "text")
33
+ demo.launch()