[3798b7]: / client / src / components / Prediction.jsx

Download this file

251 lines (244 with data), 10.7 kB

  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
import React, { useEffect, useState } from "react";
import { motion } from "framer-motion";
import axios from "axios";
const Prediction = () => {
const [userInput, setUserInput] = useState({
Age: "",
Pregnancies: "",
Glucose: "",
BloodPressure: "",
Insulin: "",
BMI: "",
SkinThickness: "",
DPF: "",
});
const [prediction, setPrediction] = useState(null);
const [buttonDisabled, setButtonDisabled] = useState(false);
const handleSubmit = async (e) => {
e.preventDefault();
setButtonDisabled(true);
try {
const response = await axios.post(
"https://diabetes-prediction-1-6a5i.onrender.com/predict",
userInput
);
setPrediction(response.data);
console.log(response.data);
} catch (error) {
console.error("Error:", error);
}
setButtonDisabled(false);
};
useEffect(() => {
window.scrollTo(0, 0);
});
const handleChange = (e) => {
setUserInput({ ...userInput, [e.target.name]: e.target.value });
};
return (
<div className="min-h-screen bg-gradient-to-r from-purple-500 to-pink-500 flex flex-col items-center justify-center pb-3 md:pb-0">
<div className="flex flex-col sm:flex-row items-center justify-center w-full">
<motion.div
initial={{ opacity: 0, x: -150 }}
whileInView={{ opacity: 1, x: 0 }}
viewport={{ once: true }}
transition={{
duration: 1,
type: "spring",
stiffness: 100,
delay: 0.5,
}}
className="max-w-md mx-auto bg-white rounded-lg shadow-lg p-8 sm:p-6 md:p-8 w-full sm:w-auto"
>
<h1 className="text-3xl font-bold mb-6 text-center text-purple-800">
Enter all details
</h1>
<form onSubmit={handleSubmit}>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<div className="mb-4">
<label
htmlFor="Age"
className="block text-gray-700 font-bold mb-2"
>
Age
</label>
<input
type="number"
name="Age"
value={userInput.Age}
onChange={handleChange}
className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline focus:ring-2 focus:ring-purple-500"
/>
</div>
<div className="mb-4">
<label
htmlFor="Pregnancies"
className="block text-gray-700 font-bold mb-2"
>
Pregnancies
</label>
<input
type="number"
name="Pregnancies"
value={userInput.Pregnancies}
onChange={handleChange}
className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline focus:ring-2 focus:ring-purple-500"
/>
</div>
<div className="mb-4">
<label
htmlFor="Glucose"
className="block text-gray-700 font-bold mb-2"
>
Glucose
</label>
<input
type="number"
name="Glucose"
value={userInput.Glucose}
onChange={handleChange}
className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline focus:ring-2 focus:ring-purple-500"
/>
</div>
<div className="mb-4">
<label
htmlFor="BloodPressure"
className="block text-gray-700 font-bold mb-2"
>
Blood Pressure
</label>
<input
type="number"
name="BloodPressure"
value={userInput.BloodPressure}
onChange={handleChange}
className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline focus:ring-2 focus:ring-purple-500"
/>
</div>
</div>
<div>
<div className="mb-4">
<label
htmlFor="Insulin"
className="block text-gray-700 font-bold mb-2"
>
Insulin
</label>
<input
type="number"
name="Insulin"
value={userInput.Insulin}
onChange={handleChange}
className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline focus:ring-2 focus:ring-purple-500"
/>
</div>
<div className="mb-4">
<label
htmlFor="BMI"
className="block text-gray-700 font-bold mb-2"
>
BMI
</label>
<input
type="number"
name="BMI"
value={userInput.BMI}
onChange={handleChange}
className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline focus:ring-2 focus:ring-purple-500"
/>
</div>
<div className="mb-4">
<label
htmlFor="SkinThickness"
className="block text-gray-700 font-bold mb-2"
>
Skin Thickness
</label>
<input
type="number"
name="SkinThickness"
value={userInput.SkinThickness}
onChange={handleChange}
className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline focus:ring-2 focus:ring-purple-500"
/>
</div>
<div className="mb-4">
<label
htmlFor="DPF"
className="block text-gray-700 font-bold mb-2"
>
DPF
</label>
<input
type="number"
name="DPF"
value={userInput.DPF}
onChange={handleChange}
className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline focus:ring-2 focus:ring-purple-500"
/>
</div>
</div>
</div>
<div className="flex justify-center mt-6">
<button
type="submit"
className={`py-2 px-4 rounded focus:outline-none focus:shadow-outline transition-colors duration-300 ${
buttonDisabled
? "bg-gray-300 text-gray-500 cursor-not-allowed"
: "bg-purple-500 hover:bg-purple-700 text-white font-bold"
}`}
disabled={buttonDisabled}
>
Predict
</button>
</div>
</form>
</motion.div>
<motion.div
initial={{ opacity: 0, x: 150 }}
whileInView={{ opacity: 1, x: 0 }}
viewport={{ once: true }}
transition={{
duration: 1,
type: "spring",
stiffness: 100,
delay: 0.5,
}}
className="w-full sm:w-auto mx-auto mt-8 sm:mt-0 sm:ml-8"
>
{!prediction && (
<div className="bg-white p-6 rounded-lg shadow-lg mx-4 sm:mx-0 mt-4 sm:mt-0 w-full max-w-3xl">
<h2 className="text-2xl font-bold mb-4 text-purple-800 text-center">
About the Parameters
</h2>
<ul className="list-disc pl-5 space-y-2 text-gray-700">
<li><strong>Age:</strong> The age of the patient. Age is a risk factor because the likelihood of developing diabetes increases as you get older.</li>
<li><strong>Pregnancies:</strong> The number of times the patient has been pregnant. Pregnancy can affect insulin sensitivity, and a higher number of pregnancies might indicate a higher risk of developing diabetes.</li>
<li><strong>Glucose:</strong> Plasma glucose concentration after a 2-hour oral glucose tolerance test. High glucose levels are a primary indicator of diabetes.</li>
<li><strong>Blood Pressure:</strong> Diastolic blood pressure (mm Hg). High blood pressure is associated with an increased risk of diabetes and its complications.</li>
<li><strong>Insulin:</strong> 2-Hour serum insulin (mu U/ml). Abnormal insulin levels can be a sign of insulin resistance, a condition often associated with diabetes.</li>
<li><strong>BMI:</strong> Body Mass Index (weight in kg/(height in m)^2). Higher BMI values indicate obesity, which is a major risk factor for diabetes.</li>
<li><strong>Skin Thickness:</strong> Triceps skin fold thickness (mm). This measure can indicate body fat distribution, which is related to diabetes risk.</li>
<li><strong>DPF:</strong> Diabetes Pedigree Function. This function estimates the genetic impact on diabetes by considering family history, helping to understand hereditary risk.</li>
</ul>
</div>
)}
{prediction && (
<div className="bg-green-100 border mx-auto flex flex-col gap-5 border-green-400 text-green-700 py-2 rounded text-center max-w-3xl">
<img
src={prediction.gif_url}
alt="Prediction GIF"
className="mx-auto pt-4 rounded-md"
/>
<p className="font-bold text-2xl px-3 mx-2 ">
{prediction.prediction}
</p>
</div>
)}
</motion.div>
</div>
</div>
);
};
export default Prediction;