Spaces:
Runtime error
Runtime error
adr
commited on
Commit
•
5b609f4
1
Parent(s):
e567656
deploy to huggingface spaces
Browse files
app.py
CHANGED
@@ -1,7 +1,21 @@
|
|
1 |
-
import
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
iface.launch()
|
|
|
1 |
+
# import all the fastai stuff.
|
2 |
+
from fastai.vision.all import *
|
3 |
+
|
4 |
+
# load our model.
|
5 |
+
learn = load_learner('export.pkl')
|
6 |
|
7 |
+
# define a prediction function, not sure what this means.
|
8 |
+
labels = learn.dls.vocab
|
9 |
+
def predict(img):
|
10 |
+
img = PILImage.create(img)
|
11 |
+
# this returns
|
12 |
+
# predicted category
|
13 |
+
# index
|
14 |
+
# probabilities of each category
|
15 |
+
pred,pred_idx,probs = learn.predict(img)
|
16 |
+
# we return a weird dictionary or JSON?
|
17 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
18 |
+
|
19 |
+
import gradio as gr
|
20 |
|
21 |
+
gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3)).launch(share=True)
|
|