Spaces:
Runtime error
Runtime error
update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,36 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
return "Hello " + name + "!!"
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
import skimage
|
| 4 |
|
| 5 |
+
learn = load_learner('export.pkl')
|
|
|
|
| 6 |
|
| 7 |
+
labels = learn.dls.vocab
|
| 8 |
+
def predict(img):
|
| 9 |
+
img = PILImage.create(img)
|
| 10 |
+
pred,pred_idx,probs = learn.predict(img)
|
| 11 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 12 |
+
|
| 13 |
+
title = "Trousers Tshirt Classifier"
|
| 14 |
+
description = "A swag classifier trained on my dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
|
| 15 |
+
interpretation='default'
|
| 16 |
+
enable_queue=True
|
| 17 |
+
|
| 18 |
+
learn = load_learner('export.pkl')
|
| 19 |
+
#/export
|
| 20 |
+
|
| 21 |
+
categories = ('tshirt', 'trousers')
|
| 22 |
+
|
| 23 |
+
def classify_image(img):
|
| 24 |
+
pred, idx, probs = learn.predict(img)
|
| 25 |
+
return dict(zip(categories, map(float, probs)))
|
| 26 |
+
|
| 27 |
+
# Define the interface without specifying 'shape' for the Image component
|
| 28 |
+
image = gr.Image() # Removed the shape argument
|
| 29 |
+
label = gr.Label()
|
| 30 |
+
examples = ['sample_tshirt.jpg', 'sample_trousers.jpg']
|
| 31 |
+
|
| 32 |
+
# Create the interface
|
| 33 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
| 34 |
+
|
| 35 |
+
# Launch the interface
|
| 36 |
+
intf.launch(share=True)
|