mg297bgyy commited on
Commit
76c91ec
·
1 Parent(s): 44bf6d0
Files changed (1) hide show
  1. app.py +45 -3
app.py CHANGED
@@ -1,4 +1,46 @@
1
- import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
1
+ # Hide - Connects voila to current notebook
2
+ #!jupyter serverextension enable --sys-prefix voila
3
+
4
+ # Voila runs jpnb but hides the code cells and only displays the output (including the ipywidgets) as well as the markdown cells.
5
+
6
+ #import fastbook
7
+ #fastbook.setup_book()
8
+ from fastbook import *
9
+ from fastai.vision.widgets import *
10
+
11
+ # Load the model
12
+ path = Path()
13
+ path.ls(file_exts='.pkl')
14
+
15
+ learn_inf = load_learner(path/'export.pkl')
16
+
17
+ # Create a button widget
18
+ btn_upload = widgets.FileUpload()
19
+ btn_upload
20
+
21
+ # Create a clear_output widget
22
+ out_pl = widgets.Output()
23
+ out_pl.clear_output()
24
+
25
+ # Create a label widget
26
+ lbl_pred = widgets.Label()
27
+
28
+ # Create a run button widget
29
+ btn_run = widgets.Button(description='Classify')
30
+ btn_run
31
+
32
+ # Function to classify the image
33
+ def on_click_classify(change):
34
+ img = PILImage.create(btn_upload.data[-1])
35
+ out_pl.clear_output()
36
+ with out_pl: display(img.to_thumb(128,128))
37
+ pred,pred_idx,probs = learn_inf.predict(img)
38
+ lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'
39
+
40
+ btn_run.on_click(on_click_classify)
41
+
42
+ # Create a Vertical Box (VBox) to hold the widgets
43
+ btn_upload = widgets.FileUpload()
44
+ VBox([widgets.Label('Select your forest!'),
45
+ btn_upload, btn_run, out_pl, lbl_pred])
46