Purpose : to find a web framwork for building APIs with python that can have all the utilities we need.
- Serving a Machine learning model with FastAPI
- FastAPI Asynchronize function
- FastAPI integrate with openCensus
- Having observability of the fastAPI web api in azure Application Insight via opencensus
- Iris dataset multiclass classification prediction
- sepal length in cm
- sepal width in cm
- petal length in cm
- petal width in cm
- output class: -- Iris Setosa [0] -- Iris Versicolour [1] -- Iris Virginica [2]
- Random Forest classifier
- Install all the modules in
requirements.txt
usingpip install -y XXXX
- In the terminal input
python main.py
, then the model API is start running. - Make a request:
-- 1. click the url
https://0.0.0.0:8080
, then add/docs
to enter the openapi swagger, then go the the/predict
tab and clickTry it out
. -- 2. Open another terminal, inputpython request.py
. Therequest.py
has 2 steps, first, post corresponding json data to the correct url, then request for final output of API to print out as json format.
- Follow the
DockerRun.txt
to build and run a docker image contains the API framework. - Then follow the same procedure above to make a request.
- In terminal, login using
az acr login --name RAPContainerRegistry
, login name and password can be found on Azure Portal - Follow the
DockerRun.txt
to build the docker. - Tag the docker image name with following format
docker tag nameOfDockerImage rapcontainerregistry.azurecr.io/fastapi:1.0.6
,fastapi:1.0.6
means repository namefastapi
, tags1.0.6
, so you can setup any repository name and version you want. - use
docker push rapcontainerregistry.azurecr.io/fastapi:1.0.6
to push the image to the RAPContainerRegistry, now you should able to see it inRepositories
tab. - Deploy the specific tags to web app.
- Go to that web server to start the web app by clicking the URL.
- Request using
python request_url.py
with correct set up of url.
- Go into the
main.py
, change theInstrumentation Key
to the corresponding Instrumentation key for your Apllication Insights. - Then after you have restart your web app, every time you make a request or a Failed request, you should able to see it in the Application Insights overview or Failures tab.
- In this case middleware only tracks the tracing of the web app activity, if you need track both log and metrics, here is the setup MS Azure Monitor
- Now you can request the model prediction by upload
csv
file usingrequest_file.py