File size: 8,577 Bytes
c9cd3bc |
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 |
<!DOCTYPE html>
<html>
<head>
<title>Mental Health Prediction</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: linear-gradient(to right, #36d1dc, #5b86e5);
animation: fadeIn 1s ease-in-out;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.container {
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
text-align: center;
width: 400px;
animation: slideUp 0.8s ease-in-out;
}
@keyframes slideUp {
from { transform: translateY(30px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
h2 {
color: #333;
}
label {
display: block;
text-align: left;
margin: 5px 0 2px;
color: #555;
}
input, select, button {
width: 100%;
padding: 10px;
margin: 5px 0 10px;
border: 1px solid #ccc;
border-radius: 5px;
transition: 0.3s;
box-sizing: border-box;
}
input:focus, select:focus {
border-color: #5b86e5;
box-shadow: 0 0 8px rgba(91, 134, 229, 0.6);
}
button {
background: #007bff;
color: white;
cursor: pointer;
border: none;
font-weight: bold;
transition: 0.3s;
}
button:hover {
background: #0056b3;
transform: scale(1.05);
}
#result, #probabilities, #disclaimer, #model-accuracy {
margin-top: 10px;
color: #333;
}
#result {
font-weight: bold;
color: #007bff;
}
#probabilities table {
width: 100%;
margin-top: 10px;
border-collapse: collapse;
}
#probabilities th, #probabilities td {
padding: 5px;
border: 1px solid #ccc;
text-align: center;
}
#probabilities th {
background: #f0f0f0;
}
#disclaimer {
font-style: italic;
color: #e74c3c;
}
#model-accuracy {
font-size: 0.9em;
color: #555;
}
</style>
<script>
function predictMentalHealth() {
// Collect form data
const form = document.getElementById('predictionForm');
const formData = new FormData(form);
// Convert form data to JSON
const data = {
Sentiment_Score: parseFloat(formData.get('Sentiment_Score')),
HRV: parseFloat(formData.get('HRV')),
Sleep_Hours: parseFloat(formData.get('Sleep_Hours')),
Activity: parseInt(formData.get('Activity')),
Age: parseInt(formData.get('Age')),
Gender: formData.get('Gender'),
Work_Study_Hours: parseFloat(formData.get('Work_Study_Hours'))
};
// Validate input
if (isNaN(data.Sentiment_Score) || data.Sentiment_Score < 0 || data.Sentiment_Score > 1) {
document.getElementById('result').innerText = 'Error: Sentiment Score must be between 0 and 1';
return;
}
if (isNaN(data.HRV) || data.HRV < 0) {
document.getElementById('result').innerText = 'Error: HRV cannot be negative';
return;
}
if (isNaN(data.Sleep_Hours) || data.Sleep_Hours < 0) {
document.getElementById('result').innerText = 'Error: Sleep Hours cannot be negative';
return;
}
if (isNaN(data.Activity) || data.Activity < 0) {
document.getElementById('result').innerText = 'Error: Activity cannot be negative';
return;
}
if (isNaN(data.Age) || data.Age < 0) {
document.getElementById('result').innerText = 'Error: Age cannot be negative';
return;
}
if (isNaN(data.Work_Study_Hours) || data.Work_Study_Hours < 0) {
document.getElementById('result').innerText = 'Error: Work/Study Hours cannot be negative';
return;
}
// Send request to the Flask API
fetch('/predict', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => {
if (data.prediction) {
// Display prediction
document.getElementById('result').innerText = 'Prediction: ' + data.prediction;
// Display probabilities in a table
const probsTable = document.getElementById('probabilities-table');
probsTable.innerHTML = '';
for (const [status, prob] of Object.entries(data.probabilities)) {
const row = probsTable.insertRow();
row.insertCell(0).innerText = status;
row.insertCell(1).innerText = (prob * 100).toFixed(2) + '%';
}
// Display disclaimer and model accuracy
document.getElementById('disclaimer').innerText = data.disclaimer || '';
document.getElementById('model-accuracy').innerText = data.model_accuracy;
} else {
document.getElementById('result').innerText = 'Error: ' + data.error;
document.getElementById('probabilities-table').innerHTML = '';
document.getElementById('disclaimer').innerText = '';
document.getElementById('model-accuracy').innerText = '';
}
})
.catch(error => {
document.getElementById('result').innerText = 'Request failed';
document.getElementById('probabilities-table').innerHTML = '';
document.getElementById('disclaimer').innerText = '';
document.getElementById('model-accuracy').innerText = '';
console.error('Error:', error);
});
}
</script>
</head>
<body>
<div class="container">
<h2>Mental Health Prediction</h2>
<form id="predictionForm" onsubmit="event.preventDefault(); predictMentalHealth();">
<label>Sentiment Score (0 to 1):</label>
<input type="number" step="0.01" name="Sentiment_Score" required>
<label>HRV (Heart Rate Variability):</label>
<input type="number" step="0.01" name="HRV" required>
<label>Sleep Hours:</label>
<input type="number" step="0.1" name="Sleep_Hours" required>
<label>Activity (Steps/Day):</label>
<input type="number" name="Activity" required>
<label>Age:</label>
<input type="number" name="Age" required>
<label>Gender:</label>
<select name="Gender" required>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
<label>Work/Study Hours:</label>
<input type="number" step="0.1" name="Work_Study_Hours" required>
<button type="submit">Predict</button>
</form>
<h3 id="result"></h3>
<div id="probabilities">
<table id="probabilities-table">
<tr><th>Status</th><th>Probability</th></tr>
</table>
</div>
<div id="disclaimer"></div>
<div id="model-accuracy"></div>
</div>
</body>
</html> |