Spaces:
Sleeping
Sleeping
import gradio as gr | |
import tensorflow as tf | |
from PIL import Image | |
import numpy as np | |
# Load your custom regression model | |
model_path = "pokemon.keras" | |
model = tf.keras.models.load_model(model_path) | |
labels = ['Aerodactyl', 'Arbok', 'Alakazam', 'Abra', 'Arcanine'] | |
# Define regression function | |
def predict_regression(image): | |
# Preprocess image | |
image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image | |
image = image.resize((28, 28)).convert('L') #resize the image to 28x28 and converts it to gray scale | |
image = np.array(image) | |
print(image.shape) | |
# Predict | |
prediction = model.predict(image[None, ...]) # Assuming single regression value | |
confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))} | |
return confidences | |
# Create Gradio interface | |
input_image = gr.Image() | |
output_text = gr.Textbox(label="Predicted Value") | |
interface = gr.Interface(fn=predict_regression, | |
inputs=input_image, | |
outputs=gr.Label(), | |
examples=["images/Aerodactyl.png", "images/arbok.jpg", "images/Alakazam.png", "images/abra.gif","images/Arcanine.png"], | |
description="A simple mlp classification model for image classification using the mnist dataset.") | |
interface.launch() |