generated from nighthawkcoders/Nighthawk-Pages
-
Notifications
You must be signed in to change notification settings - Fork 2
/
heart_attack.html
175 lines (170 loc) · 5.38 KB
/
heart_attack.html
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
---
layout: base
title: Heart Attack
permalink: /heartattack
---
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Heart Attack Prediction</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-image: url("enter");
background-position: 50% 0;
background-size: cover;
background-attachment: fixed;
background-repeat: no-repeat;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
color: #3F51B5;
font-size: 36px;
margin-bottom: 20px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}
form {
max-width: 600px;
margin: 0 auto;
}
p {
color: #555;
font-size: 16px;
line-height: 1.5;
}
label {
font-weight: bold;
display: block;
margin-bottom: 5px;
color: #333;
}
input,
select {
width: calc(100% - 22px);
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
font-size: 16px;
}
button {
background-color: #3F51B5;
color: #fff;
border: none;
border-radius: 5px;
padding: 12px 24px;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #303F9F;
}
#result {
margin-top: 20px;
}
#result p {
color: #333;
font-size: 16px;
}
/* Style for home button */
#homeButton {
position: fixed;
top: 20px;
left: 20px;
font-size: 16px;
text-decoration: none;
color: #333;
padding: 5px 10px;
border: 1px solid #ccc;
border-radius: 4px;
background-color: #f2f2f2;
}
</style>
<!-- Home button linking to index.html -->
<a id="homeButton" href="index">Home</a>
<div class="container">
<h1>Heart Attack Prediction</h1>
<form id="heartForm">
<p><strong>Important Note: </strong> Some aspects of these predictions may not be accurate due to limitations in the dataset.</p>
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>
<label for="sex">Gender:</label>
<select id="sex" name="sex" required>
<option value="Male">Male</option>
<option value="Female">Female</option>
<option value="Other">Other</option>
</select><br><br>
<label for="age">Age:</label>
<input type="number" id="age" name="age" required><br><br>
<label for="cp">Chest Pain Level:</label>
<input type="number" id="cp" name="cp" required><br><br>
<label for="trtbps">Resting Blood Pressure (Max value 200 mm/Hg)</label>
<input type="number" id="trtbps" name="trtbps" required><br><br>
<label for="chol"> Cholesterol:</label>
<input type="number" id="chol" name="chol" required><br><br>
<label for="exng">Exercise Induced Angina:</label>
<select id="exng" name="exng">
<option value="0">No Exercise Induced Angina</option>
<option value="1">Yes Exercise Induced Angina</option>
</select><br><br>
<button type="button" onclick="predictHeart()">Predict Probability of Heart Attack</button>
</form>
<div id="result"></div>
</div>
<script>
function predictHeart() {
var form = document.getElementById('heartForm');
var name = document.getElementById('name');
var resultDiv = document.getElementById('result');
// Check if any required fields are empty
var requiredFields = form.querySelectorAll('input[required], select[required]');
var isEmpty = Array.from(requiredFields).some(field => !field.value.trim());
if (isEmpty) {
resultDiv.innerHTML = '<p>Please fill out all required fields.</p>';
return;
}
var formData = {
sex: form['sex'].value,
age: form['age'].value,
cp: form['cp'].value,
trtbps: form['trtbps'].value,
chol: form['chol'].value,
exng: form['exng'].value
};
fetch('http://localhost:8086/api/heart/predict', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify(formData)
})
.then(response => response.json())
.then(data => {
resultDiv.innerHTML = '<h2>Prediction Result for ' + name.value + '</h2>';
for (var key in data) {
resultDiv.innerHTML += '<p>' + key + ': ' + data[key] + '</p>';
}
var heartProbability = parseFloat(data['heart_prob']);
if (data[key] > 30) {
resultDiv.innerHTML += '<p>💀 You are in danger.... 💀 RUN GO GET HELP !! </p>';
} else {
resultDiv.innerHTML += '<p> 🥳🥳🥳🥳 YOURE HEALTHY YAYAYYA 🥳🥳🥳🥳🥳 </p>';
}
})
.catch(error => {
console.error('Error:', error);
});
}
</script>