alonshini commited on
Commit
6a6ff99
·
1 Parent(s): 517fdd6

new script

Browse files
Files changed (1) hide show
  1. app.py +31 -17
app.py CHANGED
@@ -1,23 +1,37 @@
1
-
2
- from fastai.vision.all import *
3
-
4
  import gradio as gr
5
 
6
- learn = load_learner('model.pkl')
7
-
8
- def on_click_classify(change):
9
- img = PILImage.create(btn_upload.data[-1])
10
- out_pl.clear_output()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  with out_pl: display(img.to_thumb(128,128))
12
  pred,pred_idx,probs = learn_inf.predict(img)
13
  lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'
 
14
 
15
- btn_run.on_click(on_click_classify)
16
-
17
- btn_upload = widgets.FileUpload()
18
-
19
- VBox([widgets.Label('Select your bear!'),
20
- btn_upload, btn_run, out_pl, lbl_pred])
21
-
22
- iface = gr.Interface(fn=on_click_classify, inputs=image, outputs=label)
23
- iface.launch()
 
1
+ # gradio
 
 
2
  import gradio as gr
3
 
4
+ # fast.ai
5
+ import fastbook
6
+ fastbook.setup_book()
7
+ from fastbook import *
8
+ from fastai.vision.widgets import *
9
+
10
+ # pathlib
11
+ import pathlib
12
+ temp = pathlib.PosixPath
13
+ pathlib.PosixPath = pathlib.WindowsPath
14
+ path = Path()
15
+ # load model
16
+ learn_inf = load_learner(path/'model.pkl')
17
+
18
+ # Output of the uploaded image
19
+ # Resizes the image to 128x128
20
+ out_pl = widgets.Output()
21
+ out_pl.clear_output()
22
+ with out_pl: display(img.to_thumb(128,128))
23
+ out_pl
24
+
25
+ # Label Function that will disply our prediction data to the user
26
+ lbl_pred = widgets.Label()
27
+
28
+ # Logic function that will run the image classifier on the classify button click
29
+ def on_click_classify(input_img):
30
+ img = PILImage.create(input_img)
31
  with out_pl: display(img.to_thumb(128,128))
32
  pred,pred_idx,probs = learn_inf.predict(img)
33
  lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'
34
+ return lbl_pred.value
35
 
36
+ demo = gr.Interface(on_click_classify, gr.Image(shape=(512, 512)), "text")
37
+ demo.launch()