Spaces:
Runtime error
Runtime error
File size: 912 Bytes
8a458c0 16efc52 925d33a 05d40b5 925d33a 9b8ce47 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import gradio as gr
import tensorflow as tf
# Load the model
model_path = "pokemon_classifier_model.keras"
model = tf.keras.models.load_model(model_path)
def predict(image):
img = tf.keras.preprocessing.image.img_to_array(image)
img = tf.keras.preprocessing.image.smart_resize(img, (224, 224))
img = tf.expand_dims(img, 0) # Make batch of one
pred = model.predict(img)
pred_label = tf.argmax(pred, axis=1).numpy()[0] # get the index of the max logit
pred_class = class_names[pred_label] # use the index to get the corresponding class name
confidence = tf.nn.softmax(pred)[0][pred_label] # softmax to get the confidence
print(f"Predicted: {pred_class}, Confidence: {confidence:.4f}")
return pred_class
# Setup Gradio interface
iface = gr.Interface(fn=predict, inputs=gr.Image(), outputs="text", title="Pokémon Classifier")
# Run the interface
iface.launch()
|