Handle numerical request data
You're building a content moderation system. The system needs to calculate a trust score for each user comment based on numerical features - length, user_reputation, and report_count. You'll create an endpoint that processes these features to make them compatible for the moderation model.
Note that the ML model and CommentMetrics Pydantic model with length(int), user_reputation(int) and report_count(int) are already created and loaded for you.
Bu egzersiz
Deploying AI into Production with FastAPI
kursunun bir parçasıdırEgzersiz talimatları
In
main.py, convert the incoming commentmetricsdata into aNumPy2D array and extractlength,user_reputation,report_countbefore passing these to the model.Make the prediction using the pre-loaded
modelby passing thefeaturesarray to it.Start the server by running
main.pyusing the commandpython3 main.py.Open another terminal from the top right corner of the terminal.

Test the
predict_trustendpoint using the curl command:
curl -X POST "http://localhost:8080/predict_trust" \
-H "Content-Type: application/json" \
-d '{
"length": 150,
"user_reputation": 100,
"report_count": 0
}'
Uygulamalı interaktif egzersiz
İnteraktif egzersizlerimizden biriyle teoriyi pratiğe dökün
Egzersizi başlat