Ginger1704 commited on
Commit
bb33555
·
1 Parent(s): 873904b

forgot the app

Browse files
Files changed (1) hide show
  1. app.py +29 -22
app.py CHANGED
@@ -4,29 +4,36 @@ from fastai.vision.widgets import *
4
  from IPython.display import display
5
 
6
 
7
- learn_inf = load_learner('export.pkl')
8
- lbl_pred = widgets.Label()
9
- # lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'
10
- out_pl = widgets.Output()
11
- btn_upload = widgets.FileUpload()
12
 
13
- # VBox([widgets.Label('Select your bear!'),
14
- # btn_upload, btn_run, out_pl, lbl_pred])
15
- # def greet(name):
16
- # return "Hello " + name + "!!"
17
 
18
- def on_click_classify(picture):
19
- # btn_upload = widgets.FileUpload()
20
- # lbl_pred = widgets.Label()
21
- # lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'
22
- out_pl = widgets.Output()
23
- img = PILImage.create(picture)
24
- out_pl.clear_output()
25
- with out_pl: display(img.to_thumb(128,128))
26
- pred,pred_idx,probs = learn_inf.predict(img)
27
- print('pred,pred_idx,probs', pred,pred_idx,probs)
28
- lbl_pred.value = f'Prediction: {pred};\n Probability: {probs[pred_idx]:.04f}'
29
- return lbl_pred.value
30
 
31
- iface = gr.Interface(fn=on_click_classify, inputs="image", outputs='text')
 
 
 
 
 
 
 
 
32
  iface.launch()
 
4
  from IPython.display import display
5
 
6
 
7
+ # learn_inf = load_learner('export.pkl')
8
+ # lbl_pred = widgets.Label()
9
+ # # lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'
10
+ # out_pl = widgets.Output()
11
+ # btn_upload = widgets.FileUpload()
12
 
13
+ # # VBox([widgets.Label('Select your bear!'),
14
+ # # btn_upload, btn_run, out_pl, lbl_pred])
15
+ # # def greet(name):
16
+ # # return "Hello " + name + "!!"
17
 
18
+ # def on_click_classify(picture):
19
+ # out_pl = widgets.Output()
20
+ # img = PILImage.create(picture)
21
+ # out_pl.clear_output()
22
+ # with out_pl: display(img.to_thumb(128,128))
23
+ # pred,pred_idx,probs = learn_inf.predict(img)
24
+ # print('pred,pred_idx,probs', pred,pred_idx,probs)
25
+ # lbl_pred.value = f'Prediction: {pred};\n Probability: {probs[pred_idx]:.04f}'
26
+ # return lbl_pred.value
27
+ learn = load_learner('export.pkl')
28
+ categories = ('Hot Dog','No Hot Dog')
 
29
 
30
+ def on_click_classify(img):
31
+ pred,pred_idx,probs = learn.predict(img)
32
+ return dict(zip(categories, map(float,probs)))
33
+
34
+ image = gr.Image()
35
+ label = gr.Label()
36
+ examples = ['hot_dog.jpg', 'no_hot_dog.jpg', 'jian_yang.jpg']
37
+
38
+ iface = gr.Interface(fn=on_click_classify, inputs=image, outputs=label, examples=examples)
39
  iface.launch()