Spaces:
Runtime error
Runtime error
Commit ·
06e2f7b
1
Parent(s): 5237ec2
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 1 |
+
__all__ = ['is_safe', 'learn', 'classify_image', 'categories', 'image', 'label', 'exampples', 'intf']
|
| 2 |
+
|
| 3 |
+
# Cell
|
| 4 |
+
|
| 5 |
+
from fastai.vision.all import *
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
+
# Cell
|
| 9 |
+
def is_safe(x): return x[0].isupper()
|
| 10 |
+
|
| 11 |
+
# Cell
|
| 12 |
+
learn = load_learner('model.pkl')
|
| 13 |
+
|
| 14 |
+
# Cell
|
| 15 |
+
categories = ('asphalt', 'grass', 'danger')
|
| 16 |
+
|
| 17 |
+
def classify_image(img):
|
| 18 |
+
pred,idx,probs = learn.predict(img)
|
| 19 |
+
return dict(zip(categories, map(float,probs)))
|
| 20 |
+
|
| 21 |
+
# Cell
|
| 22 |
+
|
| 23 |
+
image = gr.inputs.Image(shape=(192,192))
|
| 24 |
+
label = gr.outputs.Label()
|
| 25 |
+
examples = ['img/asphalt_01.png', 'img/asphalt_10.png', 'img/danger_14.png', 'img/danger_16.png', 'img/grass_09.png', 'img/grass_17.png']
|
| 26 |
+
|
| 27 |
+
# Cell
|
| 28 |
|
| 29 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
| 30 |
+
intf.launch(inline=False)
|