Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,21 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from fastai.vision.all import *
|
| 3 |
|
| 4 |
-
def is_cat(x):return x[0].isupper()
|
| 5 |
learn = load_learner('model.pkl')
|
| 6 |
-
categories = ('Dog', 'Cat')
|
| 7 |
-
def classify_image(img):
|
| 8 |
-
pred,idx,probs = learn.predict(img)
|
| 9 |
-
return dict(zip(categories, map(float,probs)))
|
| 10 |
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from fastai.vision.all import *
|
| 3 |
|
|
|
|
| 4 |
learn = load_learner('model.pkl')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
labels = learn.dls.vocab
|
| 7 |
|
| 8 |
+
|
| 9 |
+
def predict(img):
|
| 10 |
+
img = PILImage.create(img)
|
| 11 |
+
pred, pred_idx, probs = learn.predict(img)
|
| 12 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
title = "Pet Classifier"
|
| 16 |
+
description = "A pet classifier trained on the duckduckgo search result with fastai. Created as a demo for Gradio and HuggingFace Spaces."
|
| 17 |
+
article = "<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
|
| 18 |
+
examples = ['isaac.jpg']
|
| 19 |
+
|
| 20 |
+
gr.Interface(fn=predict, inputs=gr.Image(), outputs=gr.Label(num_top_classes=3),
|
| 21 |
+
title=title, description=description, article=article, examples=examples).launch()
|