# Public backend endpoint
from fastapi import Request
import requests
import logging
@app.post("/messages/{id}/predict")
async def predict(pred_req: Request):
mail_id = pred_req.id
# Start transaction...
text = messages_service.get_by_id(mail_id).body
pred_response = requests.post(
"http://<PRIVATE_URL>/predict",
json={"text": text}
)
label = pred_response.json().get("label", "")
if label in ["ham", "spam"]:
# -> post
else:
# -> deny
# End transaction...