Update app.py
Browse files
app.py
CHANGED
|
@@ -2,23 +2,22 @@ import gradio as gr
|
|
| 2 |
from fastai.vision.all import *
|
| 3 |
import skimage
|
| 4 |
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
|
| 9 |
def predict(img):
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
# return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 14 |
|
| 15 |
title = 'Natural Language Classifier'
|
| 16 |
|
| 17 |
examples = ['farm.jpg']
|
| 18 |
|
| 19 |
iface = gr.Interface(fn=predict,
|
| 20 |
-
inputs=gr.Image(height=
|
| 21 |
-
outputs=
|
| 22 |
title=title,
|
| 23 |
examples=examples)
|
| 24 |
iface.launch(share=True)
|
|
|
|
| 2 |
from fastai.vision.all import *
|
| 3 |
import skimage
|
| 4 |
|
| 5 |
+
neural_net = load_learner('trained-NN.pkl')
|
| 6 |
|
| 7 |
+
labels = neural_net.dls.vocab
|
| 8 |
|
| 9 |
def predict(img):
|
| 10 |
+
img = PILImage.create(img)
|
| 11 |
+
category, idx, probs = neural_net.predict(img)
|
| 12 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
|
|
|
| 13 |
|
| 14 |
title = 'Natural Language Classifier'
|
| 15 |
|
| 16 |
examples = ['farm.jpg']
|
| 17 |
|
| 18 |
iface = gr.Interface(fn=predict,
|
| 19 |
+
inputs=gr.Image(height=512, width=512),
|
| 20 |
+
outputs=gr.Label(num_top_classes=4),
|
| 21 |
title=title,
|
| 22 |
examples=examples)
|
| 23 |
iface.launch(share=True)
|