Skip to content

Instantly share code, notes, and snippets.

@ashmibanerjee
Last active July 10, 2022 21:47
Show Gist options
  • Save ashmibanerjee/3acb6616ddc1ac698314f7e955c48b8f to your computer and use it in GitHub Desktop.
Save ashmibanerjee/3acb6616ddc1ac698314f7e955c48b8f to your computer and use it in GitHub Desktop.
from fastapi import FastAPI, HTTPException
from src.pred.image_classifier import *
from pydantic import BaseModel
app = FastAPI(title="Image Classifier API")
class Img(BaseModel):
img_url: str
@app.post("/predict/tf/", status_code=200)
async def predict_tf(request: Img):
prediction = tf_run_classifier(request.img_url)
if not prediction:
# the exception is raised, not returned - you will get a validation
# error otherwise.
raise HTTPException(
status_code=404, detail="Image could not be downloaded"
)
return prediction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment