Similar to how we built a REST API in Chapter 18, Serving Models with a RESTful API, let's start by serving median values from a JSON file. This will help us to set the model for working with Chalice:
- First of all, we need to load the JSON object:
import json
with open('./model.json', 'r') as f:
model = json.load(f)
- Now we will rename the route and define the last resource to map to the complaint type (in the same way we would for FastAPI, again!). We will also have to import a Response object:
from chalice import Response
@app.route('/predict/{complaint_type}', methods=['GET'])
def predict(complaint_type:str) -> Response:
- Finally, finalize the function by adding simple lookup logic; here, we decided to be nice and let our user know if they pass a wrong complaint type:
@app.route('/predict...