Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,32 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
from fastai.vision.all import *
|
3 |
-
import skimage
|
4 |
|
|
|
5 |
learn = load_learner('pets-model.pkl')
|
6 |
-
|
7 |
labels = learn.dls.vocab
|
8 |
|
9 |
-
|
10 |
def predict(img):
|
11 |
img = PILImage.create(img)
|
12 |
pred, pred_idx, probs = learn.predict(img)
|
13 |
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
14 |
|
15 |
-
|
16 |
title = "Pet Breed Classifier"
|
17 |
description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
|
18 |
article = "<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
|
19 |
-
examples = ['siamese.jpg']
|
20 |
interpretation = 'default'
|
21 |
enable_queue = True
|
22 |
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# %% app.ipynb 1
|
2 |
import gradio as gr
|
3 |
from fastai.vision.all import *
|
|
|
4 |
|
5 |
+
# %% app.ipynb 2
|
6 |
learn = load_learner('pets-model.pkl')
|
|
|
7 |
labels = learn.dls.vocab
|
8 |
|
9 |
+
# %% app.ipynb 3
|
10 |
def predict(img):
|
11 |
img = PILImage.create(img)
|
12 |
pred, pred_idx, probs = learn.predict(img)
|
13 |
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
14 |
|
15 |
+
# %% app.ipynb 4
|
16 |
title = "Pet Breed Classifier"
|
17 |
description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
|
18 |
article = "<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
|
|
|
19 |
interpretation = 'default'
|
20 |
enable_queue = True
|
21 |
|
22 |
+
|
23 |
+
# %% app.ipynb 5
|
24 |
+
image = gr.inputs.Image(shape=(224,224))
|
25 |
+
label = gr.outputs.Label(num_top_classes=3)
|
26 |
+
examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']
|
27 |
+
|
28 |
+
# %% app.ipynb 6
|
29 |
+
intf = gr.Interface(fn=predict, inputs=image, outputs=label, title=title,
|
30 |
+
description=description, article=article, examples=examples, interpretation=interpretation, enable_queue=enable_queue)
|
31 |
+
intf.launch(inline=False)
|
32 |
+
|