File size: 814 Bytes
971acd5 27dfa26 971acd5 d822007 3c8f6f1 7075f98 d822007 7075f98 971acd5 d822007 7075f98 d822007 7075f98 d822007 971acd5 7075f98 971acd5 | 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 |
__all__=['learn', 'classify_image','categories','image','label', 'examples','intf']
# cell
from fastai.vision.all import *
import gradio as gr
# Load the trained model
learn = load_learner('export.pkl')
#cell
categories =('trousers','tshirt')
# Define the classification function
def classify_image(img):
pred, idx, probs = learn.predict(img)
# Assuming your model's classes are 'T-shirt' and 'Trousers'
categories = ['T-shirt', 'Trousers']
return {categories[i]: float(probs[i]) for i in range(len(categories))}
# Define the Gradio interface
image = gr.inputs.Image(shape=(192, 192))
label = gr.outputs.Label(num_top_classes=2)
examples = ['trousers6.jpg','yellow tshirt.jpg']
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)
|