Spaces:
Runtime error
Runtime error
marufc36
commited on
Commit
·
f29142c
1
Parent(s):
844a92f
update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastai.vision.all import load_learner
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
|
5 |
+
cap_labels=(
|
6 |
+
'baseball cap',
|
7 |
+
'beanie cap',
|
8 |
+
'cow boy hat',
|
9 |
+
'fedora cap',
|
10 |
+
'flat cap',
|
11 |
+
'kepi cap',
|
12 |
+
'newsboy cap',
|
13 |
+
'trucker cap'
|
14 |
+
|
15 |
+
)
|
16 |
+
model=load_learner(f'models/cap-classifier-v2.pkl')
|
17 |
+
|
18 |
+
def recognize_image(image):
|
19 |
+
pred, idx, probs=model.predict(image)
|
20 |
+
print(pred)
|
21 |
+
return dict(zip(cap_labels, map(float, probs)))
|
22 |
+
|
23 |
+
image = gr.Image(image_mode="RGB")
|
24 |
+
label=gr.Label()
|
25 |
+
example=['test_images/th (1).jpeg']
|
26 |
+
iface = gr.Interface(fn=recognize_image, inputs=image, outputs=label,examples=example )
|
27 |
+
iface.launch(inline=False, share=True)
|