@@ -468,9 +468,13 @@ async def get_files(files: list[UploadFile]) -> UploadFilesResponse:
468
468
if len (dcm .pixel_array .shape ) == 2 : # noqa: PLR2004
469
469
proper_dicom_paths .append (fp )
470
470
total_uploaded_file_bytes += len (contents )
471
+ total_uploaded_file_megabytes = "%.1f" % (
472
+ total_uploaded_file_bytes / (10 ** 3 ) ** 2
473
+ )
474
+ else :
475
+ Path .unlink (fp )
471
476
except InvalidDicomError :
472
- pass
473
- total_uploaded_file_megabytes = "%.1f" % (total_uploaded_file_bytes / (10 ** 3 ) ** 2 )
477
+ Path .unlink (fp )
474
478
return UploadFilesResponse (
475
479
n_uploaded_files = len (proper_dicom_paths ),
476
480
total_size = total_uploaded_file_megabytes ,
@@ -686,7 +690,6 @@ def prepare_medsam() -> None:
686
690
medsam_model = load_model ()
687
691
raw_fp = Path ("./tmp/session-data/raw" )
688
692
dcm_fps = sorted (raw_fp .glob ("*" ))
689
- time .time ()
690
693
temp_dir = Path ("./tmp/session-data/embed" )
691
694
hs , ws = [], []
692
695
for idx , dcm_fp in enumerate (dcm_fps ):
@@ -699,7 +702,6 @@ def prepare_medsam() -> None:
699
702
hs .append (h )
700
703
ws .append (w )
701
704
img_256 = cv2 .resize (src = img_3c , dsize = (256 , 256 )).astype (np .float32 )
702
- newh , neww = img_256 .shape [:2 ]
703
705
img_256 = (img_256 - img_256 .min ()) / np .clip (
704
706
img_256 .max () - img_256 .min (),
705
707
a_min = 1e-8 ,
@@ -1047,13 +1049,7 @@ def get_dicom_paths(
1047
1049
self , # noqa: ANN101
1048
1050
data_dp : str ,
1049
1051
) -> list [Path ]:
1050
- dicom_paths = list (Path (data_dp ).rglob ("*" ))
1051
- proper_dicom_paths = []
1052
- for dicom_path in dicom_paths :
1053
- ds = pydicom .dcmread (dicom_path , stop_before_pixels = True )
1054
- if ds :
1055
- proper_dicom_paths .append (dicom_path )
1056
- return proper_dicom_paths
1052
+ return list (Path (data_dp ).rglob ("*" ))
1057
1053
1058
1054
def parse_file (
1059
1055
self , # noqa: ANN101
0 commit comments