Pokemon / app.py
Kupredom's picture
Update app.py
d175385 verified
raw
history blame contribute delete
No virus
1.58 kB
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()