Add CardioAI project with three modules
- Module 1: Dashboard for cardiovascular disease data visualization - Module 2: Machine learning predictor with Flask API - Module 3: Voice assistant with DeepSeek and CosyVoice integration - Add .gitignore for proper file exclusion - Update requirements and documentation Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
889
aicodes/module2_predictor/templates/index.html
Normal file
889
aicodes/module2_predictor/templates/index.html
Normal file
@@ -0,0 +1,889 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>CardioAI - Cardiovascular Disease Risk Assessment</title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--primary-color: #2c3e50;
|
||||
--secondary-color: #3498db;
|
||||
--success-color: #27ae60;
|
||||
--warning-color: #f39c12;
|
||||
--danger-color: #e74c3c;
|
||||
--light-color: #ecf0f1;
|
||||
--dark-color: #2c3e50;
|
||||
--border-radius: 10px;
|
||||
--box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
|
||||
--transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Roboto', sans-serif;
|
||||
line-height: 1.6;
|
||||
color: #333;
|
||||
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.header {
|
||||
text-align: center;
|
||||
margin-bottom: 40px;
|
||||
padding: 30px;
|
||||
background: white;
|
||||
border-radius: var(--border-radius);
|
||||
box-shadow: var(--box-shadow);
|
||||
}
|
||||
|
||||
.logo {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.logo i {
|
||||
font-size: 48px;
|
||||
color: var(--danger-color);
|
||||
margin-right: 15px;
|
||||
}
|
||||
|
||||
.logo h1 {
|
||||
font-family: 'Poppins', sans-serif;
|
||||
font-size: 36px;
|
||||
color: var(--primary-color);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font-size: 18px;
|
||||
color: #666;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.content {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 30px;
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
|
||||
@media (max-width: 992px) {
|
||||
.content {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.card {
|
||||
background: white;
|
||||
border-radius: var(--border-radius);
|
||||
box-shadow: var(--box-shadow);
|
||||
padding: 30px;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.card:hover {
|
||||
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.card h2 {
|
||||
font-family: 'Poppins', sans-serif;
|
||||
font-size: 24px;
|
||||
color: var(--primary-color);
|
||||
margin-bottom: 20px;
|
||||
padding-bottom: 15px;
|
||||
border-bottom: 2px solid var(--light-color);
|
||||
}
|
||||
|
||||
.card h2 i {
|
||||
margin-right: 10px;
|
||||
color: var(--secondary-color);
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
font-weight: 500;
|
||||
color: var(--dark-color);
|
||||
}
|
||||
|
||||
.form-group input, .form-group select {
|
||||
width: 100%;
|
||||
padding: 12px 15px;
|
||||
border: 2px solid #ddd;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
transition: var(--transition);
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
.form-group input:focus, .form-group select:focus {
|
||||
border-color: var(--secondary-color);
|
||||
outline: none;
|
||||
background-color: white;
|
||||
box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
|
||||
}
|
||||
|
||||
.input-with-unit {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.input-with-unit input {
|
||||
padding-right: 50px;
|
||||
}
|
||||
|
||||
.unit {
|
||||
position: absolute;
|
||||
right: 15px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
color: #777;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.form-help {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
display: inline-block;
|
||||
padding: 14px 30px;
|
||||
background: var(--secondary-color);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: var(--transition);
|
||||
width: 100%;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
background: #2980b9;
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 5px 15px rgba(41, 128, 185, 0.3);
|
||||
}
|
||||
|
||||
.btn:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.btn i {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.result-container {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.result-card {
|
||||
text-align: center;
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
.risk-level {
|
||||
font-size: 32px;
|
||||
font-weight: 700;
|
||||
margin-bottom: 20px;
|
||||
padding: 15px;
|
||||
border-radius: var(--border-radius);
|
||||
}
|
||||
|
||||
.risk-low {
|
||||
background-color: rgba(39, 174, 96, 0.1);
|
||||
color: var(--success-color);
|
||||
border: 2px solid var(--success-color);
|
||||
}
|
||||
|
||||
.risk-medium {
|
||||
background-color: rgba(243, 156, 18, 0.1);
|
||||
color: var(--warning-color);
|
||||
border: 2px solid var(--warning-color);
|
||||
}
|
||||
|
||||
.risk-high {
|
||||
background-color: rgba(231, 76, 60, 0.1);
|
||||
color: var(--danger-color);
|
||||
border: 2px solid var(--danger-color);
|
||||
}
|
||||
|
||||
.probability-circle {
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
border-radius: 50%;
|
||||
margin: 0 auto 30px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
background: conic-gradient(
|
||||
var(--secondary-color) 0% var(--percentage),
|
||||
#f0f0f0 var(--percentage) 100%
|
||||
);
|
||||
}
|
||||
|
||||
.probability-circle::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
width: 160px;
|
||||
height: 160px;
|
||||
background: white;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.probability-value {
|
||||
font-size: 48px;
|
||||
font-weight: 700;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.probability-label {
|
||||
font-size: 18px;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.prediction-result {
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
margin: 20px 0;
|
||||
padding: 15px;
|
||||
border-radius: var(--border-radius);
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
.recommendation {
|
||||
background-color: #f0f8ff;
|
||||
padding: 20px;
|
||||
border-radius: var(--border-radius);
|
||||
margin-top: 20px;
|
||||
border-left: 4px solid var(--secondary-color);
|
||||
}
|
||||
|
||||
.recommendation h3 {
|
||||
color: var(--primary-color);
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.details {
|
||||
margin-top: 30px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.details h3 {
|
||||
color: var(--primary-color);
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.details-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.detail-item {
|
||||
background-color: #f8f9fa;
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.detail-label {
|
||||
font-weight: 600;
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.detail-value {
|
||||
font-weight: 700;
|
||||
color: var(--primary-color);
|
||||
font-size: 18px;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.loading {
|
||||
display: none;
|
||||
text-align: center;
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
border: 5px solid #f3f3f3;
|
||||
border-top: 5px solid var(--secondary-color);
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
margin: 0 auto 20px;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.error {
|
||||
display: none;
|
||||
background-color: rgba(231, 76, 60, 0.1);
|
||||
border: 1px solid var(--danger-color);
|
||||
color: var(--danger-color);
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.footer {
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
margin-top: 40px;
|
||||
border-top: 1px solid #eee;
|
||||
}
|
||||
|
||||
.info-box {
|
||||
background-color: #e8f4fc;
|
||||
border-left: 4px solid var(--secondary-color);
|
||||
padding: 15px;
|
||||
margin-bottom: 25px;
|
||||
border-radius: 0 8px 8px 0;
|
||||
}
|
||||
|
||||
.info-box p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.model-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 20px;
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
.status-indicator {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-radius: 50%;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.status-connected {
|
||||
background-color: var(--success-color);
|
||||
animation: pulse 2s infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0% { opacity: 1; }
|
||||
50% { opacity: 0.5; }
|
||||
100% { opacity: 1; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<header class="header">
|
||||
<div class="logo">
|
||||
<i class="fas fa-heartbeat"></i>
|
||||
<h1>CardioAI</h1>
|
||||
</div>
|
||||
<p class="subtitle">Cardiovascular Disease Risk Assessment System</p>
|
||||
<p>Enter your health information below to assess your risk of cardiovascular disease</p>
|
||||
</header>
|
||||
|
||||
<div class="model-status" id="modelStatus">
|
||||
<div class="status-indicator status-connected"></div>
|
||||
<span>Connected to CardioAI Prediction Engine</span>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<div class="card">
|
||||
<h2><i class="fas fa-user-circle"></i> Patient Information</h2>
|
||||
|
||||
<div class="info-box">
|
||||
<p><i class="fas fa-info-circle"></i> Please provide accurate health information for the most reliable risk assessment.</p>
|
||||
</div>
|
||||
|
||||
<form id="predictionForm">
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="age_years"><i class="fas fa-birthday-cake"></i> Age (years)</label>
|
||||
<div class="input-with-unit">
|
||||
<input type="number" id="age_years" name="age_years" min="20" max="100" step="1" value="45" required>
|
||||
<span class="unit">years</span>
|
||||
</div>
|
||||
<div class="form-help">Enter age between 20-100 years</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="gender"><i class="fas fa-venus-mars"></i> Gender</label>
|
||||
<select id="gender" name="gender" required>
|
||||
<option value="1">Female</option>
|
||||
<option value="2" selected>Male</option>
|
||||
</select>
|
||||
<div class="form-help">1: Female, 2: Male</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="height"><i class="fas fa-arrows-alt-v"></i> Height</label>
|
||||
<div class="input-with-unit">
|
||||
<input type="number" id="height" name="height" min="100" max="250" step="0.1" value="170" required>
|
||||
<span class="unit">cm</span>
|
||||
</div>
|
||||
<div class="form-help">Height in centimeters (100-250 cm)</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="weight"><i class="fas fa-weight"></i> Weight</label>
|
||||
<div class="input-with-unit">
|
||||
<input type="number" id="weight" name="weight" min="30" max="200" step="0.1" value="70" required>
|
||||
<span class="unit">kg</span>
|
||||
</div>
|
||||
<div class="form-help">Weight in kilograms (30-200 kg)</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="ap_hi"><i class="fas fa-heart"></i> Systolic BP</label>
|
||||
<div class="input-with-unit">
|
||||
<input type="number" id="ap_hi" name="ap_hi" min="90" max="250" step="1" value="120" required>
|
||||
<span class="unit">mmHg</span>
|
||||
</div>
|
||||
<div class="form-help">Systolic blood pressure (90-250 mmHg)</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="ap_lo"><i class="fas fa-heartbeat"></i> Diastolic BP</label>
|
||||
<div class="input-with-unit">
|
||||
<input type="number" id="ap_lo" name="ap_lo" min="60" max="150" step="1" value="80" required>
|
||||
<span class="unit">mmHg</span>
|
||||
</div>
|
||||
<div class="form-help">Diastolic blood pressure (60-150 mmHg)</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="cholesterol"><i class="fas fa-vial"></i> Cholesterol</label>
|
||||
<select id="cholesterol" name="cholesterol" required>
|
||||
<option value="1">Normal</option>
|
||||
<option value="2" selected>Above Normal</option>
|
||||
<option value="3">Well Above Normal</option>
|
||||
</select>
|
||||
<div class="form-help">1: Normal, 2: Above Normal, 3: Well Above Normal</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="gluc"><i class="fas fa-tint"></i> Glucose</label>
|
||||
<select id="gluc" name="gluc" required>
|
||||
<option value="1">Normal</option>
|
||||
<option value="2" selected>Above Normal</option>
|
||||
<option value="3">Well Above Normal</option>
|
||||
</select>
|
||||
<div class="form-help">1: Normal, 2: Above Normal, 3: Well Above Normal</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="smoke"><i class="fas fa-smoking"></i> Smoking</label>
|
||||
<select id="smoke" name="smoke" required>
|
||||
<option value="0" selected>No</option>
|
||||
<option value="1">Yes</option>
|
||||
</select>
|
||||
<div class="form-help">0: No, 1: Yes</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="alco"><i class="fas fa-wine-glass-alt"></i> Alcohol</label>
|
||||
<select id="alco" name="alco" required>
|
||||
<option value="0" selected>No</option>
|
||||
<option value="1">Yes</option>
|
||||
</select>
|
||||
<div class="form-help">0: No, 1: Yes</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="active"><i class="fas fa-running"></i> Physical Activity</label>
|
||||
<select id="active" name="active" required>
|
||||
<option value="0">No</option>
|
||||
<option value="1" selected>Yes</option>
|
||||
</select>
|
||||
<div class="form-help">0: No, 1: Yes</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn" id="predictBtn">
|
||||
<i class="fas fa-brain"></i> Assess Cardiovascular Risk
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div class="loading" id="loading">
|
||||
<div class="loading-spinner"></div>
|
||||
<p>Analyzing health data and calculating risk...</p>
|
||||
</div>
|
||||
|
||||
<div class="error" id="errorMessage"></div>
|
||||
</div>
|
||||
|
||||
<div class="card result-container" id="resultContainer">
|
||||
<h2><i class="fas fa-chart-line"></i> Risk Assessment Results</h2>
|
||||
|
||||
<div class="result-card">
|
||||
<div class="prediction-result" id="predictionResult">
|
||||
<!-- Prediction result will be shown here -->
|
||||
</div>
|
||||
|
||||
<div class="risk-level" id="riskLevel">
|
||||
<!-- Risk level will be shown here -->
|
||||
</div>
|
||||
|
||||
<div class="probability-circle" id="probabilityCircle">
|
||||
<div class="probability-value" id="probabilityValue">0%</div>
|
||||
<div class="probability-label">Risk Probability</div>
|
||||
</div>
|
||||
|
||||
<div class="recommendation" id="recommendation">
|
||||
<!-- Recommendation will be shown here -->
|
||||
</div>
|
||||
|
||||
<div class="details">
|
||||
<h3><i class="fas fa-info-circle"></i> Input Summary</h3>
|
||||
<div class="details-grid" id="inputSummary">
|
||||
<!-- Input summary will be shown here -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button class="btn" id="newAssessmentBtn" style="margin-top: 30px; background-color: var(--primary-color);">
|
||||
<i class="fas fa-redo"></i> New Assessment
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
<p><i class="fas fa-shield-alt"></i> CardioAI - Cardiovascular Disease Intelligent Assistant System</p>
|
||||
<p>This tool provides a risk assessment based on machine learning models and should not replace professional medical advice.</p>
|
||||
<p>© 2026 CardioAI. All rights reserved.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// DOM Elements
|
||||
const predictionForm = document.getElementById('predictionForm');
|
||||
const resultContainer = document.getElementById('resultContainer');
|
||||
const loadingElement = document.getElementById('loading');
|
||||
const errorElement = document.getElementById('errorMessage');
|
||||
const probabilityCircle = document.getElementById('probabilityCircle');
|
||||
const probabilityValue = document.getElementById('probabilityValue');
|
||||
const riskLevel = document.getElementById('riskLevel');
|
||||
const predictionResult = document.getElementById('predictionResult');
|
||||
const recommendation = document.getElementById('recommendation');
|
||||
const inputSummary = document.getElementById('inputSummary');
|
||||
const newAssessmentBtn = document.getElementById('newAssessmentBtn');
|
||||
const predictBtn = document.getElementById('predictBtn');
|
||||
|
||||
// Model status check
|
||||
async function checkModelStatus() {
|
||||
try {
|
||||
const response = await fetch('/api/model_info');
|
||||
if (response.ok) {
|
||||
console.log('✅ Model is ready');
|
||||
return true;
|
||||
} else {
|
||||
console.warn('⚠️ Model may not be loaded');
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ Error checking model status:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Format feature values for display
|
||||
function formatFeatureValue(feature, value) {
|
||||
const featureLabels = {
|
||||
'age_years': 'Age',
|
||||
'gender': 'Gender',
|
||||
'height': 'Height',
|
||||
'weight': 'Weight',
|
||||
'ap_hi': 'Systolic BP',
|
||||
'ap_lo': 'Diastolic BP',
|
||||
'cholesterol': 'Cholesterol',
|
||||
'gluc': 'Glucose',
|
||||
'smoke': 'Smoking',
|
||||
'alco': 'Alcohol',
|
||||
'active': 'Physical Activity'
|
||||
};
|
||||
|
||||
const valueLabels = {
|
||||
'gender': { '1': 'Female', '2': 'Male' },
|
||||
'cholesterol': { '1': 'Normal', '2': 'Above Normal', '3': 'Well Above Normal' },
|
||||
'gluc': { '1': 'Normal', '2': 'Above Normal', '3': 'Well Above Normal' },
|
||||
'smoke': { '0': 'No', '1': 'Yes' },
|
||||
'alco': { '0': 'No', '1': 'Yes' },
|
||||
'active': { '0': 'No', '1': 'Yes' }
|
||||
};
|
||||
|
||||
const label = featureLabels[feature] || feature;
|
||||
let displayValue = value;
|
||||
|
||||
if (feature in valueLabels) {
|
||||
displayValue = valueLabels[feature][value] || value;
|
||||
} else if (feature === 'height') {
|
||||
displayValue = `${value} cm`;
|
||||
} else if (feature === 'weight') {
|
||||
displayValue = `${value} kg`;
|
||||
} else if (feature === 'ap_hi' || feature === 'ap_lo') {
|
||||
displayValue = `${value} mmHg`;
|
||||
} else if (feature === 'age_years') {
|
||||
displayValue = `${value} years`;
|
||||
}
|
||||
|
||||
return { label, value: displayValue };
|
||||
}
|
||||
|
||||
// Show loading state
|
||||
function showLoading() {
|
||||
loadingElement.style.display = 'block';
|
||||
predictBtn.disabled = true;
|
||||
predictBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Processing...';
|
||||
errorElement.style.display = 'none';
|
||||
}
|
||||
|
||||
// Hide loading state
|
||||
function hideLoading() {
|
||||
loadingElement.style.display = 'none';
|
||||
predictBtn.disabled = false;
|
||||
predictBtn.innerHTML = '<i class="fas fa-brain"></i> Assess Cardiovascular Risk';
|
||||
}
|
||||
|
||||
// Show error message
|
||||
function showError(message) {
|
||||
errorElement.textContent = message;
|
||||
errorElement.style.display = 'block';
|
||||
hideLoading();
|
||||
}
|
||||
|
||||
// Display results
|
||||
function displayResults(data) {
|
||||
// Update probability circle
|
||||
const percentage = (data.probability * 100).toFixed(1);
|
||||
probabilityCircle.style.setProperty('--percentage', `${percentage}%`);
|
||||
probabilityValue.textContent = `${percentage}%`;
|
||||
|
||||
// Update risk level
|
||||
let riskClass = '';
|
||||
let riskText = '';
|
||||
|
||||
if (data.risk_level === 'Low') {
|
||||
riskClass = 'risk-low';
|
||||
riskText = 'Low Risk';
|
||||
} else if (data.risk_level === 'Medium') {
|
||||
riskClass = 'risk-medium';
|
||||
riskText = 'Medium Risk';
|
||||
} else {
|
||||
riskClass = 'risk-high';
|
||||
riskText = 'High Risk';
|
||||
}
|
||||
|
||||
riskLevel.className = `risk-level ${riskClass}`;
|
||||
riskLevel.innerHTML = `<i class="fas fa-exclamation-circle"></i> ${riskText}`;
|
||||
|
||||
// Update prediction result
|
||||
if (data.prediction === 1) {
|
||||
predictionResult.innerHTML = `
|
||||
<i class="fas fa-exclamation-triangle"></i>
|
||||
<span style="color: ${data.risk_level === 'High' ? '#e74c3c' : '#f39c12'}">
|
||||
Cardiovascular Disease Risk Detected
|
||||
</span>
|
||||
`;
|
||||
} else {
|
||||
predictionResult.innerHTML = `
|
||||
<i class="fas fa-check-circle"></i>
|
||||
<span style="color: #27ae60">
|
||||
No Significant Cardiovascular Disease Risk Detected
|
||||
</span>
|
||||
`;
|
||||
}
|
||||
|
||||
// Update recommendation
|
||||
recommendation.innerHTML = `
|
||||
<h3><i class="fas fa-stethoscope"></i> Recommendation</h3>
|
||||
<p>${data.recommendation}</p>
|
||||
<p style="margin-top: 10px; font-size: 14px; color: #666;">
|
||||
<i class="fas fa-lightbulb"></i> Probability of cardiovascular disease: ${percentage}%
|
||||
</p>
|
||||
`;
|
||||
|
||||
// Update input summary
|
||||
let summaryHTML = '';
|
||||
for (const [feature, value] of Object.entries(data.input_features)) {
|
||||
const formatted = formatFeatureValue(feature, value);
|
||||
summaryHTML += `
|
||||
<div class="detail-item">
|
||||
<div class="detail-label">${formatted.label}</div>
|
||||
<div class="detail-value">${formatted.value}</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
inputSummary.innerHTML = summaryHTML;
|
||||
|
||||
// Show result container
|
||||
resultContainer.style.display = 'block';
|
||||
|
||||
// Scroll to results
|
||||
resultContainer.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
||||
}
|
||||
|
||||
// Form submission handler
|
||||
predictionForm.addEventListener('submit', async function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
// Validate form
|
||||
if (!predictionForm.checkValidity()) {
|
||||
predictionForm.reportValidity();
|
||||
return;
|
||||
}
|
||||
|
||||
// Collect form data
|
||||
const formData = new FormData(predictionForm);
|
||||
const data = Object.fromEntries(formData.entries());
|
||||
|
||||
// Convert numeric values
|
||||
const numericFields = ['age_years', 'height', 'weight', 'ap_hi', 'ap_lo',
|
||||
'cholesterol', 'gluc', 'smoke', 'alco', 'active', 'gender'];
|
||||
numericFields.forEach(field => {
|
||||
if (data[field] !== undefined) {
|
||||
data[field] = parseFloat(data[field]);
|
||||
}
|
||||
});
|
||||
|
||||
showLoading();
|
||||
|
||||
try {
|
||||
// Send prediction request
|
||||
const response = await fetch('/predict_cardio', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (response.ok && result.status === 'success') {
|
||||
displayResults(result);
|
||||
} else {
|
||||
showError(result.message || 'Error making prediction');
|
||||
}
|
||||
} catch (error) {
|
||||
showError(`Network error: ${error.message}. Please check if the server is running.`);
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
});
|
||||
|
||||
// New assessment button
|
||||
newAssessmentBtn.addEventListener('click', function() {
|
||||
resultContainer.style.display = 'none';
|
||||
predictionForm.reset();
|
||||
|
||||
// Scroll back to form
|
||||
predictionForm.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
||||
});
|
||||
|
||||
// Initialize with example data and check model status
|
||||
document.addEventListener('DOMContentLoaded', async function() {
|
||||
console.log('🚀 CardioAI Web Interface Initialized');
|
||||
|
||||
// Check model status
|
||||
const modelReady = await checkModelStatus();
|
||||
if (!modelReady) {
|
||||
console.warn('Model may not be ready. Please ensure the training script has been run.');
|
||||
}
|
||||
|
||||
// Set up example data button (optional)
|
||||
const exampleBtn = document.createElement('button');
|
||||
exampleBtn.type = 'button';
|
||||
exampleBtn.className = 'btn';
|
||||
exampleBtn.style.backgroundColor = 'var(--warning-color)';
|
||||
exampleBtn.style.marginTop = '10px';
|
||||
exampleBtn.innerHTML = '<i class="fas fa-vial"></i> Load Example Data';
|
||||
exampleBtn.onclick = function() {
|
||||
document.getElementById('age_years').value = 55;
|
||||
document.getElementById('gender').value = 2;
|
||||
document.getElementById('height').value = 175.5;
|
||||
document.getElementById('weight').value = 85.2;
|
||||
document.getElementById('ap_hi').value = 140;
|
||||
document.getElementById('ap_lo').value = 90;
|
||||
document.getElementById('cholesterol').value = 3;
|
||||
document.getElementById('gluc').value = 2;
|
||||
document.getElementById('smoke').value = 1;
|
||||
document.getElementById('alco').value = 1;
|
||||
document.getElementById('active').value = 0;
|
||||
};
|
||||
|
||||
predictionForm.appendChild(exampleBtn);
|
||||
});
|
||||
|
||||
// Input validation helper
|
||||
function setupInputValidation() {
|
||||
const inputs = document.querySelectorAll('input[type="number"]');
|
||||
inputs.forEach(input => {
|
||||
input.addEventListener('input', function() {
|
||||
const min = parseFloat(this.min);
|
||||
const max = parseFloat(this.max);
|
||||
const value = parseFloat(this.value);
|
||||
|
||||
if (!isNaN(min) && !isNaN(max) && !isNaN(value)) {
|
||||
if (value < min) this.value = min;
|
||||
if (value > max) this.value = max;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Initialize input validation
|
||||
setupInputValidation();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user