I am using FastAPI to make predictions using a ML model. When I give a task_id
and input
, the app should add it to the background task and return the response accordingly. However, I am getting Error 500
when I try to do it.
After adding task_id_globally
, it started throwing errors before it worked fine.
Error
File ".\app\main.py", line 36, in post
return {'result': response_name[task_id_global]}
TypeError: list indices must be integers or slices, not NoneType
Code
task_id_global = None
@app.get('/predict')
async def predict(task_id:int, background_tasks: BackgroundTasks,solute,solvent):
task_id_global = task_id
if task_id == 0:
background_tasks.add_task(predictions,solute,solvent)
return {'success'}
elif task_id == 1:
background_tasks.add_task(predictions_two,solute)
return {'success'}
else:
return "Give proper task_id"
response_name = [response, attach_drug_name()]
@app.get('/predict_solubility')
async def post():
return {'result': response_name[task_id_global]}