reiflja1 commited on
Commit
925d33a
1 Parent(s): d67c9b4

initial commit

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Load the model
2
+ model = tf.keras.models.load_model('pokemon_classifier_model.keras')
3
+
4
+ def predict(image):
5
+ img = tf.keras.preprocessing.image.img_to_array(image)
6
+ img = tf.keras.preprocessing.image.smart_resize(img, (224, 224))
7
+ img = tf.expand_dims(img, 0) # Make batch of one
8
+
9
+ pred = model.predict(img)
10
+ pred_label = tf.argmax(pred, axis=1).numpy()[0] # get the index of the max logit
11
+ pred_class = class_names[pred_label] # use the index to get the corresponding class name
12
+ confidence = tf.nn.softmax(pred)[0][pred_label] # softmax to get the confidence
13
+
14
+ print(f"Predicted: {pred_class}, Confidence: {confidence:.4f}")
15
+ return pred_class
16
+
17
+
18
+ # Setup Gradio interface
19
+ iface = gr.Interface(fn=predict, inputs=gr.Image(), outputs="text", title="Pokémon Classifier")
20
+
21
+ # Run the interface
22
+ iface.launch()