REST API Integration
Learn to integrate inference code as a REST API.
This lesson contains a step-by-step guide to integrate our image classification model into the FastAPI framework. We’ll serve it as an HTTP POST API.
We’ll reuse some of the code from our previous lesson to perform the following operations:
- Create the FastAPI instance.
- Add the CORS middleware.
Press + to interact
from fastapi import FastAPI, File, UploadFilefrom fastapi.middleware.cors import CORSMiddlewareimport torchfrom PIL import Imageimport torchvision.transforms as transformsimport timmimport ioapp = FastAPI(title="Image Classification API",description="Working demo for weather classification.",version="0.0.1")app.add_middleware(CORSMiddleware,allow_origins=["*"],allow_credentials=True,allow_methods=["*"],allow_headers=["*"],)print('The title of the application is:', app.title)print('The application contains the following middleware:', app.user_middleware)
Startup event
The startup event handler is the ideal place to ...
Access this course and 1400+ top-rated courses and projects.