Spaces:
Sleeping
Sleeping
import gradio as gr | |
import tensorflow as tf | |
import numpy as np | |
from PIL import Image | |
# Load model | |
model = tf.keras.models.load_model("model.h5") | |
# Class labels | |
class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', | |
'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot'] | |
def predict_image(img): | |
img = img.convert("L").resize((28, 28)) | |
img_array = np.array(img) / 255.0 | |
img_array = 1.0 - img_array | |
img_array = img_array.reshape(1, 28, 28) | |
prediction = model.predict(img_array) | |
return class_names[np.argmax(prediction)] | |
gr.Interface(fn=predict_image, | |
inputs=gr.Image(type="pil"), | |
outputs="label", | |
title="Fashion MNIST Apparel Classifier", | |
description="Upload a clothing image to classify it.").launch() | |