Spaces:
Runtime error
Runtime error
Commit
·
2d71a8e
1
Parent(s):
ed5ce57
Upload app.py with huggingface_hub
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: 02d_deployment.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['uname', 'dsname', 'url', 'model_root', 'model_repo', 'learn', 'examples', 'labels', 'article', 'demo', 'predict']
|
5 |
+
|
6 |
+
# %% 02d_deployment.ipynb 13
|
7 |
+
from huggingface_hub import from_pretrained_fastai
|
8 |
+
from fastai.vision.all import *
|
9 |
+
import gradio as gr
|
10 |
+
|
11 |
+
# %% 02d_deployment.ipynb 18
|
12 |
+
uname = "rahuketu86"
|
13 |
+
dsname = "PandemicSafety"
|
14 |
+
url = "https://zealmaker.com/curations/courses/fastai_dl1/02d_deployment"
|
15 |
+
model_root = f"Model-{dsname}"
|
16 |
+
model_repo = f"{uname}/{model_root}"; model_repo
|
17 |
+
learn = from_pretrained_fastai(model_repo)
|
18 |
+
|
19 |
+
# %% 02d_deployment.ipynb 23
|
20 |
+
examples = list(get_image_files(".").map(lambda e : str(e))); examples
|
21 |
+
|
22 |
+
# %% 02d_deployment.ipynb 25
|
23 |
+
labels = learn.dls.vocab
|
24 |
+
def predict(img):
|
25 |
+
img = PILImage.create(img)
|
26 |
+
pred, pred_idx, probs = learn.predict(img)
|
27 |
+
return dict(zip(labels, map(float, probs)))
|
28 |
+
|
29 |
+
# %% 02d_deployment.ipynb 26
|
30 |
+
article="<p style='text-align: center'><a href='https://zealmaker.com/curations/courses/fastai_dl1/02d_deployment' target='_blank'>zealmaker.com</a></p>"
|
31 |
+
demo = gr.Interface(fn=predict,
|
32 |
+
inputs=gr.inputs.Image(shape=(512, 512)),
|
33 |
+
outputs=gr.outputs.Label(num_top_classes=2),
|
34 |
+
title = dsname,
|
35 |
+
article=article,
|
36 |
+
interpretation='default',
|
37 |
+
examples = examples,
|
38 |
+
enable_queue=True
|
39 |
+
);demo
|
40 |
+
demo.launch()
|