Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

303
Vistas
unable to do prediction in fastapi and return response

I have a machine learning API where I am doing predictions. It's working fine before introducing task_id. But after adding task_id I am getting response as null even though it's working properly but not returning the response

@app.get('/predict')
def predict(task_id,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}
    if task_id == 1:
        return "this is second one"

enter image description here

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The reason for returning null is that your code never makes it into the if statements (which, by the way, should be if...elif, rather than having two individual if statements). This is due to your endpoint receiving task_id as a string (i.e., "0", "1", etc), but you check against integer values. Thus, you should declare task_id as int parameter, as shown below:

@app.get('/predict')
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"
    else:
        return "some default response"
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda