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.
Questo esercizio fa parte del corso
Deploying AI into Production with FastAPI
Istruzioni dell'esercizio
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
}'
Esercizio pratico interattivo
Passa dalla teoria alla pratica con uno dei nostri esercizi interattivi
Inizia esercizio