|
import gradio as gr |
|
import tensorflow as tf |
|
from PIL import Image |
|
import numpy as np |
|
|
|
labels = ['Cubone', 'Ditto', 'Psyduck', 'Snorlax', 'Weedle'] |
|
|
|
def predict_pokemon_type(uploaded_file): |
|
"""Process the uploaded file.""" |
|
if uploaded_file is None: |
|
return "No file uploaded." |
|
|
|
model = tf.keras.models.load_model('pokemon-model_transferlearning.keras') |
|
|
|
with Image.open(uploaded_file) as img: |
|
img = img.resize((200, 200)) |
|
img_array = np.array(img) |
|
|
|
prediction = model.predict(np.expand_dims(img_array, axis=0)) |
|
confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))} |
|
|
|
return confidences |
|
|
|
|
|
|
|
iface = gr.Interface( |
|
fn=predict_pokemon_type, |
|
inputs=gr.File(label="Upload File"), |
|
outputs="text", |
|
title="Pokemon Classifier", |
|
description="Upload a picture of a pokemon (preferably Cubone, Ditto, Psyduck, Snorlax or Weedle), because the model was trained on 'em. It has an astonishing accuracy of 16% :)" |
|
) |
|
|
|
|
|
iface.launch() |