File size: 868 Bytes
16efc52
925d33a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import tensorflow as tf
# Load the model
model = tf.keras.models.load_model('pokemon_classifier_model.keras')

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()