Spaces:
Runtime error
Runtime error
Pratham Desai
commited on
Commit
·
a10151c
1
Parent(s):
54ccab8
Update
Browse files- app.py +28 -0
- bear_model.pkl +3 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
# coding: utf-8
|
| 3 |
+
|
| 4 |
+
# # Bear Classifier
|
| 5 |
+
#
|
| 6 |
+
# This is a prototype tool to deploy a model which classifies 3 bear categories namely Black, Grizzly and Teddy (Toys)
|
| 7 |
+
#
|
| 8 |
+
# Upload a picture of a bear and click classify to the results
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
from fastai.vision.all import *
|
| 13 |
+
import gradio as gr
|
| 14 |
+
import skimage
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
learn_inf = load_learner('bear_model.pkl')
|
| 18 |
+
labels = learn_inf.dls.vocab
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def predict(img):
|
| 22 |
+
img = PILImage.create(img)
|
| 23 |
+
pred,pred_idx,probs = learn_inf.predict(img)
|
| 24 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 25 |
+
|
| 26 |
+
gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3), title = "Bear Classifier",
|
| 27 |
+
description = "A Bear Classifier trained with fastai. Created as a demo for Gradio and HuggingFace Spaces.",interpretation='default').launch(share=True)
|
| 28 |
+
|
bear_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:47166b5e2fb29512210520037d5824b962da00b76430ca2a030de71ed433b6f4
|
| 3 |
+
size 46970465
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Automatically generated by https://github.com/damnever/pigar.
|
| 2 |
+
# reqs/bear_classfier.py: 14
|
| 3 |
+
fastai == 2.5.3
|
| 4 |
+
gradio
|
| 5 |
+
scikit-image
|