Skip to content

Commit

Permalink
fix: handle any prediction exception
Browse files Browse the repository at this point in the history
  • Loading branch information
danellecline committed Sep 30, 2024
1 parent f911e71 commit 64e8f96
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ async def get_ids(project: str = DEFAULT_PROJECT):

@app.post("/knn/{top_n}/{project}", status_code=status.HTTP_200_OK)
async def knn(files: List[UploadFile] = File(...), top_n: int = 1, project: str = DEFAULT_PROJECT):
info(f"Predicting {len(files)} for top {top_n} in project {project}")
if len(files) > BATCH_SIZE:
return {"error": f"Images should be less than batch size {BATCH_SIZE}"}
try:
info(f"Predicting {len(files)} for top {top_n} in project {project}")
if len(files) > BATCH_SIZE:
return {"error": f"Images should be less than batch size {BATCH_SIZE}"}

if top_n == 0:
return {"error": f"Please provide a valid top_n value greater than 0"}
if top_n == 0:
return {"error": f"Please provide a valid top_n value greater than 0"}

# Check if the project name is in the config
if project not in global_config.keys():
return {"error": f"Invalid project name {project}"}
# Check if the project name is in the config
if project not in global_config.keys():
return {"error": f"Invalid project name {project}"}

v = global_config[project]['v']
images = [f.file for f in files]
try:
v = global_config[project]['v']
images = [f.file for f in files]
predictions, scores, ids = v.predict(images, top_n)
return {"predictions": predictions, "scores": scores, "ids": ids}
except Exception as e:
Expand Down

0 comments on commit 64e8f96

Please sign in to comment.