Harshith Reddy
commited on
Commit
·
6849f7a
1
Parent(s):
935dfed
Increase file size limits: upload 1 GB, processing 2 GB
Browse files- README.md +2 -2
- app.py +5 -5
- processing.py +2 -2
README.md
CHANGED
|
@@ -458,7 +458,7 @@ Creates Gradio interface for web UI.
|
|
| 458 |
- Shape validation (minimum 3D, maximum 2000 per dimension)
|
| 459 |
- Voxel spacing validation
|
| 460 |
- NaN/Inf value detection
|
| 461 |
-
- File size limits (upload: max
|
| 462 |
- File size warnings (< 100 KB may indicate compression)
|
| 463 |
- Dimension warnings (< 20 slices may indicate incomplete volume)
|
| 464 |
- Metadata validation (voxel spacing, affine matrix)
|
|
@@ -696,7 +696,7 @@ Upload a NIfTI file for liver segmentation.
|
|
| 696 |
}
|
| 697 |
```
|
| 698 |
|
| 699 |
-
**Note:** For mask files >
|
| 700 |
|
| 701 |
#### GET /api/health
|
| 702 |
Check API health and model status.
|
|
|
|
| 458 |
- Shape validation (minimum 3D, maximum 2000 per dimension)
|
| 459 |
- Voxel spacing validation
|
| 460 |
- NaN/Inf value detection
|
| 461 |
+
- File size limits (upload: max 1 GB, processing: max 2 GB)
|
| 462 |
- File size warnings (< 100 KB may indicate compression)
|
| 463 |
- Dimension warnings (< 20 slices may indicate incomplete volume)
|
| 464 |
- Metadata validation (voxel spacing, affine matrix)
|
|
|
|
| 696 |
}
|
| 697 |
```
|
| 698 |
|
| 699 |
+
**Note:** For mask files > 1 GB, `segmentation_file` will be `null` and `mask_path_token` will be provided. Use `mask_download_url` to download the file. Tokens expire after 24 hours.
|
| 700 |
|
| 701 |
#### GET /api/health
|
| 702 |
Check API health and model status.
|
app.py
CHANGED
|
@@ -307,10 +307,10 @@ async def segment_liver(
|
|
| 307 |
content = await file.read()
|
| 308 |
file_size_mb = len(content) / (1024**2)
|
| 309 |
|
| 310 |
-
if file_size_mb >
|
| 311 |
raise HTTPException(
|
| 312 |
status_code=413,
|
| 313 |
-
detail=f"File too large: {file_size_mb:.1f} MB. Maximum upload size is
|
| 314 |
)
|
| 315 |
|
| 316 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.nii.gz') as tmp_file:
|
|
@@ -329,7 +329,7 @@ async def segment_liver(
|
|
| 329 |
seg_path = result["segmentation_path"]
|
| 330 |
seg_file_size = os.path.getsize(seg_path) / (1024**2)
|
| 331 |
|
| 332 |
-
if seg_file_size >
|
| 333 |
token = secrets.token_urlsafe(16)
|
| 334 |
token_dir = "/tmp/seg_tokens"
|
| 335 |
os.makedirs(token_dir, exist_ok=True)
|
|
@@ -348,7 +348,7 @@ async def segment_liver(
|
|
| 348 |
result["mask_download_url"] = None
|
| 349 |
|
| 350 |
os.unlink(tmp_path)
|
| 351 |
-
if seg_file_size <=
|
| 352 |
os.unlink(seg_path)
|
| 353 |
|
| 354 |
return JSONResponse(content=result)
|
|
@@ -381,7 +381,7 @@ def create_interface():
|
|
| 381 |
nifti_input = gr.File(
|
| 382 |
file_count="single",
|
| 383 |
file_types=[".nii.gz", ".nii"],
|
| 384 |
-
label="Upload NIfTI File (max
|
| 385 |
)
|
| 386 |
|
| 387 |
modality = gr.Radio(
|
|
|
|
| 307 |
content = await file.read()
|
| 308 |
file_size_mb = len(content) / (1024**2)
|
| 309 |
|
| 310 |
+
if file_size_mb > 1000:
|
| 311 |
raise HTTPException(
|
| 312 |
status_code=413,
|
| 313 |
+
detail=f"File too large: {file_size_mb:.1f} MB. Maximum upload size is 1 GB. Please compress or resample your NIfTI file."
|
| 314 |
)
|
| 315 |
|
| 316 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.nii.gz') as tmp_file:
|
|
|
|
| 329 |
seg_path = result["segmentation_path"]
|
| 330 |
seg_file_size = os.path.getsize(seg_path) / (1024**2)
|
| 331 |
|
| 332 |
+
if seg_file_size > 1000:
|
| 333 |
token = secrets.token_urlsafe(16)
|
| 334 |
token_dir = "/tmp/seg_tokens"
|
| 335 |
os.makedirs(token_dir, exist_ok=True)
|
|
|
|
| 348 |
result["mask_download_url"] = None
|
| 349 |
|
| 350 |
os.unlink(tmp_path)
|
| 351 |
+
if seg_file_size <= 1000:
|
| 352 |
os.unlink(seg_path)
|
| 353 |
|
| 354 |
return JSONResponse(content=result)
|
|
|
|
| 381 |
nifti_input = gr.File(
|
| 382 |
file_count="single",
|
| 383 |
file_types=[".nii.gz", ".nii"],
|
| 384 |
+
label="Upload NIfTI File (max 1 GB)"
|
| 385 |
)
|
| 386 |
|
| 387 |
modality = gr.Radio(
|
processing.py
CHANGED
|
@@ -39,8 +39,8 @@ def preprocess_nifti(file_path, device=None):
|
|
| 39 |
file_size_kb = os.path.getsize(file_path) / 1024
|
| 40 |
if file_size == 0:
|
| 41 |
raise ValueError("NIfTI file is empty")
|
| 42 |
-
if file_size >
|
| 43 |
-
raise ValueError(f"NIfTI file too large: {file_size:.1f} MB. Maximum processing size is
|
| 44 |
|
| 45 |
if file_size_kb < 100:
|
| 46 |
print(f" ⚠ WARNING: File size is very small ({file_size_kb:.1f} KB). This may indicate:")
|
|
|
|
| 39 |
file_size_kb = os.path.getsize(file_path) / 1024
|
| 40 |
if file_size == 0:
|
| 41 |
raise ValueError("NIfTI file is empty")
|
| 42 |
+
if file_size > 2000:
|
| 43 |
+
raise ValueError(f"NIfTI file too large: {file_size:.1f} MB. Maximum processing size is 2 GB. For larger files, consider compression or resampling.")
|
| 44 |
|
| 45 |
if file_size_kb < 100:
|
| 46 |
print(f" ⚠ WARNING: File size is very small ({file_size_kb:.1f} KB). This may indicate:")
|