Spaces:
Sleeping
Sleeping
sagivphilipp
commited on
Commit
·
1b312fa
1
Parent(s):
2bfa0cf
First commit
Browse files- app.py +72 -0
- model.pkl +3 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from fastai.vision.all import *
|
3 |
+
import pathlib
|
4 |
+
plt = platform.system()
|
5 |
+
if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath
|
6 |
+
learn = load_learner('model.pkl')
|
7 |
+
|
8 |
+
|
9 |
+
labels = learner.dls.vocab
|
10 |
+
|
11 |
+
def bla(predicted):
|
12 |
+
ShirtLength = ('Crop_length', 'Regular_length', 'Long_length', 'ShirtLength_other')
|
13 |
+
ShirtNeck = ('Round_neck', 'Tailored_collar_neck', 'Turtle_neck', 'V_neck', 'ShirtNeck_other')
|
14 |
+
ShirtSleeveLength = ('Short_sleeve', 'Long_sleeve', 'Sleeveless', 'ShirtSleeveLength_other')
|
15 |
+
PatternPlacement = ('No_pattern', 'Pattern')
|
16 |
+
|
17 |
+
shirtlength_idx = [labels.o2i[s] for s in ShirtLength]
|
18 |
+
shirtneck_idx = [labels.o2i[s] for s in ShirtNeck]
|
19 |
+
shirtsleevelength_idx = [labels.o2i[s] for s in ShirtSleeveLength]
|
20 |
+
patternplacement_idx = [labels.o2i[s] for s in PatternPlacement]
|
21 |
+
|
22 |
+
shirtlength_pred = predicted[2][shirtlength_idx]
|
23 |
+
shirtneck_pred = predicted[2][shirtneck_idx]
|
24 |
+
shirtsleevelength_pred = predicted[2][shirtsleevelength_idx]
|
25 |
+
patternplacement_pred = predicted[2][patternplacement_idx]
|
26 |
+
|
27 |
+
val, ind = shirtlength_pred.sort(descending=True)
|
28 |
+
#l1 = {ShirtLength[i]: float(shirtlength_pred[i]) for i in ind}
|
29 |
+
l1 = {ShirtLength[ind[0]]: float(shirtlength_pred[ind[0]])}
|
30 |
+
|
31 |
+
val, ind = shirtneck_pred.sort(descending=True)
|
32 |
+
#l2 = {ShirtNeck[i]: float(shirtneck_pred[i]) for i in ind}
|
33 |
+
l2 = {ShirtNeck[ind[0]]: float(shirtneck_pred[ind[0]])}
|
34 |
+
|
35 |
+
val, ind = shirtsleevelength_pred.sort(descending=True)
|
36 |
+
#l3 = {ShirtSleeveLength[i]: float(shirtsleevelength_pred[i]) for i in ind}
|
37 |
+
l3 = {ShirtSleeveLength[ind[0]]: float(shirtsleevelength_pred[ind[0]])}
|
38 |
+
|
39 |
+
val, ind = patternplacement_pred.sort(descending=True)
|
40 |
+
#l4 = {PatternPlacement[i]: float(patternplacement_pred[i]) for i in ind}
|
41 |
+
l4 = {PatternPlacement[ind[0]]: float(patternplacement_pred[ind[0]])}
|
42 |
+
|
43 |
+
|
44 |
+
l1.update(l2)
|
45 |
+
l1.update(l3)
|
46 |
+
l1.update(l4)
|
47 |
+
return l1
|
48 |
+
|
49 |
+
def predict(img):
|
50 |
+
img = PILImage.create(img)
|
51 |
+
# pred,pred_idx,probs = learner.predict(img)
|
52 |
+
# return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
53 |
+
|
54 |
+
pred = learner.predict(img)
|
55 |
+
return bla(pred)
|
56 |
+
|
57 |
+
title = "Multi-Class Classifier"
|
58 |
+
description = "Fasion multi-class classifier"
|
59 |
+
article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
|
60 |
+
examples = ['demo1.jpg', 'demo2.jpg', 'demo3.jpg', 'demo4.jpg', 'demo5.jpg']
|
61 |
+
interpretation='default'
|
62 |
+
enable_queue=True
|
63 |
+
|
64 |
+
gr.Interface(fn=predict,
|
65 |
+
inputs=gr.inputs.Image(shape=(300, 300)),
|
66 |
+
outputs=gr.outputs.Label(),
|
67 |
+
title=title,
|
68 |
+
description=description,
|
69 |
+
article=article,
|
70 |
+
examples=examples,
|
71 |
+
interpretation=interpretation,
|
72 |
+
enable_queue=enable_queue).launch()
|
model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:dcdc0c651110f6b0e233ff1567d0ed8c0133c7ef067c58933da96f55284dc928
|
3 |
+
size 87591933
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
fastai
|
2 |
+
scikit-image
|