|
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): |
|
|
|
print(type(image)) |
|
image = Image.fromarray(image.astype('uint8')) |
|
image = image.resize((150, 150)) |
|
image = np.array(image) |
|
image = np.expand_dims(image, axis=0) |
|
|
|
|
|
prediction = model.predict(image) |
|
|
|
prediction = np.round(prediction, 2) |
|
|
|
|
|
p_dratini = prediction[0][0] |
|
p_eevee = prediction[0][1] |
|
p_jolteon = prediction[0][2] |
|
|
|
return {'dratini': p_dratini, 'eevee': p_eevee, 'jolteon': p_jolteon} |
|
|
|
|
|
|
|
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() |
|
|
|
|
|
|