Commit
•
ada7a1f
1
Parent(s):
3d7ca9c
added example streamlit papaya
Browse files- .gitattributes +1 -0
- .gitignore +2 -0
- .streamlit/config.toml +2 -0
- NOTES.md +14 -0
- app.py +59 -0
- requirements.txt +1 -0
- static/promis12-test-Case00-mask.nii.gz +3 -0
- static/promis12-test-Case00.nii.gz +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
*.nii.gz filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
__pycache__
|
2 |
+
static/tmp
|
.streamlit/config.toml
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
[server]
|
2 |
+
enableStaticServing = true
|
NOTES.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
```
|
3 |
+
python3.8 -m venv /mnt/scratch/venv/streamlit
|
4 |
+
source /mnt/scratch/venv/streamlit/bin/activate
|
5 |
+
|
6 |
+
pip install -r requirements.txt
|
7 |
+
```
|
8 |
+
|
9 |
+
'''
|
10 |
+
alternatives
|
11 |
+
https://github.com/amine0110/medical-visualization-with-streamlit/tree/main
|
12 |
+
https://neurosnippets.com/posts/diesitcom
|
13 |
+
|
14 |
+
'''
|
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import os
|
3 |
+
import streamlit as st
|
4 |
+
|
5 |
+
papaya_script = """
|
6 |
+
<style>
|
7 |
+
:root {
|
8 |
+
background-color: black;
|
9 |
+
}
|
10 |
+
</style>
|
11 |
+
<script src="https://cdn.jsdelivr.net/npm/papaya-viewer@1.0.1455/release/current/standard/papaya.min.js"></script>
|
12 |
+
<link href="https://cdn.jsdelivr.net/npm/papaya-viewer@1.0.1455/release/current/standard/papaya.min.css" rel="stylesheet">
|
13 |
+
<script type="text/javascript">
|
14 |
+
var params = [];
|
15 |
+
params["luts"] = [{"name": "Custom", "data":[[0, 0, 0, 0], [0.5, 0, 0, 0], [1, 1, 0, 0]]}];
|
16 |
+
params["images"] = ["{{IMAGE_FULLPATH}}","{{MASK_FULLPATH}}"];
|
17 |
+
params["{{MASK_BASENAME}}"] = {"min": 0, "max": 1, "lut": "Custom", "alpha":0.5};
|
18 |
+
</script>
|
19 |
+
<div class="papaya" data-params="params"></div>
|
20 |
+
"""
|
21 |
+
|
22 |
+
|
23 |
+
def handle_input(myimage,mymask,papaya_script):
|
24 |
+
mydict = {}
|
25 |
+
os.makedirs('static/tmp/',exist_ok=True)
|
26 |
+
image_path = 'static/tmp/image.nii.gz'
|
27 |
+
mask_path = 'static/tmp/mask.nii.gz'
|
28 |
+
for file_path,uploaded_file in [(image_path,myimage),(mask_path,mymask)]:
|
29 |
+
bytes_data = uploaded_file.getvalue()
|
30 |
+
with open(file_path,'wb') as f:
|
31 |
+
f.write(bytes_data)
|
32 |
+
|
33 |
+
image_path = './app/static/tmp/image.nii.gz'
|
34 |
+
mask_path = './app/static/tmp/mask.nii.gz'
|
35 |
+
papaya_script = papaya_script.replace("{{IMAGE_FULLPATH}}",image_path)
|
36 |
+
papaya_script = papaya_script.replace("{{MASK_FULLPATH}}",mask_path)
|
37 |
+
papaya_script = papaya_script.replace("{{MASK_BASENAME}}","mask.nii.gz")
|
38 |
+
|
39 |
+
st.components.v1.html(papaya_script,height=600,width=800)
|
40 |
+
|
41 |
+
def main():
|
42 |
+
|
43 |
+
st.subheader("papaya-image-viewer")
|
44 |
+
myimage = st.file_uploader(
|
45 |
+
"Upload your image nifti file", accept_multiple_files=False)
|
46 |
+
mymask = st.file_uploader(
|
47 |
+
"Upload your mask nifti file here and click on 'Render'", accept_multiple_files=False)
|
48 |
+
if st.button("Render"):
|
49 |
+
with st.spinner("Processing"):
|
50 |
+
handle_input(myimage,mymask,papaya_script)
|
51 |
+
|
52 |
+
|
53 |
+
if __name__ == '__main__':
|
54 |
+
main()
|
55 |
+
|
56 |
+
|
57 |
+
# papaya_script = papaya_script.replace("{{IMAGE_FULLPATH}}","./app/static/promis12-test-Case00.nii.gz")
|
58 |
+
# papaya_script = papaya_script.replace("{{MASK_FULLPATH}}","./app/static/promis12-test-Case00-mask.nii.gz")
|
59 |
+
# papaya_script = papaya_script.replace("{{MASK_BASENAME}}","promis12-test-Case00-mask.nii.gz")
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
streamlit>=1.19.0
|
static/promis12-test-Case00-mask.nii.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:14b159df22eb0b404a7a8851315a0269b37ad9bff1517577d681abb3514fc742
|
3 |
+
size 7774
|
static/promis12-test-Case00.nii.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:813dda4c7e60436017707cf7d371c311a1401750681e338fe29dac6bb087185c
|
3 |
+
size 2832200
|