Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -30,13 +30,12 @@ async def segment(files: list[UploadFile]):
|
|
| 30 |
# with tempfile.NamedTemporaryFile(suffix=".nii") as tempFile:
|
| 31 |
# nib.save(output_img, tempFile.name)
|
| 32 |
# return FileResponse(tempFile.name, media_type="multipart/form-data")
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
|
| 41 |
except Exception as e:
|
| 42 |
print(f"Error occurred: {str(e)}")
|
|
|
|
| 30 |
# with tempfile.NamedTemporaryFile(suffix=".nii") as tempFile:
|
| 31 |
# nib.save(output_img, tempFile.name)
|
| 32 |
# return FileResponse(tempFile.name, media_type="multipart/form-data")
|
| 33 |
+
|
| 34 |
+
with tempfile.NamedTemporaryFile(suffix=".nii", delete=False) as tempFile:
|
| 35 |
+
nib.save(output_img, tempFile.name)
|
| 36 |
+
tempFile.seek(0) # Move cursor to the beginning of the file
|
| 37 |
+
file_content = tempFile.read()
|
| 38 |
+
return StreamingResponse(content=file_content, media_type="application/octet-stream")
|
|
|
|
| 39 |
|
| 40 |
except Exception as e:
|
| 41 |
print(f"Error occurred: {str(e)}")
|