kai1217 commited on
Commit
c6e705d
1 Parent(s): c03bc2e

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +40 -0
  2. requirements.txt +2 -0
  3. resnet34_stage-2.pkl +3 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastai.vision.all import *
2
+ from io import BytesIO
3
+ import requests
4
+ import streamlit as st
5
+
6
+ def predict(img):
7
+ st.image(img, caption="Your image", use_column_width=True)
8
+ pred, key, probs = learn_inf.predict(img)
9
+ # st.write(learn_inf.predict(img))
10
+
11
+ f"""
12
+ ### Rediction result: {pred}
13
+ ### Probability of {pred}: {probs[key].item()*100: .2f}%
14
+ """
15
+
16
+
17
+ path = "./"
18
+ learn_inf = load_learner(path + "resnet34_stage-2.pkl")
19
+
20
+ option = st.radio("", ["Upload Image", "Image URL"])
21
+
22
+ if option == "Upload Image":
23
+ uploaded_file = st.file_uploader("Please upload an image.")
24
+
25
+ if uploaded_file is not None:
26
+ img = PILImage.create(uploaded_file)
27
+ predict(img)
28
+
29
+ else:
30
+ url = st.text_input("Please input a url.")
31
+
32
+ if url != "":
33
+ try:
34
+ response = requests.get(url)
35
+ pil_img = PILImage.create(BytesIO(response.content))
36
+ predict(pil_img)
37
+
38
+ except:
39
+ st.text("Problem reading image from", url)
40
+
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastbook
2
+ altair<5
resnet34_stage-2.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:687403fee39568d93026ba38a00851dae2e3cd2f8ea7c4aae2039dbdd6dce6a5
3
+ size 87483274