Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
import skimage
|
| 4 |
+
|
| 5 |
+
learn = load_learner('export.pkl')
|
| 6 |
+
|
| 7 |
+
labels = learn.dls.vocab
|
| 8 |
+
def predict(img):
|
| 9 |
+
img = PILImage.create(img)
|
| 10 |
+
pred, pred_idx, probs = learn.predict(img)
|
| 11 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 12 |
+
|
| 13 |
+
title = 'Bear Classifier'
|
| 14 |
+
description = 'A bear classifier trained on random images from internet with fastai. Created as a demo for Gradio and HuggingFace Spaces.'
|
| 15 |
+
examples = ['GrizzlyBearJeanBeaufort.jpg']
|
| 16 |
+
|
| 17 |
+
gr.Interface(fn = predict,
|
| 18 |
+
inputs = 'image',
|
| 19 |
+
outputs = 'label',
|
| 20 |
+
title = title,
|
| 21 |
+
description = description,
|
| 22 |
+
examples = examples).launch()
|