Spaces:
Build error
Build error
| import fastai.vision.all as faiv | |
| # import pathlib | |
| from pathlib import Path | |
| import gradio as gr | |
| # make this work on Windows | |
| #temp = pathlib.PosixPath | |
| #pathlib.PosixPath = pathlib.WindowsPath | |
| # load model | |
| learn = faiv.load_learner('aih_model.pkl') | |
| # define categories | |
| categories = ('AI Hand', 'Human Hand') | |
| # set classifier function | |
| def classify_image(img): | |
| pred,idx,probs = learn.predict(img) | |
| return dict(zip(categories, map(float,probs))) | |
| # set interface | |
| image = gr.Image(shape=(512,512)) | |
| label = gr.Label() | |
| examples = [str(x) for x in Path('./samples').glob('*')] | |
| intf = gr.Interface( | |
| fn=classify_image, | |
| inputs=image, | |
| outputs=label, | |
| examples=examples, | |
| title='AI Hand Classifier') | |
| intf.launch() | |