I am having a fast API that does ml predictions and uses celery for task queue.
prediction code
response = {}
async def predictions(solute, solvent):
m = Chem.MolFromSmiles(solute,sanitize=False)
n = Chem.MolFromSmiles(solvent,sanitize=False)
mol = Chem.MolFromSmiles(solute)
solute = Chem.MolToSmiles(mol)
mol = Chem.MolFromSmiles(solvent)
solvent = Chem.MolToSmiles(mol)
interaction_map_one = torch.trunc(interaction_map)
response["interaction_map"] = (interaction_map_one.detach().numpy()).tolist()
response["predictions"] = delta_g.item()
and my function in worker.py
from model.model import predictions, response
@celery.task(name='predictions')
def predictions(solute, solvent):
return {'result': response}
and main.py where i create the celery task
@app.get(api_names[0])
async def predict(solute,solvent):
task = predictions.delay(solute,solvent)
return JSONResponse({'task_id': task.id})
Actually, I am migrating from fast API background tasks to celery and facing problems with returning responses. When I am running it is giving an empty dictionary celery which means it's not running the prediction. But I don't know where I am doing wrong. If you can check the below picture you will understand what I am saying.
I am guessing I have done some wrong in the worker.py but not sure what it is.
I have tried using but still I am getting empty dictionary.
from model.model import predictions, response
@celery.task(name='predictions')
def create_task(solute, solvent):
predictions(solute, solvent)
return {'result': response}
