Spaces:
Runtime error
Runtime error
Update main.py
Browse files12345619 unmodified lines262728293031323334from model_loader import load_vChain_modelfrom inference import preprocess_input, segment_allimport tempfileimport numpy as npimport nibabel as nib19 unmodified linesprint("Segmented Successfuly!", output.shape)output_img = nib.Nifti1Image(output, affine=np.eye(4))with tempfile.NamedTemporaryFile(suffix=".nii") as tempFile:nib.save(output_img, tempFile.name)return FileResponse(tempFile.name, media_type="multipart/form-data")except Exception as e:print(f"Error occurred: {str(e)}")123456719 unmodified lines27282930313233343536373839404142434445464748495051from model_loader import load_vChain_modelfrom inference import preprocess_input, segment_allimport ioimport gzipimport tempfileimport numpy as npimport nibabel as nib19 unmodified linesprint("Segmented Successfuly!", output.shape)output_img = nib.Nifti1Image(output, affine=np.eye(4))# with tempfile.NamedTemporaryFile(suffix=".nii") as tempFile:# nib.save(output_img, tempFile.name)# return FileResponse(tempFile.name, media_type="multipart/form-data")with io.BytesIO() as buffer:# Save the NIfTI image to the buffernib.save(nifti_img, buffer)buffer.seek(0) # Reset the buffer cursor to the beginning# Compress the buffer content using gzipwith io.BytesIO() as gz_buffer:with gzip.GzipFile(fileobj=gz_buffer, mode="wb") as gz_file:gz_file.write(buffer.read())# Get the compressed contentcompressed_content = gz_buffer.getvalue()# Return the compressed content as a streaming responsereturn StreamingResponse(content=compressed_content, media_type="application/octet-stream")except Exception as e:print(f"Error occurred: {str(e)}")
main.py+21-4