CoolFace
Apppublic

fuminnovation07/machinelearning_models

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
testing.ipynb257 linesDownload Raw Back to root
1{2 "cells": [3  {4   "cell_type": "code",5   "execution_count": 8,6   "id": "initial_id",7   "metadata": {8    "collapsed": true,9    "ExecuteTime": {10     "end_time": "2025-01-11T19:07:39.073318726Z",11     "start_time": "2025-01-11T19:07:38.201074211Z"12    }13   },14   "outputs": [15    {16     "name": "stdout",17     "output_type": "stream",18     "text": [19      "Prediction Result: {'prediction': 'healthy'}\n"20     ]21    }22   ],23   "source": [24    "import requests\n",25    "\n",26    "# Define the URL of the FastAPI endpoint\n",27    "url = \"http://127.0.0.1:8000/health_predict\"  # Replace with the actual endpoint if hosted remotely\n",28    "\n",29    "# Define the input payload\n",30    "payload = {\n",31    "    \"Gender\": \"M\",\n",32    "    \"Age\": 67,\n",33    "    \"SBP\": 145,\n",34    "    \"HBP\": 84,\n",35    "    \"heart_rate\": 116,\n",36    "    \"Glucose\": 128,\n",37    "    \"SpO2\": 98,\n",38    "    \"Temprature\": 97.8\n",39    "}\n",40    "\n",41    "# Make the POST request\n",42    "response = requests.post(url, json=payload)\n",43    "\n",44    "# Print the response\n",45    "if response.status_code == 200:\n",46    "    print(\"Prediction Result:\", response.json())\n",47    "else:\n",48    "    print(f\"Error: {response.status_code}, Message: {response.text}\")\n"49   ]50  },51  {52   "cell_type": "code",53   "execution_count": 9,54   "outputs": [55    {56     "name": "stdout",57     "output_type": "stream",58     "text": [59      "Prediction: Not Fraud\n"60     ]61    }62   ],63   "source": [64    "import requests\n",65    "\n",66    "# URL of the FastAPI endpoint\n",67    "url = \"http://127.0.0.1:8000/fraud_predict\"\n",68    "\n",69    "# Sample data to send in the POST request (make sure the data format matches the model)\n",70    "input_data = {\n",71    "    \"V1\": 0.1,\n",72    "    \"V2\": 0.4,\n",73    "    \"V3\": 0.7,\n",74    "    \"V4\": 1.0,\n",75    "    \"V5\": 1.3,\n",76    "    \"V6\": 0.1,\n",77    "    \"V7\": 0.4,\n",78    "    \"V8\": 0.7,\n",79    "    \"V9\": 1.0,\n",80    "    \"V10\": 1.3,\n",81    "    \"V11\": 0.1,\n",82    "    \"V12\": 0.4,\n",83    "    \"V13\": 0.7,\n",84    "    \"V14\": 1.0,\n",85    "    \"V15\": 1.3,\n",86    "    \"V16\": 0.1,\n",87    "    \"V17\": 0.4,\n",88    "    \"V18\": 0.7,\n",89    "    \"V19\": 1.0,\n",90    "    \"V20\": 1.3,\n",91    "    \"V21\": 0.1,\n",92    "    \"V22\": 0.4,\n",93    "    \"V23\": 0.7,\n",94    "    \"V24\": 1.0,\n",95    "    \"V25\": 1.3,\n",96    "    \"V26\": 0.1,\n",97    "    \"V27\": 0.4,\n",98    "    \"V28\": 0.7,\n",99    "    \"Amount\": 100\n",100    "}\n",101    "\n",102    "# Send the POST request to the FastAPI server\n",103    "response = requests.post(url, json=input_data)\n",104    "\n",105    "# Check if the request was successful and print the response\n",106    "if response.status_code == 200:\n",107    "    result = response.json()\n",108    "    print(\"Prediction:\", result[\"prediction\"])\n",109    "else:\n",110    "    print(\"Error:\", response.status_code, response.text)\n"111   ],112   "metadata": {113    "collapsed": false,114    "ExecuteTime": {115     "end_time": "2025-01-11T19:11:14.154786492Z",116     "start_time": "2025-01-11T19:11:13.225551826Z"117    }118   },119   "id": "39edb6c6f953f8df"120  },121  {122   "cell_type": "code",123   "execution_count": 17,124   "outputs": [125    {126     "name": "stdout",127     "output_type": "stream",128     "text": [129      "Prediction Result: {'prediction': 'not arrest'}\n"130     ]131    }132   ],133   "source": [134    "import requests\n",135    "\n",136    "# Sample data to send in the request\n",137    "sample_data = {\n",138    "    \"Case\": \"JF113025\",\n",139    "    \"Block\": \"067XX S MORGAN ST\",\n",140    "    \"IUCR\": 2826,\n",141    "    \"Primary_Type\": \"OTHER OFFENSE\",\n",142    "    \"Description\": \"HARASSMENT BY ELECTRONIC MEANS\",\n",143    "    \"Location_Description\": \"RESIDENCE\",\n",144    "    \"FBI_Code\": 26,\n",145    "    \"Updated_On\": \"9/14/2023 15:41\",\n",146    "    \"Location\": \"(41.771782439, -87.649436929)\"\n",147    "}\n",148    "\n",149    "# URL for FastAPI endpoint\n",150    "url = \"http://127.0.0.1:8000/predict_crime\"\n",151    "\n",152    "# Send a POST request with the sample data as JSON\n",153    "response = requests.post(url, json=sample_data)\n",154    "\n",155    "# Check if the request was successful\n",156    "if response.status_code == 200:\n",157    "    print(f\"Prediction Result: {response.json()}\")\n",158    "else:\n",159    "    print(f\"Error: {response.status_code}, {response.text}\")\n"160   ],161   "metadata": {162    "collapsed": false,163    "ExecuteTime": {164     "end_time": "2025-01-11T19:44:26.136356206Z",165     "start_time": "2025-01-11T19:44:25.549072705Z"166    }167   },168   "id": "be329568072d336c"169  },170  {171   "cell_type": "code",172   "execution_count": 18,173   "outputs": [174    {175     "name": "stderr",176     "output_type": "stream",177     "text": [178      "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",179      "To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n",180      "2025-01-12 00:45:44.479984: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n"181     ]182    },183    {184     "name": "stdout",185     "output_type": "stream",186     "text": [187      "fastapi version: 0.115.4\n",188      "pydantic version: 2.9.2\n",189      "pickle version: 4.0\n",190      "joblib version: 1.3.2\n",191      "numpy version: 1.26.4\n",192      "tensorflow version: 2.16.1\n",193      "pandas version: 2.2.0\n"194     ]195    }196   ],197   "source": [198    "import fastapi\n",199    "import pydantic\n",200    "import pickle\n",201    "import joblib\n",202    "import numpy as np\n",203    "import tensorflow as tf\n",204    "import pandas as pd\n",205    "\n",206    "# Print the versions of each library\n",207    "print(f\"fastapi version: {fastapi.__version__}\")\n",208    "print(f\"pydantic version: {pydantic.__version__}\")\n",209    "print(f\"pickle version: {pickle.format_version}\")  # pickle doesn't have __version__, but you can check the format version\n",210    "print(f\"joblib version: {joblib.__version__}\")\n",211    "print(f\"numpy version: {np.__version__}\")\n",212    "print(f\"tensorflow version: {tf.__version__}\")\n",213    "print(f\"pandas version: {pd.__version__}\")\n"214   ],215   "metadata": {216    "collapsed": false,217    "ExecuteTime": {218     "end_time": "2025-01-11T19:45:45.753678471Z",219     "start_time": "2025-01-11T19:45:42.265117643Z"220    }221   },222   "id": "c76b855ced5fe0a3"223  },224  {225   "cell_type": "code",226   "execution_count": null,227   "outputs": [],228   "source": [],229   "metadata": {230    "collapsed": false231   },232   "id": "fc1962a8e8381309"233  }234 ],235 "metadata": {236  "kernelspec": {237   "display_name": "Python 3",238   "language": "python",239   "name": "python3"240  },241  "language_info": {242   "codemirror_mode": {243    "name": "ipython",244    "version": 2245   },246   "file_extension": ".py",247   "mimetype": "text/x-python",248   "name": "python",249   "nbconvert_exporter": "python",250   "pygments_lexer": "ipython2",251   "version": "2.7.6"252  }253 },254 "nbformat": 4,255 "nbformat_minor": 5256}257