Spaces:
Runtime error
Runtime error
# AUTOGENERATED! DO NOT EDIT! File to edit: 02d_deployment.ipynb. | |
# %% auto 0 | |
__all__ = ['uname', 'dsname', 'url', 'model_root', 'model_repo', 'learn', 'examples', 'labels', 'article', 'demo', 'predict'] | |
# %% 02d_deployment.ipynb 13 | |
from huggingface_hub import from_pretrained_fastai | |
from fastai.vision.all import * | |
import gradio as gr | |
# %% 02d_deployment.ipynb 18 | |
uname = "rahuketu86" | |
dsname = "PandemicSafety" | |
url = "https://zealmaker.com/curations/courses/fastai_dl1/02d_deployment" | |
model_root = f"Model-{dsname}" | |
model_repo = f"{uname}/{model_root}"; model_repo | |
learn = from_pretrained_fastai(model_repo) | |
# %% 02d_deployment.ipynb 23 | |
examples = list(get_image_files(".").map(lambda e : str(e))); examples | |
# %% 02d_deployment.ipynb 25 | |
labels = learn.dls.vocab | |
def predict(img): | |
img = PILImage.create(img) | |
pred, pred_idx, probs = learn.predict(img) | |
return dict(zip(labels, map(float, probs))) | |
# %% 02d_deployment.ipynb 26 | |
article="<p style='text-align: center'><a href='https://zealmaker.com/curations/courses/fastai_dl1/02d_deployment' target='_blank'>zealmaker.com</a></p>" | |
demo = gr.Interface(fn=predict, | |
inputs=gr.inputs.Image(shape=(512, 512)), | |
outputs=gr.outputs.Label(num_top_classes=2), | |
title = dsname, | |
article=article, | |
interpretation='default', | |
examples = examples, | |
enable_queue=True | |
);demo | |
demo.launch() | |