File size: 7,164 Bytes
27dbc11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
{
 "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
}