Your Name commited on
Commit
2c58008
1 Parent(s): c1f292a

set inference to false once finished

Browse files
Files changed (1) hide show
  1. handler.py +40 -38
handler.py CHANGED
@@ -222,44 +222,6 @@ class EndpointHandler:
222
  )
223
  return self.pipe
224
 
225
- def __call__(self, data: Any) -> Dict:
226
- """Handle incoming requests."""
227
-
228
- action = data.get("action", None)
229
- request_id = data.get("request_id")
230
-
231
- # Check if the request_id is valid for all actions
232
- if not request_id:
233
- return {"flag": "error", "message": "Missing request_id."}
234
-
235
- if action == "check_progress":
236
- return self.check_progress(request_id)
237
-
238
- elif action == "inference":
239
- # Check if an inference is already in progress
240
- if self.inference_in_progress:
241
- return {
242
- "flag": "error",
243
- "message": "Another inference is already in progress. Please wait.",
244
- }
245
-
246
- # Set the inference state to in progress
247
- self.clean_request_data(request_id)
248
- self.inference_in_progress = True
249
- self.inference_progress[request_id] = 0
250
- self.inference_images[request_id] = None
251
-
252
- self.executor.submit(self.start_inference, data)
253
-
254
- return {
255
- "flag": "success",
256
- "message": "Inference started",
257
- "request_id": request_id,
258
- }
259
-
260
- else:
261
- return {"flag": "error", "message": f"Unsupported action: {action}"}
262
-
263
  def clean_request_data(self, request_id: str):
264
  """Clean up the data related to a specific request ID."""
265
 
@@ -418,9 +380,49 @@ class EndpointHandler:
418
  num_inference_steps, 0, image, request_id, "complete"
419
  )
420
 
 
 
421
  # for debug
422
  # image.save("squirelb.png", format="PNG")
423
 
424
  except Exception as e:
425
  # Handle any other exceptions and return an error response
426
  return {"flag": "error", "message": str(e)}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
  )
223
  return self.pipe
224
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
  def clean_request_data(self, request_id: str):
226
  """Clean up the data related to a specific request ID."""
227
 
 
380
  num_inference_steps, 0, image, request_id, "complete"
381
  )
382
 
383
+ self.inference_in_progress = False
384
+
385
  # for debug
386
  # image.save("squirelb.png", format="PNG")
387
 
388
  except Exception as e:
389
  # Handle any other exceptions and return an error response
390
  return {"flag": "error", "message": str(e)}
391
+
392
+ def __call__(self, data: Any) -> Dict:
393
+ """Handle incoming requests."""
394
+
395
+ action = data.get("action", None)
396
+ request_id = data.get("request_id")
397
+
398
+ # Check if the request_id is valid for all actions
399
+ if not request_id:
400
+ return {"flag": "error", "message": "Missing request_id."}
401
+
402
+ if action == "check_progress":
403
+ return self.check_progress(request_id)
404
+
405
+ elif action == "inference":
406
+ # Check if an inference is already in progress
407
+ if self.inference_in_progress:
408
+ return {
409
+ "flag": "error",
410
+ "message": "Another inference is already in progress. Please wait.",
411
+ }
412
+
413
+ # Set the inference state to in progress
414
+ self.clean_request_data(request_id)
415
+ self.inference_in_progress = True
416
+ self.inference_progress[request_id] = 0
417
+ self.inference_images[request_id] = None
418
+
419
+ self.executor.submit(self.start_inference, data)
420
+
421
+ return {
422
+ "flag": "success",
423
+ "message": "Inference started",
424
+ "request_id": request_id,
425
+ }
426
+
427
+ else:
428
+ return {"flag": "error", "message": f"Unsupported action: {action}"}