abidlabs HF Staff commited on
Commit
d621daa
·
1 Parent(s): 1453c80

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Make sure we've got the latest version of fastai:
2
+ from fastai.vision.all import *
3
+ import gradio as gr
4
+ import pathlib
5
+
6
+
7
+ def new_path(cls, *args, **kwargs):
8
+
9
+ cls = pathlib.WindowsPath
10
+ self = cls._from_parts(args)
11
+ if not self._flavour.is_supported:
12
+ raise NotImplementedError("cannot instantiate %r on your system"
13
+ % (cls.__name__,))
14
+ return self
15
+ Path.__new__=new_path
16
+
17
+
18
+ def is_cat(x): return x[0].isupper()
19
+
20
+ learn = load_learner('model.pkl')
21
+ categories = ('Dog', 'Cat')
22
+ def classify_image(img):
23
+ pred,idx,probs = learn.predict(img)
24
+ return dict(zip(categories, map(float, probs)))
25
+
26
+ image = gr.Image(shape=(192,192))
27
+ label = gr.Label()
28
+ examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']
29
+
30
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
31
+ intf.launch(inline=False)
32
+
33
+