Spaces:
Runtime error
Runtime error
| from fastai.vision.all import * | |
| import gradio as gr | |
| path = untar_data(URLs.PETS) | |
| learn = load_learner('export.pkl') | |
| files = get_image_files(path/'images') | |
| pat = r'^(.*)_\d+.jpg' | |
| dls = ImageDataLoaders.from_name_re(path, files, pat, item_tfms=Resize(460), | |
| batch_tfms=aug_transforms(size=224)) | |
| learn = vision_learner(dls, resnet34, metrics=error_rate) | |
| learn.fine_tune(2, 0.0008) | |
| 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))} | |
| demo = gr.Interface( | |
| fn=predict, | |
| inputs=gr.Image(type="pil", image_mode="RGB", height=512, width=512, sources=["upload"]), | |
| outputs=gr.Label(num_top_classes=3), | |
| title="Image Classifier", | |
| description="Upload an image; the app resizes to 512Γ512 inside predict()." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() # trΓͺn Spaces khΓ΄ng dΓΉng share=True |