andreped commited on
Commit
74ebf3e
·
1 Parent(s): be8cccc

Fixed demo + added demo README + new Dockerfile

Browse files
Files changed (5) hide show
  1. Dockerfile +6 -21
  2. demo/README.md +31 -0
  3. demo/requirements.txt +1 -1
  4. demo/src/compute.py +1 -1
  5. demo/src/gui.py +2 -2
Dockerfile CHANGED
@@ -1,33 +1,18 @@
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
- FROM tensorflow/tensorflow:2.4.2-gpu
4
-
5
- # fix for broken keys in Ubuntu-18.04
6
- RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub
7
-
8
- # install Python 3.7
9
- RUN apt-get update && apt-get install -y --no-install-recommends software-properties-common \
10
- libsm6 libxext6 libxrender-dev curl \
11
- && rm -rf /var/lib/apt/lists/*
12
-
13
- RUN echo "**** Installing Python ****" && \
14
- add-apt-repository ppa:deadsnakes/ppa && \
15
- apt-get install -y build-essential python3.7 python3.7-dev python3-pip && \
16
- curl -O https://bootstrap.pypa.io/get-pip.py && \
17
- python3.7 get-pip.py && \
18
- rm -rf /var/lib/apt/lists/*
19
 
20
  WORKDIR /code
21
 
22
  RUN apt-get update -y
 
23
  RUN apt install git --fix-missing -y
 
24
 
25
  # install dependencies
26
  COPY ./demo/requirements.txt /code/demo/requirements.txt
27
- RUN python3.7 -m pip install --no-cache-dir --upgrade -r /code/demo/requirements.txt
28
-
29
- # Install wget
30
- RUN apt install wget -y
31
 
32
  # Set up a new user named "user" with user ID 1000
33
  RUN useradd -m -u 1000 user
@@ -51,4 +36,4 @@ COPY --chown=user . $HOME/app
51
  # Download test sample
52
  RUN wget https://github.com/VemundFredriksen/LungTumorMask/releases/download/0.0.1/lung_001.nii.gz
53
 
54
- CMD ["python3.7", "demo/app.py"]
 
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
+ #FROM pytorch/pytorch:1.10.0-cuda11.3-cudnn8-runtime
4
+ FROM python:3.8.10-slim
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  WORKDIR /code
7
 
8
  RUN apt-get update -y
9
+ #RUN apt-get install -y python3 python3-pip
10
  RUN apt install git --fix-missing -y
11
+ RUN apt install wget -y
12
 
13
  # install dependencies
14
  COPY ./demo/requirements.txt /code/demo/requirements.txt
15
+ RUN python -m pip install --no-cache-dir --upgrade -r /code/demo/requirements.txt
 
 
 
16
 
17
  # Set up a new user named "user" with user ID 1000
18
  RUN useradd -m -u 1000 user
 
36
  # Download test sample
37
  RUN wget https://github.com/VemundFredriksen/LungTumorMask/releases/download/0.0.1/lung_001.nii.gz
38
 
39
+ CMD ["python", "demo/app.py"]
demo/README.md ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Hugging Face demo - through docker SDK
2
+
3
+ Deploying simple models in a gradio-based web interface in Hugging Face spaces is easy.
4
+ For any other custom pipeline, with various dependencies and challenging behaviour, it
5
+ might be necessary to use Docker containers instead.
6
+
7
+ For every new push to the main branch, continuous deployment to the Hugging Face
8
+ `LungTumorMask` space is performed through a GitHub Actions workflow.
9
+
10
+ When the space is updated, the Docker image is rebuilt/updated (caching if possible).
11
+ Then when finished, the end users can test the app as they please.
12
+
13
+ Right now, the functionality of the app is extremely limited, only offering a widget
14
+ for uploading a NIfTI file (`.nii` or `.nii.gz`) and visualizing the produced surface
15
+ of the predicted lung tumor volume when finished processing.
16
+
17
+ Analysis process can be monitored from the `Logs` tab next to the `Running` button
18
+ in the Hugging Face `LungTumorMask` space.
19
+
20
+ It is also possible to build the app as a docker image and deploy it. To do so follow these steps:
21
+
22
+ ```
23
+ docker build -t lungtumormask:latest ..
24
+ docker run -it -p 7860:7860 lungtumormask:latest
25
+ ```
26
+
27
+ Then open `http://localhost:7860` in your favourite internet browser to view the demo.
28
+
29
+ TODOs:
30
+ - [X] Add gallery widget to enable scrolling through 2D slices
31
+ - [X] Render segmentation for individual 2D slices as overlays
demo/requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
  lungtumormask @ git+https://github.com/vemundfredriksen/LungTumorMask.git
2
- gradio==3.32.0
 
1
  lungtumormask @ git+https://github.com/vemundfredriksen/LungTumorMask.git
2
+ gradio==3.44.4
demo/src/compute.py CHANGED
@@ -1,3 +1,3 @@
1
  def run_model(input_path):
2
  from lungtumormask import mask
3
- mask.mask(input_path, "./output.nii.gz", lung_filter=True, threshold=0.5, radius=1, batch_size=1)
 
1
  def run_model(input_path):
2
  from lungtumormask import mask
3
+ mask.mask(input_path, "./prediction.nii.gz", lung_filter=True, threshold=0.5, radius=1, batch_size=1)
demo/src/gui.py CHANGED
@@ -11,7 +11,7 @@ class WebUI:
11
  self.pred_images = []
12
 
13
  # @TODO: This should be dynamically set based on chosen volume size
14
- self.nb_slider_items = 160
15
 
16
  self.class_name = class_name
17
  self.cwd = cwd
@@ -100,4 +100,4 @@ class WebUI:
100
 
101
  # sharing app publicly -> share=True: https://gradio.app/sharing-your-app/
102
  # inference times > 60 seconds -> need queue(): https://github.com/tloen/alpaca-lora/issues/60#issuecomment-1510006062
103
- demo.queue().launch(server_name="0.0.0.0", server_port=7860, share=True)
 
11
  self.pred_images = []
12
 
13
  # @TODO: This should be dynamically set based on chosen volume size
14
+ self.nb_slider_items = 300
15
 
16
  self.class_name = class_name
17
  self.cwd = cwd
 
100
 
101
  # sharing app publicly -> share=True: https://gradio.app/sharing-your-app/
102
  # inference times > 60 seconds -> need queue(): https://github.com/tloen/alpaca-lora/issues/60#issuecomment-1510006062
103
+ demo.queue().launch(server_name="0.0.0.0", server_port=7860, share=False)