Last active
July 10, 2022 21:47
-
-
Save ashmibanerjee/3acb6616ddc1ac698314f7e955c48b8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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