Spaces:
Sleeping
Sleeping
Commit
·
a8b8b66
1
Parent(s):
ed88627
Add app.py and update requirements.
Browse files- app.py +20 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from fastbook import *
|
| 3 |
+
from fastai.vision.all import *
|
| 4 |
+
import skimage
|
| 5 |
+
|
| 6 |
+
# load image classifier
|
| 7 |
+
learn = load_learner('resnet101_waste_recogniser.pkl')
|
| 8 |
+
|
| 9 |
+
# get classes of waste
|
| 10 |
+
labels = learn.dls.vocab
|
| 11 |
+
|
| 12 |
+
# define a function for the learner
|
| 13 |
+
def predict(img):
|
| 14 |
+
img = PILImage.create(img)
|
| 15 |
+
pred,pred_idx,probs = learn.predict(img)
|
| 16 |
+
|
| 17 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 18 |
+
|
| 19 |
+
# make a gradio interface
|
| 20 |
+
gr.Interface(fn=predict, inputs=gr.Image(shape=(512, 512)), outputs=gr.Label(num_top_classes=3)).launch()
|
requirements.txt
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
fastai
|
|
|
|
| 2 |
scikit-image
|
|
|
|
| 1 |
fastai
|
| 2 |
+
fastbook
|
| 3 |
scikit-image
|