{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Deploy ML Models with FastAPI & Docker\n",
        "Xenors practice notebook. Run each cell and compare the output with the tutorial page.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Validate request data with Pydantic\n",
        "Schema validation prevents malformed requests reaching the model.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "from pydantic import BaseModel, Field\n",
        "class ChurnRequest(BaseModel):\n",
        "    tenure: int = Field(ge=0)\n",
        "    monthly_charges: float = Field(gt=0)\n",
        "print(ChurnRequest(tenure=12, monthly_charges=79.5).model_dump())\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Expected/checkpoint**\n",
        "```text\n{'tenure': 12, 'monthly_charges': 79.5}\n```\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Smoke-test a prediction endpoint\n",
        "A deployment is not done until an external client can call it successfully.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import requests\n",
        "r = requests.post('http://localhost:8000/predict', json={'tenure':12,'monthly_charges':79.5})\n",
        "print(r.status_code)\n",
        "print(r.json())\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Expected/checkpoint**\n",
        "```text\n200\n{\"prediction\": 0, \"probability\": 0.18}\n```\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3.x"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}