0

I am using Django rest framework to do prediction on two strings and using celery to run inference. But I was unable to make use of celery workers even though I have done everything perfectly. I am getting predictions from drf only

I am using redis as a broker.

My tasks.py

@shared_task(bind=True)
def predictions(self,solute, solvent):

    mol = Chem.MolFromSmiles(solute)
    mol = Chem.AddHs(mol)
    solute = Chem.MolToSmiles(mol)
    solute_graph = get_graph_from_smile(solute)

    mol = Chem.MolFromSmiles(solvent)
    mol = Chem.AddHs(mol)
    solvent = Chem.MolToSmiles(mol)
    solvent_graph = get_graph_from_smile(solvent)
    delta_g, interaction_map = model([solute_graph.to(device), solvent_graph.to(device)])
    return delta_g, torch.trunc(interaction_map)

My views.py

@api_view(['GET'])
def result(request):
    response = {}
    solute = request.GET.get('solute')
    solvent = request.GET.get('solvent')
    results = predictions(solute,solvent)
    response["interaction_map"] = (results[1].detach().numpy()).tolist()

    response["predictions"] = results[0].item()

    return Response({'result': response}, status=200)

I guess the problem is not adding .delay() to results = predictions(solute,solvent) but if I add results = predictions(solute,solvent).delay() I am getting error.

My flower panel enter image description here

Even though I am getting my prediction perfectly without any error their is no celery task is running please help me where I am doing wrong

6
  • What's the error? Commented Jan 10, 2022 at 2:22
  • while using results = predictions(solute,solvent).delay() i am getting error predictions() missing 2 required positional arguments: 'solute' and 'solvent' but i am passing solute and solvent @BrianDestura Commented Jan 10, 2022 at 2:35
  • By using delay, it should be: predictions.delay(solute,solvent) Commented Jan 10, 2022 at 2:41
  • @BrianDestura then I am getting 'AsyncResult' object is not subscriptable error Commented Jan 10, 2022 at 2:45
  • You might want to revisit the docs for this. At least in this case, you will have to do results.get() to get the result Commented Jan 10, 2022 at 2:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.