utility-ai commited on
Commit
8d6be65
1 Parent(s): 1a67e68

built a simple streamlit app and updated dependencies

Browse files
Files changed (3) hide show
  1. Makefile +12 -0
  2. app.py +50 -0
  3. requirements.txt +3 -0
Makefile ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ install:
2
+ pip install --upgrade pip && \
3
+ pip install -r requirements.txt
4
+
5
+ #format:
6
+ # python -m black *.py
7
+
8
+ # lint:
9
+ # pylint --disable=R,C *.py
10
+
11
+ #test:
12
+ # python -m pytest -vv -----------------
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from fastai.vision.all import *
3
+
4
+ def is_cat(x):
5
+ return x[0].isupper()
6
+
7
+ model = load_learner('model.pkl')
8
+
9
+ categories = ('Dog', 'Cat')
10
+
11
+ def clasify_image(img):
12
+ img = PILImage.create(img)
13
+ pred,idx,probs = model.predict(img)
14
+ return dict(zip(categories, map(float,probs)))
15
+
16
+
17
+ def main():
18
+
19
+ st.title("Dog or Cat predictor")
20
+
21
+ #The input is an image
22
+ image = st.file_uploader("Upload an image", "jpg")
23
+ # Display the image once it has been uploaded
24
+ if image:
25
+ disp = Image.open(image)
26
+ st.image(disp, width=150)
27
+ # Make the prediction
28
+ if st.button("Predict", use_container_width=True):
29
+ result = clasify_image(image)
30
+ for key, value in result.items():
31
+ st.progress(value, f"Probabiity that its a {key} is {value:.15f}%")
32
+
33
+ #There should be examples you can pick from to put into the input interface
34
+ images = [
35
+ Image.open('photos/cat/001.jpg'),
36
+ Image.open('photos/dog/006.jpg'),
37
+ Image.open('photos/dog/007.jpg'),
38
+ Image.open('photos/cat/003.jpg')
39
+
40
+ ]
41
+
42
+ col1, col2, col3, col4 = st.columns(4)
43
+
44
+ col1.image(images[0], width=150)
45
+ col2.image(images[1], width=150)
46
+ col3.image(images[2], width=150)
47
+ col4.image(images[3], width=150)
48
+
49
+ if __name__ == "__main__":
50
+ main()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit==1.28.0
2
+ fastai==2.7.13
3
+ git-lfs==1.6