File tree 1 file changed +6
-4
lines changed
1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -555,19 +555,21 @@ async def upload_image(image: UploadFile = File(...)):
555
555
response_future = asyncio .Future ()
556
556
await request_queue .put ((image_tensor , response_future ))
557
557
masks = await response_future
558
-
559
- # Save an example
560
- plt .figure (figsize = (image_tensor .shape [1 ]/ 100. , image_tensor .shape [0 ]/ 100. ), dpi = 100 )
558
+
559
+ # Create figure and ensure it's closed after generating response
560
+ fig = plt .figure (figsize = (image_tensor .shape [1 ]/ 100. , image_tensor .shape [0 ]/ 100. ), dpi = 100 )
561
561
plt .imshow (image_tensor )
562
562
show_anns (masks , rle_to_mask )
563
563
plt .axis ('off' )
564
564
plt .tight_layout ()
565
+
565
566
buf = BytesIO ()
566
567
plt .savefig (buf , format = 'png' )
567
568
buf .seek (0 )
569
+ plt .close (fig ) # Close figure after we're done with it
570
+
568
571
return StreamingResponse (buf , media_type = "image/png" )
569
572
570
-
571
573
# uvicorn.run(app, host=host, port=port, log_level="info")
572
574
uvicorn .run (app , host = host , port = port )
573
575
You can’t perform that action at this time.
0 commit comments