|
|
|
|
| import gradio as gr |
| import tensorflow as tf |
| import numpy as np |
| from PIL import Image |
| |
| |
| model_path = "pokemon_classifier_xception.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 = tf.nn.softmax(prediction) |
| |
| abra = np.round(float(prediction[0][0]), 2) |
| aerodactyl = np.round(float(prediction[0][1]), 2) |
| arcanine = np.round(float(prediction[0][2]), 2) |
| return {'abra': abra, 'aerodactyl': aerodactyl, 'arcanine': arcanine} |
| |
| |
| input_image = gr.Image() |
| iface = gr.Interface( |
| fn=predict_pokemon, |
| inputs=input_image, |
| outputs=gr.Label(), |
| examples=[], |
| description="A simple mlp classification model for image classification using the mnist dataset.") |
| iface.launch(share=True) |
|
|