Tuba18Huang commited on
Commit
b458abb
1 Parent(s): 55271d5

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +49 -0
  2. requirements.txt +2 -0
  3. resnet34_stage-2.pkl +3 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastai.vision.all import *
2
+ from io import BytesIO
3
+ import requests
4
+ import streamlit as st
5
+
6
+ """
7
+ # U-Net
8
+ This is a segmentation model for images of Brain MRI.
9
+ """
10
+
11
+ def predict(img):
12
+ st.image(img, caption="Your image", use_column_width=True)
13
+ pred_mask = learn_inf.predict(img)[0]
14
+ pred_mask = pred_mask.numpy()*255
15
+ # pred, key, probs = learn_inf.predict(img)
16
+ # st.write(learn_inf.predict(img))
17
+
18
+ f"""
19
+ ### Rediction result:
20
+ """
21
+ st.image(pred_mask, caption="Prediction Mask", use_column_width=True)
22
+
23
+ def label_func(x):
24
+ return x.parents[0] / (x.stem + '_mask' + x.suffix)
25
+
26
+ path = "./"
27
+ learn_inf = load_learner(path + "model-34")
28
+
29
+ option = st.radio("", ["Upload Image", "Image URL"])
30
+
31
+ if option == "Upload Image":
32
+ uploaded_file = st.file_uploader("Please upload an image.")
33
+
34
+ if uploaded_file is not None:
35
+ img = PILImage.create(uploaded_file)
36
+ predict(img)
37
+
38
+ else:
39
+ url = st.text_input("Please input a url.")
40
+
41
+ if url != "":
42
+ try:
43
+ response = requests.get(url)
44
+ pil_img = PILImage.create(BytesIO(response.content))
45
+ predict(pil_img)
46
+
47
+ except:
48
+ st.text("Problem reading image from", url)
49
+
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:df8dd2618d6acdafcf4492ede89ca5ab6d55f93a39e6e2cbfa90417ddba40ff4
3
+ size 37242314