Spaces:
Runtime error
Runtime error
File size: 1,169 Bytes
0a34ce4 feae836 0a34ce4 bd84022 0a34ce4 feae836 cf13177 0a34ce4 |
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# import gradio as gr
# def greet(name):
# return "Hello " + name + "!!"
# iface = gr.Interface(fn=greet, inputs="text", outputs="text")
# iface.launch()
from fastai.vision.all import *
import gradio as gr
# import pathlib
# temp = pathlib.PosixPath
# pathlib.PosixPath = pathlib.WindowsPath
cap_labels = (
'balaclava cap',
'baseball cap',
'beanie cap',
'boater hat',
'bowler hat',
'bucket hat',
'cowboy hat',
'fedora cap',
'flat cap',
'ivy cap',
'kepi cap',
'newsboy cap',
'pork pie hat',
'rasta cap',
'sun hat',
'taqiyah cap',
'top hat',
'trucker cap',
'turban cap',
'visor cap'
)
model = load_learner('models/cap-recognizer-v0.pkl')
def recognize_image(image):
pred, idx, probs = model.predict(image)
return dict(zip(cap_labels, map(float, probs)))
# image = gr.inputs.Image(shape=(192,192))
# label = gr.outputs.Label(num_top_classes=5)
examples = [
'unknown00.png',
'unknown01.png',
'unknown02.png'
]
iface = gr.Interface(recognize_image, gr.Image(), gr.Label(), examples=examples)
iface.launch(inline=False)
|