SkinVL / templates /index.html
leonsimon23's picture
Update templates/index.html
562efa6 verified
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>皮肤医生临床诊疗辅助系统</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lucide/0.263.1/lucide.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #00bcd4, #8bc34a);
color: white;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.container {
background: rgba(255, 255, 255, 0.2);
padding: 30px;
border-radius: 15px;
max-width: 600px;
width: 100%;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
font-size: 2.5rem;
margin-bottom: 20px;
}
.form-group {
margin-bottom: 15px;
}
input[type="file"], textarea {
width: 100%;
padding: 10px;
border-radius: 5px;
border: 1px solid #ddd;
}
textarea {
resize: vertical;
height: 100px;
}
button {
width: 100%;
padding: 12px;
background-color: #4CAF50;
border: none;
border-radius: 5px;
color: white;
font-size: 1.2rem;
cursor: pointer;
transition: background-color 0.3s;
}
button:disabled {
background-color: #9e9e9e;
}
button:hover {
background-color: #45a049;
}
.results {
margin-top: 20px;
padding: 15px;
border-radius: 5px;
background-color: rgba(255, 255, 255, 0.2);
}
.error-message {
color: red;
}
.success-message {
color: green;
}
.loading {
display: none;
text-align: center;
font-size: 1.2rem;
}
</style>
</head>
<body>
<div class="container">
<h1>皮肤病诊断助手</h1>
<form id="uploadForm">
<div class="form-group">
<label for="textInput">症状描述</label>
<textarea id="textInput" placeholder="请输入您的症状描述(可选)"></textarea>
</div>
<div class="form-group">
<label for="imageInput">上传皮肤病变图像(可选)</label>
<input type="file" id="imageInput" accept="image/*">
</div>
<div class="form-group">
<button type="submit" id="submitBtn">提交分析</button>
</div>
</form>
<div id="loadingIndicator" class="loading">
<div class="spinner"></div>
<p>正在分析,请稍等...</p>
</div>
<div id="results" class="results"></div>
</div>
<script>
const form = document.getElementById('uploadForm');
const textInput = document.getElementById('textInput');
const imageInput = document.getElementById('imageInput');
const submitBtn = document.getElementById('submitBtn');
const results = document.getElementById('results');
const loadingIndicator = document.getElementById('loadingIndicator');
form.addEventListener('submit', async (e) => {
e.preventDefault();
const text = textInput.value.trim();
const imageFile = imageInput.files[0];
if (!text && !imageFile) {
alert("请至少提供症状描述或上传图像!");
return;
}
if (imageFile && imageFile.size > 10 * 1024 * 1024) {
alert("文件过大,请确保文件小于10MB");
return;
}
submitBtn.disabled = true; // 禁用按钮避免重复提交
loadingIndicator.style.display = 'block'; // 显示加载动画
const formData = new FormData();
formData.append('text', text);
if (imageFile) {
formData.append('image', imageFile);
}
try {
const response = await fetch('/analyze', {
method: 'POST',
body: formData,
});
const result = await response.json();
if (result.error) {
results.innerHTML = `<div class="error-message">${result.error}</div>`;
} else {
results.innerHTML = `<div class="success-message">${result.result}</div>`;
}
} catch (error) {
results.innerHTML = `<div class="error-message">网络请求失败,请稍后重试。</div>`;
} finally {
submitBtn.disabled = false; // 重新启用按钮
loadingIndicator.style.display = 'none'; // 隐藏加载动画
}
});
</script>
</body>
</html>