{ "cells": [ { "cell_type": "code", "execution_count": 8, "id": "initial_id", "metadata": { "collapsed": true, "ExecuteTime": { "end_time": "2025-01-11T19:07:39.073318726Z", "start_time": "2025-01-11T19:07:38.201074211Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Prediction Result: {'prediction': 'healthy'}\n" ] } ], "source": [ "import requests\n", "\n", "# Define the URL of the FastAPI endpoint\n", "url = \"http://127.0.0.1:8000/health_predict\" # Replace with the actual endpoint if hosted remotely\n", "\n", "# Define the input payload\n", "payload = {\n", " \"Gender\": \"M\",\n", " \"Age\": 67,\n", " \"SBP\": 145,\n", " \"HBP\": 84,\n", " \"heart_rate\": 116,\n", " \"Glucose\": 128,\n", " \"SpO2\": 98,\n", " \"Temprature\": 97.8\n", "}\n", "\n", "# Make the POST request\n", "response = requests.post(url, json=payload)\n", "\n", "# Print the response\n", "if response.status_code == 200:\n", " print(\"Prediction Result:\", response.json())\n", "else:\n", " print(f\"Error: {response.status_code}, Message: {response.text}\")\n" ] }, { "cell_type": "code", "execution_count": 9, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Prediction: Not Fraud\n" ] } ], "source": [ "import requests\n", "\n", "# URL of the FastAPI endpoint\n", "url = \"http://127.0.0.1:8000/fraud_predict\"\n", "\n", "# Sample data to send in the POST request (make sure the data format matches the model)\n", "input_data = {\n", " \"V1\": 0.1,\n", " \"V2\": 0.4,\n", " \"V3\": 0.7,\n", " \"V4\": 1.0,\n", " \"V5\": 1.3,\n", " \"V6\": 0.1,\n", " \"V7\": 0.4,\n", " \"V8\": 0.7,\n", " \"V9\": 1.0,\n", " \"V10\": 1.3,\n", " \"V11\": 0.1,\n", " \"V12\": 0.4,\n", " \"V13\": 0.7,\n", " \"V14\": 1.0,\n", " \"V15\": 1.3,\n", " \"V16\": 0.1,\n", " \"V17\": 0.4,\n", " \"V18\": 0.7,\n", " \"V19\": 1.0,\n", " \"V20\": 1.3,\n", " \"V21\": 0.1,\n", " \"V22\": 0.4,\n", " \"V23\": 0.7,\n", " \"V24\": 1.0,\n", " \"V25\": 1.3,\n", " \"V26\": 0.1,\n", " \"V27\": 0.4,\n", " \"V28\": 0.7,\n", " \"Amount\": 100\n", "}\n", "\n", "# Send the POST request to the FastAPI server\n", "response = requests.post(url, json=input_data)\n", "\n", "# Check if the request was successful and print the response\n", "if response.status_code == 200:\n", " result = response.json()\n", " print(\"Prediction:\", result[\"prediction\"])\n", "else:\n", " print(\"Error:\", response.status_code, response.text)\n" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2025-01-11T19:11:14.154786492Z", "start_time": "2025-01-11T19:11:13.225551826Z" } }, "id": "39edb6c6f953f8df" }, { "cell_type": "code", "execution_count": 17, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Prediction Result: {'prediction': 'not arrest'}\n" ] } ], "source": [ "import requests\n", "\n", "# Sample data to send in the request\n", "sample_data = {\n", " \"Case\": \"JF113025\",\n", " \"Block\": \"067XX S MORGAN ST\",\n", " \"IUCR\": 2826,\n", " \"Primary_Type\": \"OTHER OFFENSE\",\n", " \"Description\": \"HARASSMENT BY ELECTRONIC MEANS\",\n", " \"Location_Description\": \"RESIDENCE\",\n", " \"FBI_Code\": 26,\n", " \"Updated_On\": \"9/14/2023 15:41\",\n", " \"Location\": \"(41.771782439, -87.649436929)\"\n", "}\n", "\n", "# URL for FastAPI endpoint\n", "url = \"http://127.0.0.1:8000/predict_crime\"\n", "\n", "# Send a POST request with the sample data as JSON\n", "response = requests.post(url, json=sample_data)\n", "\n", "# Check if the request was successful\n", "if response.status_code == 200:\n", " print(f\"Prediction Result: {response.json()}\")\n", "else:\n", " print(f\"Error: {response.status_code}, {response.text}\")\n" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2025-01-11T19:44:26.136356206Z", "start_time": "2025-01-11T19:44:25.549072705Z" } }, "id": "be329568072d336c" }, { "cell_type": "code", "execution_count": 18, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2025-01-12 00:45:43.425294: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n", "To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n", "2025-01-12 00:45:44.479984: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "fastapi version: 0.115.4\n", "pydantic version: 2.9.2\n", "pickle version: 4.0\n", "joblib version: 1.3.2\n", "numpy version: 1.26.4\n", "tensorflow version: 2.16.1\n", "pandas version: 2.2.0\n" ] } ], "source": [ "import fastapi\n", "import pydantic\n", "import pickle\n", "import joblib\n", "import numpy as np\n", "import tensorflow as tf\n", "import pandas as pd\n", "\n", "# Print the versions of each library\n", "print(f\"fastapi version: {fastapi.__version__}\")\n", "print(f\"pydantic version: {pydantic.__version__}\")\n", "print(f\"pickle version: {pickle.format_version}\") # pickle doesn't have __version__, but you can check the format version\n", "print(f\"joblib version: {joblib.__version__}\")\n", "print(f\"numpy version: {np.__version__}\")\n", "print(f\"tensorflow version: {tf.__version__}\")\n", "print(f\"pandas version: {pd.__version__}\")\n" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2025-01-11T19:45:45.753678471Z", "start_time": "2025-01-11T19:45:42.265117643Z" } }, "id": "c76b855ced5fe0a3" }, { "cell_type": "code", "execution_count": null, "outputs": [], "source": [], "metadata": { "collapsed": false }, "id": "fc1962a8e8381309" } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 5 }