Deploying AI into Production with FastAPI
Matt Eckerle
Software and Data Engineering Leader


class CommentMetrics(BaseModel): length: int user_karma: int report_count: intclass CommentText(BaseModel): content: str

app = FastAPI()@app.post("/predict")def predict_score(data: CommentMetrics):features = np.array([ data.length, data.user_karma, data.report_count ])model = CommentScorer() prediction = model.predict(features)return {"prediction": round(prediction, 2), "input": data.dict()}
@app.post("/analyze_text")def analyze(comment: CommentText):forbidden = ["spam", "hate", "free" "fake", "sign up"]text_lower = comment.lower()issues = [word for word in forbidden if word in text_lower]return { "issues": issues, "needs_moderation": len(issues) }
Output for comment: Sign up for free
{
"issues": ["free", "sign up"],
"needs_moderation": 2
}
Deploying AI into Production with FastAPI