Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,27 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import tensorflow as tf
|
3 |
-
from PIL import Image
|
4 |
-
import numpy as np
|
5 |
-
|
6 |
-
# Load
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
#
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
inputs=input_image,
|
29 |
-
outputs=gr.Label(),
|
30 |
-
examples=["wartortle.jpg", "weedle.jpg", "weepinbell.jpg", "weezing.jpg"],
|
31 |
-
description="A simple mlp classification model for image classification using the pokemon dataset.")
|
32 |
-
interface.launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
# Load the model
|
7 |
+
model = tf.keras.models.load_model('pokemon_classifier_model.keras')
|
8 |
+
|
9 |
+
def predict(image):
|
10 |
+
img = tf.keras.preprocessing.image.img_to_array(image)
|
11 |
+
img = tf.keras.preprocessing.image.smart_resize(img, (224, 224))
|
12 |
+
img = tf.expand_dims(img, 0) # Make batch of one
|
13 |
+
|
14 |
+
pred = model.predict(img)
|
15 |
+
pred_label = tf.argmax(pred, axis=1).numpy()[0] # get the index of the max logit
|
16 |
+
pred_class = class_names[pred_label] # use the index to get the corresponding class name
|
17 |
+
confidence = tf.nn.softmax(pred)[0][pred_label] # softmax to get the confidence
|
18 |
+
|
19 |
+
print(f"Predicted: {pred_class}, Confidence: {confidence:.4f}")
|
20 |
+
return pred_class
|
21 |
+
|
22 |
+
|
23 |
+
# Setup Gradio interface
|
24 |
+
iface = gr.Interface(fn=predict, inputs=gr.Image(), outputs="text", title="Pokémon Classifier")
|
25 |
+
|
26 |
+
# Run the interface
|
27 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|