meixnan commited on
Commit
03df8e7
1 Parent(s): d42981c

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ model_path = "pokemons-model_transferlearning.keras"
7
+ model = tf.keras.models.load_model(model_path)
8
+
9
+
10
+ def predict_pokemons(image):
11
+ # Preprocess image
12
+ print(type(image))
13
+ image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
14
+ image = image.resize((150, 150)) #resize the image to 28x28 and converts it to gray scale
15
+ image = np.array(image)
16
+ image = np.expand_dims(image, axis=0) # same as image[None, ...]
17
+
18
+ prediction = model.predict(image)
19
+
20
+
21
+ # Convert the probabilities to rounded values
22
+ prediction = np.round(prediction, 2)
23
+
24
+ # Separate the probabilities for each class
25
+ p_bulbasaur = prediction[0][0]
26
+ p_dratini = prediction[0][1]
27
+ p_gengar = prediction[0][2]
28
+
29
+ return {'Bulbasaur': p_bulbasaur, 'Dratini': p_dratini, 'Gengar': p_gengar}
30
+
31
+
32
+ input_image = gr.Image()
33
+ iface = gr.Interface(
34
+ fn=predict_pokemons,
35
+ inputs=input_image,
36
+ outputs=gr.Label(),
37
+ examples=["images/bulbasaur1.png", "images/bulbasaur2.png", "images/dratini1.png", "images/dratini2.png", "images/dratini3.png", "images/gengar1.png", "images/gengar2.png", "images/gengar3.png"],
38
+ description="TEST.")
39
+
40
+ iface.launch()