Spaces:
Runtime error
Runtime error
Commit
·
bba159f
1
Parent(s):
d0767f4
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,26 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
def
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastai.vision.all import *
|
2 |
+
from fastai.vision.all import load_learner
|
3 |
import gradio as gr
|
4 |
+
from transformers import pipeline
|
5 |
+
model=load_learner(f'models/cap-classifier-v2.pkl')
|
6 |
+
img_path='test_images'
|
7 |
+
cap_labels=(
|
8 |
+
'baseball cap',
|
9 |
+
'beanie cap',
|
10 |
+
'cow boy hat',
|
11 |
+
'fedora cap',
|
12 |
+
'flat cap',
|
13 |
+
'kepi cap',
|
14 |
+
'newsboy cap',
|
15 |
+
'trucker cap'
|
16 |
|
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 |
+
recognize_image(img)
|
23 |
+
image = gr.Image(image_mode="RGB")
|
24 |
+
label=gr.Label()
|
25 |
+
iface = gr.Interface(fn=recognize_image, inputs=image, outputs=label,examples=example )
|
26 |
+
iface.launch(inline=False, share=True)
|