LouayMagdy commited on
Commit
30e912a
·
verified ·
1 Parent(s): 88389cf

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +8 -8
main.py CHANGED
@@ -32,21 +32,21 @@ async def segment(files: list[UploadFile]):
32
  # return FileResponse(tempFile.name, media_type="multipart/form-data")
33
 
34
  with io.BytesIO() as buffer:
35
- # Save the NIfTI image to the buffer
36
  nib.save(nifti_img, buffer)
37
  buffer.seek(0) # Reset the buffer cursor to the beginning
38
 
39
  # Compress the buffer content using gzip
40
  with io.BytesIO() as gz_buffer:
41
  with gzip.GzipFile(fileobj=gz_buffer, mode="wb") as gz_file:
42
- gz_file.write(buffer.read())
 
 
 
 
 
 
43
 
44
- # Get the compressed content
45
- compressed_content = gz_buffer.getvalue()
46
-
47
- # Return the compressed content as a streaming response
48
- return StreamingResponse(content=compressed_content, media_type="application/octet-stream")
49
-
50
  except Exception as e:
51
  print(f"Error occurred: {str(e)}")
52
  return {"msg": "An error occurred during segmentation."}
 
32
  # return FileResponse(tempFile.name, media_type="multipart/form-data")
33
 
34
  with io.BytesIO() as buffer:
35
+ # Save the NIfTI image to the buffer
36
  nib.save(nifti_img, buffer)
37
  buffer.seek(0) # Reset the buffer cursor to the beginning
38
 
39
  # Compress the buffer content using gzip
40
  with io.BytesIO() as gz_buffer:
41
  with gzip.GzipFile(fileobj=gz_buffer, mode="wb") as gz_file:
42
+ gz_file.write(buffer.getvalue()) # Write the buffer content directly
43
+
44
+ # Reset the buffer cursor to the beginning
45
+ gz_buffer.seek(0)
46
+
47
+ # Return the compressed content as a streaming response
48
+ return StreamingResponse(content=gz_buffer, media_type="application/octet-stream")
49
 
 
 
 
 
 
 
50
  except Exception as e:
51
  print(f"Error occurred: {str(e)}")
52
  return {"msg": "An error occurred during segmentation."}