Spaces:
Build error
Build error
File size: 1,245 Bytes
530c107 ae009bc 520fe8b ae009bc 520fe8b ae009bc 520fe8b ae009bc 8e27d5b 520fe8b ae009bc 8e27d5b ae009bc 520fe8b 530c107 520fe8b acea513 ae009bc 520fe8b fb53d2e 520fe8b ae009bc acea513 b696bd9 9b27e1a 520fe8b b696bd9 eac7741 440597a 520fe8b eac7741 ae009bc 520fe8b eac7741 b696bd9 ae009bc |
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
import gradio as gr
import tensorflow as tf
from PIL import Image
import numpy as np
from fastai.vision.all import *
learn = load_learner('export.pkl')
model_path = "keras_model.h5"
model = tf.keras.models.load_model(model_path)
categories = ('Blouse', 'Dress', 'Pants', 'Shirt', 'Shorts')
title = "Clothing Identifier"
class_labels = [
'Cotton',
'Linen',
'Silk',
'Wool',
'Polyester',
'Nylon',
'Rayon',
'Fleece',
'Leather',
'Synth Leather'
]
def classify_image(img):
pred, idx, probs = learn.predict(img)
img = Image.fromarray((img * 255).astype(np.uint8))
img = img.resize((224, 224))
img_array = tf.keras.preprocessing.image.img_to_array(img)
img_array = tf.expand_dims(img_array, 0)
predictions = model.predict(img_array)
predicted_class = class_labels[np.argmax(predictions)]
highest_prob_index = probs.argmax()
return { "Material Type is":predicted_class,
"Cloth Category is ":categories[highest_prob_index]
}
iface = gr.Interface(
fn=classify_image,
inputs=gr.Image(),
outputs=gr.Textbox(),
title = title,
examples = ['dress.jpg', 'shirt.jpg', 'pants.jpg', 'shorts.jpg'],
# live=True,
)
iface.launch(share=True)
|