From b934a6b6e97838ff213dd2cebd70202eb058617f Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Thu, 22 Sep 2022 22:55:57 +0530 Subject: [PATCH] Compatibility mode for API calls made without the streaming flag --- ui/server.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ui/server.py b/ui/server.py index 1532794b..2ca0f88d 100644 --- a/ui/server.py +++ b/ui/server.py @@ -114,16 +114,24 @@ def image(req : ImageRequest): r.use_face_correction = req.use_face_correction r.show_only_filtered_image = req.show_only_filtered_image - r.stream_progress_updates = req.stream_progress_updates + r.stream_progress_updates = True # the underlying implementation only supports streaming r.stream_image_progress = req.stream_image_progress try: + if not req.stream_progress_updates: + r.stream_image_progress = False + res = runtime.mk_img(r) - if r.stream_progress_updates: + if req.stream_progress_updates: return StreamingResponse(res, media_type='application/json') - else: - return res.json() + else: # compatibility mode: buffer the streaming responses, and return the last one + last_result = None + + for result in res: + last_result = result + + return json.loads(last_result) except Exception as e: print(traceback.format_exc()) return HTTPException(status_code=500, detail=str(e))