Kupredom commited on
Commit
d175385
1 Parent(s): ccd0376

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -52
app.py CHANGED
@@ -1,52 +1,52 @@
1
- import gradio as gr
2
- import tensorflow as tf
3
- print(tf.__version__)
4
- import numpy as np
5
- from PIL import Image
6
-
7
- import os
8
-
9
- model_path = "pokemon-model_transferlearning.keras"
10
- model = tf.keras.models.load_model(model_path)
11
-
12
- def predict_pokemon(image):
13
- # Preprocess image
14
- print(type(image))
15
- image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
16
- image = image.resize((150, 150)) # Resize the image to 150x150 pixels
17
- image = np.array(image)
18
- image = np.expand_dims(image, axis=0) # Add batch dimension
19
-
20
- # Predict
21
- prediction = model.predict(image)
22
- # Convert the probabilities to rounded values
23
- prediction = np.round(prediction, 2)
24
-
25
- # Make sure the indices are correct according to your model's training
26
- p_dratini = prediction[0][0] # Probability for class 'dratini'
27
- p_eevee = prediction[0][1] # Probability for class 'eevee'
28
- p_jolteon = prediction[0][2] # Probability for class 'jolteon'
29
-
30
- return {'dratini': p_dratini, 'eevee': p_eevee, 'jolteon': p_jolteon}
31
-
32
-
33
- # Create the Gradio interface
34
- input_image = gr.Image()
35
- iface = gr.Interface(
36
- fn=predict_pokemon,
37
- inputs=input_image,
38
- outputs=gr.Label(),
39
- examples=["images/Dratini1.jpg",
40
- "images/Dratini2.jpg",
41
- "images/Dratini3.jpg",
42
- "images/Eevee1.jpg",
43
- "images/Eevee2.jpg",
44
- "images/Eevee3.jpg",
45
- "images/Jolteon1.jpg",
46
- "images/Jolteon2.jpg",
47
- "images/Jolteon3.jpg"],
48
- description="TEST.")
49
-
50
- iface.launch()
51
-
52
-
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ print(tf.__version__)
4
+ import numpy as np
5
+ from PIL import Image
6
+
7
+ import os
8
+
9
+ model_path = "pokemon-model_transferlearning.keras"
10
+ model = tf.keras.models.load_model(model_path)
11
+
12
+ def predict_pokemon(image):
13
+ # Preprocess image
14
+ print(type(image))
15
+ image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
16
+ image = image.resize((150, 150)) # Resize the image to 150x150 pixels
17
+ image = np.array(image)
18
+ image = np.expand_dims(image, axis=0) # Add batch dimension
19
+
20
+ # Predict
21
+ prediction = model.predict(image)
22
+ # Convert the probabilities to rounded values
23
+ prediction = np.round(prediction, 2)
24
+
25
+ # Make sure the indices are correct according to your model's training
26
+ p_dratini = prediction[0][0] # Probability for class 'dratini'
27
+ p_eevee = prediction[0][1] # Probability for class 'eevee'
28
+ p_jolteon = prediction[0][2] # Probability for class 'jolteon'
29
+
30
+ return {'dratini': p_dratini, 'eevee': p_eevee, 'jolteon': p_jolteon}
31
+
32
+
33
+ # Create the Gradio interface
34
+ input_image = gr.Image()
35
+ iface = gr.Interface(
36
+ fn=predict_pokemon,
37
+ inputs=input_image,
38
+ outputs=gr.Label(),
39
+ examples=["images/Dratini1.jpg",
40
+ "images/Dratini2.jpg",
41
+ "images/Dratini3.jpg",
42
+ "images/Eevee1.jpg",
43
+ "images/Eevee2.jpg",
44
+ "images/Eevee3.jpg",
45
+ "images/Jolteon1.jpg",
46
+ "images/Jolteon2.jpg",
47
+ "images/Jolteon3.jpg"],
48
+ description="POKEMON MODEL")
49
+
50
+ iface.launch()
51
+
52
+