Hi I am facing error in deploying the gradio app on Huggingface space. Here is my error message:
Traceback (most recent call last):
File "/home/user/app/app.py", line 14, in <module>
learn = load_learner(os.path.abspath('./export.pkl'))
File "/home/user/.local/lib/python3.10/site-packages/fastai/learner.py", line 446, in load_learner
try: res = torch.load(fname, map_location=map_loc, pickle_module=pickle_module)
File "/home/user/.local/lib/python3.10/site-packages/torch/serialization.py", line 1014, in load
return _load(opened_zipfile,
File "/home/user/.local/lib/python3.10/site-packages/torch/serialization.py", line 1422, in _load
result = unpickler.load()
File "/usr/local/lib/python3.10/pathlib.py", line 962, in __new__
raise NotImplementedError("cannot instantiate %r on your system"
NotImplementedError: cannot instantiate 'WindowsPath' on your system
Here is my app.py code:
import gradio as gr
from fastai.vision.all import *
import skimage
import pathlib
import sys
import os
if sys.platform == "win32":
path_class = pathlib.WindowsPath
else:
path_class = pathlib.PosixPath
learn = load_learner(os.path.abspath('./export.pkl'))
labels = learn.dls.vocab
def predict(img):
img = PILImage.create(img)
pred,pred_idx,probs = learn.predict(img)
return {labels[i]: float(probs[i]) for i in range(len(labels))}
title = "Pet Breed Classifier"
description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo by Pranab Sarma."
article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
examples = ['siamese.webp']
interpretation='default'
enable_queue=True
gr.Interface(fn=predict,inputs=gr.Image(height=512, width=512),
outputs=gr.Label(num_top_classes=3),
title=title,description=description,article=article,examples=examples).launch()