Web application using starlette


I have trouble understanding how to implement a web application using Stralette in lesson2. I see the code in the lesson but I do not know where to implement this code? is this in a cell of the notebook? is there a good tutorial in using Starlette?

here is the code in the lesson I am refering to,

So you might create a route something like this (thanks to Simon Willison for the structure of this code):

* *@app.route("/classify-url", methods=["GET"])async def classify_url(request): bytes = await get_bytes(request.query_params["url"]) img = open_image(BytesIO(bytes)) _,_,losses = learner.predict(img) return JSONResponse({ "predictions": sorted( zip(cat_learner.data.classes, map(float, losses)), key=lambda p: p[1], reverse=True ) })* *

I‘ve built a repo to deploy fastai Models using starlette. Maybe the Code helps you Unterstand how starlette works:). Let me know if you have any questions.


Hi florianl hope all is well!
Great little server and app!
Cheers mrfabulous1 :smiley: :smiley:

1 Like