Elam commited on
Commit
e90d11e
·
1 Parent(s): 9a4f29c

New interface with images

Browse files
Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -1,7 +1,20 @@
 
 
 
 
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
+
2
+ __all__ = ['learn','classify_image','categories','image','label','examples','intf']
3
+
4
+ from fastai.vision.all import *
5
  import gradio as gr
6
 
7
+ learn = load_learner('model.pkl')
8
+
9
+ categories = ('Car', 'Bike')
10
+ def classify_image(img):
11
+ is_car,_,probs = learn.predict(PILImage.create(img))
12
+ return dict(zip(categories, map(float,probs))) #gradio only supports floats and it doesn't handle PyTorch tensors
13
+
14
+ image = gr.inputs.Image(shape=(192,192))
15
+ label = gr.outputs.Label()
16
+ examples = ['volkswagen.jpg','motorbike.jpg']
17
+
18
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
19
+ intf.launch(inline=False)
20