mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
making model api async so we can run from within fastapi endpoint and locally
This commit is contained in:
parent
5e5609a7ca
commit
ff44212f98
1 changed files with 9 additions and 4 deletions
|
|
@ -289,8 +289,7 @@ class ModelApi:
|
|||
|
||||
logger.info("Lambda functions are warmed up and ready to go!")
|
||||
|
||||
def async_paginated_predictions(self, data, bucket, batch_size, model_prefixes=None, extract_ids=True):
|
||||
|
||||
async def async_paginated_predictions(self, data, bucket, batch_size, model_prefixes=None, extract_ids=True):
|
||||
all_predictions = self.predictions_template()
|
||||
to_loop_over = range(0, data.shape[0], batch_size)
|
||||
|
||||
|
|
@ -306,7 +305,13 @@ class ModelApi:
|
|||
for key, scored in predictions_dict.items():
|
||||
all_predictions[key] = pd.concat([all_predictions[key], scored])
|
||||
|
||||
# Run the async function
|
||||
asyncio.run(run_batches())
|
||||
# Check if there is an existing event loop
|
||||
try:
|
||||
# If there is an existing event loop, await the coroutine directly
|
||||
loop = asyncio.get_running_loop()
|
||||
await run_batches()
|
||||
except RuntimeError: # No running event loop
|
||||
# If no event loop is running, use asyncio.run()
|
||||
asyncio.run(run_batches())
|
||||
|
||||
return all_predictions
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue