NelsonGc commited on
Commit
c211d7c
·
1 Parent(s): 88a208b

add in missing app.py details

Browse files
Files changed (1) hide show
  1. app.py +39 -2
app.py CHANGED
@@ -1,4 +1,41 @@
1
  import streamlit as st
 
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from fastai.vision.widgets import *
3
+ from fastai.vision.all import *
4
 
5
+ from pathlib import Path
6
+
7
+ import streamlit as st
8
+
9
+ def is_cat(x): return x[0].isupper()
10
+
11
+ class Predict:
12
+ def __init__(self, filename):
13
+ self.learn_inference = load_learner(Path()/filename)
14
+ self.img = self.get_image_from_upload()
15
+ if self.img is not None:
16
+ self.display_output()
17
+ self.get_prediction()
18
+
19
+ @staticmethod
20
+ def get_image_from_upload():
21
+ uploaded_file = st.file_uploader("Upload Files",type=['png','jpeg', 'jpg'])
22
+ if uploaded_file is not None:
23
+ return PILImage.create((uploaded_file))
24
+ return None
25
+
26
+ def display_output(self):
27
+ st.image(self.img.to_thumb(500,500), caption='Uploaded Image')
28
+
29
+ def get_prediction(self):
30
+
31
+ if st.button('Classify'):
32
+ pred, pred_idx, probs = self.learn_inference.predict(self.img)
33
+ st.write(f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}')
34
+ else:
35
+ st.write(f'Click the button to classify')
36
+
37
+ if __name__=='__main__':
38
+
39
+ file_name='model.pkl'
40
+
41
+ predictor = Predict(file_name)