I am using fast API to do predictions. I am taking the if and the inputs through the get request and returning the response. But I want to change the endpoint dynamically from the input id given by the user and I was unable to do it. I am getting name task_id is not defined
from pydantic import BaseModel
class SoluteSolvent(BaseModel):
solvent: str
solute: str
task_id: int
api_names = ['/predict','/predict_json']
@app.get(api_names[task_id])
def predict(task_id: int,solute: str, solvent: str):
if task_id == 0:
results = predictions(solute, solvent)
response["interaction_map"] = (results[1].detach().numpy()).tolist()
response["predictions"] = results[0].item()
return {'result': response}
elif task_id == 1:
return "this is second one"