marix1120 commited on
Commit
eaefa9f
1 Parent(s): d37d5f7

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -8
app.py CHANGED
@@ -4,20 +4,31 @@
4
  Automatically generated by Colaboratory.
5
 
6
  Original file is located at
7
- https://colab.research.google.com/drive/1tB5UaeH3SiFcvNJelcs0apxr4mFEHmtA
8
  """
9
 
 
10
 
11
-
12
  from fastai.vision.all import *
13
  import gradio as gr
14
 
 
 
 
15
  learn = load_learner('model.pkl')
16
 
17
- labels = learn.dls.vocab
18
- def predict(img):
19
- img = PILImage.create(img)
20
- pred,pred_idx,probs = learn.predict(img)
21
- return {labels[i]: float(probs[i]) for i in range(len(labels))}
 
 
 
 
 
 
22
 
23
- gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3)).launch(share=True)
 
 
4
  Automatically generated by Colaboratory.
5
 
6
  Original file is located at
7
+ https://colab.research.google.com/drive/1sm_pZkdxzPTsmU4kQ9Sdiq5VlFEqRWDQ
8
  """
9
 
10
+ __all__ = ['is_cat', 'learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']
11
 
12
+ # Cell
13
  from fastai.vision.all import *
14
  import gradio as gr
15
 
16
+ def is_cat(x): return x[0].isupper()
17
+
18
+ # Cell
19
  learn = load_learner('model.pkl')
20
 
21
+ # Cell
22
+ categories = ('Dog', 'Cat')
23
+
24
+ def classify_image(img):
25
+ pred,idx,probs = learn.predict(img)
26
+ return dict(zip(categories, map(float,probs)))
27
+
28
+ # Cell
29
+ image = gr.inputs.Image(shape=(192, 192))
30
+ label = gr.outputs.Label()
31
+ examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']
32
 
33
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
34
+ intf.launch(inline=False)