Apple commited on
Commit
109b062
·
0 Parent(s):

first commit

Browse files
Procfile ADDED
@@ -0,0 +1 @@
 
 
1
+ web: sh setup.sh && streamlit run app.py
README.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Lineage Population Model
3
+ emoji: 🐨
4
+ colorFrom: purple
5
+ colorTo: green
6
+ sdk: streamlit
7
+ sdk_version: 1.17.0
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import functions
2
+ import streamlit as st
3
+ import numpy as np
4
+ import pandas as pd
5
+ from PIL import Image
6
+ from pathlib import Path
7
+ import joblib
8
+
9
+ import numpy as np
10
+ import cv2
11
+ import onnxruntime as ort
12
+ import imutils
13
+ # import matplotlib.pyplot as plt
14
+ import pandas as pd
15
+ import plotly.express as px
16
+
17
+
18
+ functions.lineage_population_model()
functions.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import pandas as pd
4
+ from PIL import Image
5
+ from pathlib import Path
6
+ import joblib
7
+
8
+ import numpy as np
9
+ import cv2
10
+ import onnxruntime as ort
11
+ import imutils
12
+ # import matplotlib.pyplot as plt
13
+ import pandas as pd
14
+ import plotly.express as px
15
+
16
+
17
+ def scale_model_outputs(scaler_path, data):
18
+ scaler= joblib.load(scaler_path)
19
+ scaled=scaler.inverse_transform(data)
20
+ return(scaled)
21
+
22
+
23
+ def onnx_predict_lineage_population(input_image):
24
+ ort_session = ort.InferenceSession('onnx_models/lineage_population_model.onnx')
25
+ img = Image.fromarray(np.uint8(input_image))
26
+ resized = img.resize((256, 256), Image.NEAREST)
27
+
28
+ transposed=np.transpose(resized, (2, 1, 0))
29
+ img_unsqueeze = expand_dims(transposed)
30
+
31
+ onnx_outputs = ort_session.run(None, {'input': img_unsqueeze.astype('float32')})
32
+ return(onnx_outputs[0])
33
+
34
+
35
+
36
+ def expand_dims(arr):
37
+ norm=(arr-np.min(arr))/(np.max(arr)-np.min(arr)) #normalize
38
+ ret = np.expand_dims(norm, axis=0)
39
+ return(ret)
40
+
41
+
42
+
43
+ def lineage_population_model():
44
+ selected_box2 = st.sidebar.selectbox(
45
+ 'Choose Example Input',
46
+ (['Example_1.png'])
47
+ )
48
+
49
+ st.title('Predict Cell Lineage Populations')
50
+ instructions = """
51
+ Predict the population of cells in C. elegans embryo using fluorescence microscopy data. \n
52
+ Either upload your own image or select from the sidebar to get a preconfigured image.
53
+ The image you select or upload will be fed through the Deep Neural Network in real-time
54
+ and the output will be displayed to the screen.
55
+ """
56
+ st.text(instructions)
57
+ file = st.file_uploader('Upload an image or choose an example')
58
+ example_image = Image.open('./images/lineage_population_examples/'+selected_box2).convert("RGB")
59
+
60
+ col1, col2= st.beta_columns(2)
61
+
62
+ if file:
63
+ input = Image.open(file).convert("RGB")
64
+ fig1 = px.imshow(input, binary_string=True, labels=dict(x="Input Image"))
65
+ fig1.update(layout_coloraxis_showscale=False)
66
+ fig1.update_layout(margin=dict(l=0, r=0, b=0, t=0))
67
+ col1.plotly_chart(fig1, use_container_width=True)
68
+ else:
69
+ input = example_image
70
+ fig1 = px.imshow(input, binary_string=True, labels=dict(x="Input Image"))
71
+ fig1.update(layout_coloraxis_showscale=False)
72
+ fig1.update_layout(margin=dict(l=0, r=0, b=0, t=0))
73
+ col1.plotly_chart(fig1, use_container_width=True)
74
+
75
+ pressed = st.button('Run')
76
+ if pressed:
77
+ st.empty()
78
+ output = onnx_predict_lineage_population(np.array(input))
79
+ scaled_output = scale_model_outputs(scaler_path="./scaler.gz", data=output)
80
+
81
+ for i in range(len(scaled_output[0])):
82
+ scaled_output[0][i]=int(round(scaled_output[0][i]))
83
+
84
+ df = pd.DataFrame({"Lineage":["A", "E", "M", "P", "C", "D", "Z"] , "Population": scaled_output[0]})
85
+ col2.table(df)
images/lineage_population_examples/Example_1.png ADDED
requirements.txt ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ altair==4.1.0
2
+ argon2-cffi==20.1.0
3
+ astor==0.8.1
4
+ async-generator==1.10
5
+ attrs==21.2.0
6
+ backcall==0.2.0
7
+ base58==2.1.0
8
+ bleach==3.3.1
9
+ blinker==1.4
10
+ cachetools==4.2.2
11
+ certifi==2021.5.30
12
+ cffi==1.14.6
13
+ charset-normalizer==2.0.3
14
+ click==7.1.2
15
+ debugpy==1.4.1
16
+ decorator==5.0.9
17
+ defusedxml==0.7.1
18
+ entrypoints==0.3
19
+ flatbuffers==2.0
20
+ gitdb==4.0.7
21
+ GitPython==3.1.18
22
+ idna==3.2
23
+ imutils==0.5.4
24
+ ipykernel==6.0.3
25
+ ipython==7.25.0
26
+ ipython-genutils==0.2.0
27
+ ipywidgets==7.6.3
28
+ jedi==0.18.0
29
+ Jinja2==3.0.1
30
+ joblib==1.0.1
31
+ jsonschema==3.2.0
32
+ jupyter-client==6.1.12
33
+ jupyter-core==4.7.1
34
+ jupyterlab-pygments==0.1.2
35
+ jupyterlab-widgets==1.0.0
36
+ MarkupSafe==2.0.1
37
+ matplotlib-inline==0.1.2
38
+ mistune==0.8.4
39
+ nbclient==0.5.3
40
+ nbconvert==6.1.0
41
+ nbformat==5.1.3
42
+ nest-asyncio==1.5.1
43
+ notebook==6.4.0
44
+ numpy==1.21.1
45
+ onnxruntime==1.8.1
46
+ opencv-python-headless==4.5.3.56
47
+ packaging==21.0
48
+ pandas==1.3.1
49
+ pandocfilters==1.4.3
50
+ parso==0.8.2
51
+ pexpect==4.8.0
52
+ pickleshare==0.7.5
53
+ Pillow==8.3.1
54
+ plotly==5.1.0
55
+ prometheus-client==0.11.0
56
+ prompt-toolkit==3.0.19
57
+ protobuf==3.17.3
58
+ ptyprocess==0.7.0
59
+ pyarrow==5.0.0
60
+ pycparser==2.20
61
+ pydeck==0.6.2
62
+ Pygments==2.9.0
63
+ pyparsing==2.4.7
64
+ pyrsistent==0.18.0
65
+ python-dateutil==2.8.2
66
+ pytz==2021.1
67
+ pyzmq==22.1.0
68
+ requests==2.26.0
69
+ scikit-learn==0.24.1
70
+ scipy==1.7.0
71
+ Send2Trash==1.7.1
72
+ six==1.16.0
73
+ smmap==4.0.0
74
+ streamlit==0.85.1
75
+ tenacity==8.0.1
76
+ terminado==0.10.1
77
+ testpath==0.5.0
78
+ threadpoolctl==2.2.0
79
+ toml==0.10.2
80
+ toolz==0.11.1
81
+ tornado==6.1
82
+ traitlets==5.0.5
83
+ tzlocal==2.1
84
+ urllib3==1.26.6
85
+ validators==0.18.2
86
+ watchdog==2.1.3
87
+ wcwidth==0.2.5
88
+ webencodings==0.5.1
89
+ widgetsnbextension==3.5.1
scaler.gz ADDED
Binary file (507 Bytes). View file
 
setup.sh ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ mkdir -p ~/.streamlit/
2
+ echo "\
3
+ [server]\n\
4
+ headless = true\n\
5
+ port = $PORT\n\
6
+ enableCORS = false\n\
7
+ \n\
8
+ " > ~/.streamlit/config.toml