rpa45 commited on
Commit
30c415e
1 Parent(s): 3a5a58b
Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -1,19 +1,33 @@
1
- from fastai.vision.all import *
 
2
  from pathlib import Path
3
  import gradio as gr
4
 
5
- learn = load_learner('aih_model.pkl')
 
 
6
 
 
 
 
 
7
  categories = ('AI Hand', 'Human Hand')
8
 
 
9
  def classify_image(img):
10
  pred,idx,probs = learn.predict(img)
11
  return dict(zip(categories, map(float,probs)))
12
 
 
13
  image = gr.Image(shape=(512,512))
14
  label = gr.Label()
15
  examples = [str(x) for x in Path('./samples').glob('*')]
16
 
17
- intf = gr.Interface(fn=classify_image, inputs=image, outputs=label,
18
- examples=examples)
 
 
 
 
 
19
  intf.launch()
 
1
+ import fastai.vision.all as faiv
2
+ import pathlib
3
  from pathlib import Path
4
  import gradio as gr
5
 
6
+ # make this work on Windows
7
+ temp = pathlib.PosixPath
8
+ pathlib.PosixPath = pathlib.WindowsPath
9
 
10
+ # load model
11
+ learn = faiv.load_learner('aih_model.pkl')
12
+
13
+ # define categories
14
  categories = ('AI Hand', 'Human Hand')
15
 
16
+ # set classifier function
17
  def classify_image(img):
18
  pred,idx,probs = learn.predict(img)
19
  return dict(zip(categories, map(float,probs)))
20
 
21
+ # set interface
22
  image = gr.Image(shape=(512,512))
23
  label = gr.Label()
24
  examples = [str(x) for x in Path('./samples').glob('*')]
25
 
26
+ intf = gr.Interface(
27
+ fn=classify_image,
28
+ inputs=image,
29
+ outputs=label,
30
+ examples=examples,
31
+ title='AI Hand Classifier')
32
+
33
  intf.launch()