andreped commited on
Commit
1978249
1 Parent(s): 9435739

Dockerized livermask and app

Browse files
Files changed (5) hide show
  1. README.md +0 -10
  2. demo/Dockerfile +31 -0
  3. demo/README.md +13 -0
  4. demo/app.py +13 -2
  5. demo/requirements.txt +2 -0
README.md CHANGED
@@ -1,13 +1,3 @@
1
- ---
2
- title: 'livermask: Automatic Liver Parenchyma and vessel segmentation in CT'
3
- colorFrom: indigo
4
- sdk: gradio
5
- sdk_version: 3.32.0
6
- emoji: 🚀
7
- pinned: false
8
- license: mit
9
- app_file: demo/app.py
10
- ---
11
  <div align="center">
12
  <h1 align="center">livermask</h1>
13
  <h3 align="center">Automatic liver parenchyma and vessel segmentation in CT using deep learning</h3>
 
 
 
 
 
 
 
 
 
 
 
1
  <div align="center">
2
  <h1 align="center">livermask</h1>
3
  <h3 align="center">Automatic liver parenchyma and vessel segmentation in CT using deep learning</h3>
demo/Dockerfile ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # you will also find guides on how best to write your Dockerfile
3
+
4
+ FROM python:3.7
5
+
6
+ WORKDIR /code
7
+
8
+ # install dependencies
9
+ COPY ./requirements.txt /code/requirements.txt
10
+ RUN python3 -m pip install --no-cache-dir --upgrade -r /code/requirements.txt
11
+
12
+ # resolve issue with tf==2.4 and gradio versioning issue
13
+ RUN python3 -m pip install --force-reinstall typing_extensions==4.0.0
14
+
15
+ # Set up a new user named "user" with user ID 1000
16
+ RUN useradd -m -u 1000 user
17
+
18
+ # Switch to the "user" user
19
+ USER user
20
+
21
+ # Set home to the user's home directory
22
+ ENV HOME=/home/user \
23
+ PATH=/home/user/.local/bin:$PATH
24
+
25
+ # Set the working directory to the user's home directory
26
+ WORKDIR $HOME/app
27
+
28
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
29
+ COPY --chown=user . $HOME/app
30
+
31
+ CMD ["python3", "app.py"]
demo/README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: 'livermask: Automatic Liver Parenchyma and vessel segmentation in CT'
3
+ colorFrom: indigo
4
+ colorTo: indigo
5
+ sdk: docker
6
+ app_port: 7860
7
+ emoji: 🚀
8
+ pinned: false
9
+ license: mit
10
+ app_file: demo/app.py
11
+ ---
12
+
13
+ # livermask Hugging Face demo - through docker SDK
demo/app.py CHANGED
@@ -27,7 +27,17 @@ def nifti_to_glb(path):
27
 
28
 
29
  def run_model(input_path):
30
- sp.check_call(["livermask", "--input", input_path, "--output", "prediction", "--verbose"])
 
 
 
 
 
 
 
 
 
 
31
 
32
 
33
  def load_mesh(mesh_file_name):
@@ -38,6 +48,7 @@ def load_mesh(mesh_file_name):
38
 
39
 
40
  if __name__ == "__main__":
 
41
  demo = gr.Interface(
42
  fn=load_mesh,
43
  inputs=gr.UploadButton(label="Click to Upload a File", file_types=[".nii", ".nii.nz"], file_count="single"),
@@ -45,4 +56,4 @@ if __name__ == "__main__":
45
  title="livermask: Automatic Liver Parenchyma segmentation in CT",
46
  description="Using pretrained deep learning model trained on the LiTS17 dataset",
47
  )
48
- demo.launch()
 
27
 
28
 
29
  def run_model(input_path):
30
+ from livermask.utils.run import run_analysis
31
+
32
+ run_analysis(cpu=False, extension='.nii', path=input_path, output='prediction', verbose=True, vessels=False)
33
+
34
+ #cmd_docker = ["python3", "-m", "livermask.livermask", "--input", input_path, "--output", "prediction", "--verbose"]
35
+ #sp.check_call(cmd_docker, shell=True) # @FIXME: shell=True here is not optimal -> starts a shell after calling script
36
+
37
+ #p = sp.Popen(cmd_docker, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
38
+ #stdout, stderr = p.communicate()
39
+ #print("stdout:", stdout)
40
+ #print("stderr:", stderr)
41
 
42
 
43
  def load_mesh(mesh_file_name):
 
48
 
49
 
50
  if __name__ == "__main__":
51
+ print("Launching demo...")
52
  demo = gr.Interface(
53
  fn=load_mesh,
54
  inputs=gr.UploadButton(label="Click to Upload a File", file_types=[".nii", ".nii.nz"], file_count="single"),
 
56
  title="livermask: Automatic Liver Parenchyma segmentation in CT",
57
  description="Using pretrained deep learning model trained on the LiTS17 dataset",
58
  )
59
+ demo.launch(server_name="0.0.0.0", server_port=7860)
demo/requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ livermask @ git+https://github.com/andreped/livermask.git
2
+ gradio==3.32.0