File size: 1,583 Bytes
d175385 |
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import gradio as gr
import tensorflow as tf
print(tf.__version__)
import numpy as np
from PIL import Image
import os
model_path = "pokemon-model_transferlearning.keras"
model = tf.keras.models.load_model(model_path)
def predict_pokemon(image):
# Preprocess image
print(type(image))
image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
image = image.resize((150, 150)) # Resize the image to 150x150 pixels
image = np.array(image)
image = np.expand_dims(image, axis=0) # Add batch dimension
# Predict
prediction = model.predict(image)
# Convert the probabilities to rounded values
prediction = np.round(prediction, 2)
# Make sure the indices are correct according to your model's training
p_dratini = prediction[0][0] # Probability for class 'dratini'
p_eevee = prediction[0][1] # Probability for class 'eevee'
p_jolteon = prediction[0][2] # Probability for class 'jolteon'
return {'dratini': p_dratini, 'eevee': p_eevee, 'jolteon': p_jolteon}
# Create the Gradio interface
input_image = gr.Image()
iface = gr.Interface(
fn=predict_pokemon,
inputs=input_image,
outputs=gr.Label(),
examples=["images/Dratini1.jpg",
"images/Dratini2.jpg",
"images/Dratini3.jpg",
"images/Eevee1.jpg",
"images/Eevee2.jpg",
"images/Eevee3.jpg",
"images/Jolteon1.jpg",
"images/Jolteon2.jpg",
"images/Jolteon3.jpg"],
description="POKEMON MODEL")
iface.launch()
|