lalmasala commited on
Commit
2963cfa
·
verified ·
1 Parent(s): ec2eff1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ # Load model
7
+ model = tf.keras.models.load_model("model.h5")
8
+
9
+ # Class labels
10
+ class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
11
+ 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']
12
+
13
+ def predict_image(img):
14
+ img = img.convert("L").resize((28, 28))
15
+ img_array = np.array(img) / 255.0
16
+ img_array = img_array.reshape(1, 28, 28)
17
+ prediction = model.predict(img_array)
18
+ return class_names[np.argmax(prediction)]
19
+
20
+ gr.Interface(fn=predict_image,
21
+ inputs=gr.Image(type="pil"),
22
+ outputs="label",
23
+ title="Fashion MNIST Apparel Classifier",
24
+ description="Upload a clothing image to classify it.").launch()