Skip to content

Commit

Permalink
Fix adhoc package
Browse files Browse the repository at this point in the history
  • Loading branch information
uw0s committed Apr 15, 2024
1 parent 98cfa0b commit c3dfb7f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
6 changes: 6 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ cd python/ && make clean check all && cd ..
# Staging
cd python/ && make STAGING=1

# Installation
pip install https://api.github.com/repos/valab-certh/meddisc/tarball/main#subdirectory=python

# Usage
STAGING=1 meddisc

20 changes: 12 additions & 8 deletions python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ def dcm2dictmetadata(ds: pydicom.dataset.Dataset) -> dict[str, dict[str, str]]:


app = FastAPI()
templates = Jinja2Templates(directory="templates")
app.mount(path="/static", app=StaticFiles(directory="static"), name="static")
templates_dir = Path(__file__).parent / "templates"
static_dir = Path(__file__).parent / "static"
templates = Jinja2Templates(directory=templates_dir)
app.mount(path="/static", app=StaticFiles(directory=static_dir), name="static")

client = TestClient(app)

Expand Down Expand Up @@ -169,10 +171,10 @@ def test_submit_button() -> None:
"retain_descriptors": False,
"patient_pseudo_id_prefix": "OrgX - ",
}
response = client.post(app_url() + "/submit_button", json=test_options)
if response.status_code != status.HTTP_200_OK:
raise AssertionError
json_response = response.json()
response = client.post(self.app_url() + "/submit_button", json=test_options)
if response.status_code != status.HTTP_200_OK:
raise AssertionError
json_response = response.json()
desired_hash = "cd6e8eae4006ca7b150c3217667de6b6f7b435f93961d182e72b4da7773884a9"
hasher = hashlib.sha256()
block_size = 65536
Expand Down Expand Up @@ -317,7 +319,8 @@ def load_model() -> MedsamLite:
mask_decoder=medsam_lite_mask_decoder,
prompt_encoder=medsam_lite_prompt_encoder,
)
medsam_lite_checkpoint = torch.load("./prm/lite_medsam.pth", map_location="cpu")
medsam_dir = Path(__file__).parent / "templates" / "lite_medsam.pth"
medsam_lite_checkpoint = torch.load(medsam_dir, map_location="cpu")
medsam_model.load_state_dict(medsam_lite_checkpoint)
medsam_model.to("cpu")

Expand Down Expand Up @@ -1479,6 +1482,7 @@ def ndarray_size(arr: NDArray[Any]) -> int:

def meddisc() -> None:
tmp_directories = [
Path("tmp"),
Path("tmp/session-data/raw"),
Path("tmp/session-data/clean"),
Path("tmp/session-data/embed"),
Expand Down Expand Up @@ -1516,7 +1520,7 @@ def meddisc() -> None:
run(
app,
host="0.0.0.0", # noqa: S104
port=443,
port=8000,
ssl_certfile="tmp/fullchain.pem",
ssl_keyfile="tmp/privkey.pem",
)
Expand Down
15 changes: 13 additions & 2 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ dependencies = [
"python-multipart==0.0.9",
"segment-anything@https://api.github.com/repos/facebookresearch/segment-anything/tarball/main",
"tensorflow==2.16.1",
"torch@https://download.pytorch.org/whl/cpu/torch-2.2.1%2Bcpu-cp312-cp312-linux_x86_64.whl",
"torchvision@https://download.pytorch.org/whl/cpu/torchvision-0.17.1%2Bcpu-cp312-cp312-linux_x86_64.whl",
"torch==2.2.2",
"torchvision==0.17.2",
"uvicorn==0.27.1"
]
name = "meddisc"
Expand All @@ -35,3 +35,14 @@ meddisc = "main:main_cli"

[tool.setuptools]
py-modules = ["main"]

[tool.setuptools.package-data]
'*' = [
"*.css",
"*.html",
"*.js",
"*.pth"
]

[tool.setuptools.packages.find]
where = ["."]

0 comments on commit c3dfb7f

Please sign in to comment.