adr commited on
Commit
5b609f4
1 Parent(s): e567656

deploy to huggingface spaces

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -1,7 +1,21 @@
1
- import gradio as gr
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
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)