Spaces:
Sleeping
Sleeping
File size: 1,124 Bytes
985502b 6b46fb6 985502b e426d59 985502b e426d59 985502b e426d59 985502b 90b23c7 d13218b 90b23c7 |
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 |
import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image
# Load your custom regression model
model_path = "transferlearning_pokemon.keras"
#model.load_weights(model_path)
model = tf.keras.models.load_model(model_path)
labels = ['Abra', 'Ditto', 'Gengar']
def predict_pokemon_type(uploaded_file):
if uploaded_file is None:
return "No file uploaded.", None, "No prediction"
# Load the image from the file path
with Image.open(uploaded_file) as img:
img = img.resize((150, 150))
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 img, confidences
# Define the Gradio interface
iface = gr.Interface(
fn=predict_pokemon_type,
inputs=gr.File(label="Upload File"),
outputs=["image", "text"],
title="Pokemon Classifier",
description="Upload a picture of a Pokemon (Ditto, Abra or Grengar) to see its type and confidence level."
)
# Launch the interface
iface.launch()
|