File size: 807 Bytes
2963cfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c280689
2963cfa
 
 
 
 
 
 
 
 
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
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()