Skip to content

Commit

Permalink
(WIP) Improve gradio demo visualization (#24)
Browse files Browse the repository at this point in the history
This PR changes the following demo visualization and interation
- Replace click buttons by a slider to slice through 3d image
- Cache all images in the start to speed up image scrolling
- Add paragraph breaks to system messages display
- Move the files under `monai_vila_2d`

---------

Signed-off-by: Mingxin Zheng <[email protected]>
  • Loading branch information
mingxin-zheng authored Oct 21, 2024
1 parent 96e0766 commit 3894031
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 109 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
demo_monai_vila2d:
cd thirdparty/VILA; \
./environment_setup.sh
pip install -U nibabel python-dotenv deepspeed gradio monai[nibabel,pynrrd,skimage]
pip install -U python-dotenv deepspeed gradio monai[nibabel,pynrrd,skimage]
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ For details, see [here](./monai_vila2d/README.md).
```bash
git clone https://github.com/Project-MONAI/VLM --recursive
cd VLM
python -m venv .venv
python3.10 -m venv .venv
source .venv/bin/activate
make demo_monai_vila2d
```
Expand All @@ -70,9 +70,10 @@ For details, see [here](./monai_vila2d/README.md).

1. Start the Gradio demo:
```bash
python demo/gradio_monai_vila2d.py \
--modelpath /data/checkpoints/<checkpoint-name> \
--convmode <llama_3 or vicuna_1> \
cd monai_vila2d/demo
python gradio_monai_vila2d.py \
--modelpath /data/checkpoints/<8B-checkpoint-name> \
--convmode llama_3 \
--port 7860
```

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 3 additions & 5 deletions demo/experts/utils.py → monai_vila2d/demo/experts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import re
from io import BytesIO
from pathlib import Path
from typing import List
from urllib.parse import urlparse

import numpy as np
import requests
Expand Down Expand Up @@ -144,11 +142,11 @@ def get_filename_from_cd(url, cd):
return fname[0].strip('"').strip("'")


def get_slice_filenames(image_file, slice_index):
def get_slice_filenames(image_file: str, slice_index: int, ext: str = "jpg"):
"""Small helper function to get the slice filenames"""
base_name = os.path.basename(image_file)
image_filename = base_name.replace(".nii.gz", f"_slice{slice_index}.jpg")
seg_filename = base_name.replace(".nii.gz", f"_slice{slice_index}_seg.jpg")
image_filename = base_name.replace(".nii.gz", f"_slice{slice_index}_img.{ext}")
seg_filename = base_name.replace(".nii.gz", f"_slice{slice_index}_seg.{ext}")
return image_filename, seg_filename


Expand Down
199 changes: 100 additions & 99 deletions demo/gradio_monai_vila2d.py → monai_vila2d/demo/gradio_monai_vila2d.py

Large diffs are not rendered by default.

File renamed without changes.

0 comments on commit 3894031

Please sign in to comment.