Skip to content

Commit

Permalink
Refactored + updated gradio app README
Browse files Browse the repository at this point in the history
  • Loading branch information
andreped committed May 24, 2023
1 parent 4eaed2f commit e7f6bf3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ colorFrom: indigo
colorTo: indigo
sdk: docker
app_port: 7860
emoji: 🚀
emoji: 🔎
pinned: false
license: mit
app_file: demo/app.py
Expand Down
30 changes: 30 additions & 0 deletions demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,33 @@ app_file: demo/app.py
---

# livermask Hugging Face demo - through docker SDK

Deploying simple models in a gradio-based web interface in Hugging Face spaces is easy.
For any other custom pipeline, with various dependencies and challenging behaviour, it
might be necessary to use Docker containers instead.

Deployment through a custom Docker image over the existing Gradio image was
necessary in this case due to `tensorflow` and `gradio` having colliding
versions. As `livermask` depends on `tf`, the only way to get around it was
fixing the broken dependency, which was handled by reinstalling and changing
the `typing_extensions` with a version that `gradio` required for the widgets
we used. Luckily, this did not break anything in `tf`, even though `tf` has a
very strict versioning criteria for this dependency.

Anyways, everything works as intended now. For every new push to the main branch,
continuous deployment to the Hugging Face `livermask` space is performed through
GitHub Actions.

When the space is updated, the Docker image is rebuilt/updated (caching if possible).
Then when finished, the end users can test the app as they please.

Right now, the functionality of the app is extremely limited, only offering a widget
for uploading a NIfTI file (`.nii` or `.nii.gz`) and visualizing the produced surface
of the predicted liver parenchyma 3D volume when finished processing.

Analysis process can be monitored from the `Logs` tab next to the `Running` button
in the Hugging Face `livermask` space.

Natural future TODOs include:
- [ ] Add gallery widget to enable scrolling through 2D slices
- [ ] Render segmentation for individual 2D slices as overlays
8 changes: 0 additions & 8 deletions demo/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ def run_model(input_path):
from livermask.utils.run import run_analysis

run_analysis(cpu=True, extension='.nii', path=input_path, output='prediction', verbose=True, vessels=False, name="/home/user/app/model.h5", mp_enabled=False)

#cmd_docker = ["python3", "-m", "livermask.livermask", "--input", input_path, "--output", "prediction", "--verbose"]
#sp.check_call(cmd_docker, shell=True) # @FIXME: shell=True here is not optimal -> starts a shell after calling script

#p = sp.Popen(cmd_docker, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#stdout, stderr = p.communicate()
#print("stdout:", stdout)
#print("stderr:", stderr)


def load_mesh(mesh_file_name):
Expand Down

0 comments on commit e7f6bf3

Please sign in to comment.