Umang Kaushik commited on
Commit
8826d5f
1 Parent(s): c2b3f16

renamed classifier.py to app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from fastai.vision.all import *
3
+ from PIL import Image
4
+ import pathlib
5
+ import urllib.request
6
+
7
+ temp = pathlib.PosixPath
8
+ plt = platform.system()
9
+ if plt == 'Windows': pathlib.PosixPath = pathlib.WindowsPath
10
+
11
+ # MODEL_URL = "https://drive.google.com/uc?export=download&id=1cH5nY1T5oykEcLyWtjA8Wv-Xn8vO20BS"
12
+ # urllib.request.urlretrieve(MODEL_URL, "model.pkl")
13
+
14
+ path = Path()
15
+ path.ls(file_exts='.pkl')
16
+
17
+ learn_inf = load_learner(path/'export.pkl', cpu=True)
18
+ # out_pl = st.image(load_image(image), width=250)
19
+
20
+
21
+ def load_image(img_file):
22
+ img = PILImage.create(img_file)
23
+ return img
24
+
25
+ def on_click_classify(image):
26
+ # load_image(image)
27
+ out_pl = st.image(load_image(image), width=250)
28
+ pred, pred_idx, probs = learn_inf.predict(load_image(image))
29
+ st.write('Prediction: ', str(pred)[10:], '; Probability: ', float(probs[pred_idx]))
30
+
31
+
32
+ st.title('Dog Classifier')
33
+ st.header('Choose your Dog!!')
34
+ image = st.file_uploader(label=' ', type=['png', 'jpg'], key='img', help='upload an img of dog')
35
+
36
+ # picture = st.camera_input(label='Click your dog!')
37
+
38
+
39
+ # btn_run.on_change(on_click_classify)
40
+ btn_run = st.button(label='Classify')
41
+ if btn_run:
42
+ on_click_classify(image)
43
+
44
+
45
+ st.markdown('#### Created by **Umang Kaushik**')
46
+ st.markdown('##### **[Github](https://github.com/Umang-10)**')
47
+