save code
This commit is contained in:
@@ -0,0 +1,183 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>人体换装工具</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
.input-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
}
|
||||
input[type="text"] {
|
||||
padding: 8px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
button {
|
||||
padding: 10px 15px;
|
||||
background-color: #4CAF50;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
position: relative;
|
||||
}
|
||||
button:hover {
|
||||
background-color: #45a049;
|
||||
}
|
||||
button:disabled {
|
||||
background-color: #cccccc;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.button-loading::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
margin: auto;
|
||||
border: 4px solid transparent;
|
||||
border-top-color: #ffffff;
|
||||
border-radius: 50%;
|
||||
animation: button-loading-spinner 1s ease infinite;
|
||||
}
|
||||
@keyframes button-loading-spinner {
|
||||
from {
|
||||
transform: rotate(0turn);
|
||||
}
|
||||
to {
|
||||
transform: rotate(1turn);
|
||||
}
|
||||
}
|
||||
.result {
|
||||
margin-top: 20px;
|
||||
padding: 15px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
display: none;
|
||||
}
|
||||
.result-image {
|
||||
max-width: 100%;
|
||||
margin-top: 10px;
|
||||
border: 1px solid #eee;
|
||||
}
|
||||
.error {
|
||||
color: red;
|
||||
margin-top: 10px;
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>人体换装工具</h1>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="human-url">人体图片URL:</label>
|
||||
<input type="text" id="human-url" value="http://112.126.94.241:18888/static/imgs/human_20250713_091718_fb1f8a05.jpg">
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="cloth-url">衣服图片URL:</label>
|
||||
<input type="text" id="cloth-url" value="http://112.126.94.241:18888/static/imgs/cloth_20250713_092536_279335d2.jpg">
|
||||
</div>
|
||||
|
||||
<button id="submit-btn">提交处理</button>
|
||||
|
||||
<div id="error-message" class="error"></div>
|
||||
|
||||
<div id="result" class="result">
|
||||
<h3>处理结果:</h3>
|
||||
<p>处理后的图片URL: <a id="result-url" href="" target="_blank"></a></p>
|
||||
<img id="result-image" class="result-image" src="" alt="处理后的图片">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('submit-btn').addEventListener('click', async function() {
|
||||
const humanUrl = document.getElementById('human-url').value;
|
||||
const clothUrl = document.getElementById('cloth-url').value;
|
||||
const submitBtn = document.getElementById('submit-btn');
|
||||
|
||||
// 隐藏之前的结果和错误
|
||||
document.getElementById('result').style.display = 'none';
|
||||
document.getElementById('error-message').style.display = 'none';
|
||||
|
||||
// 验证URL是否为空
|
||||
if (!humanUrl || !clothUrl) {
|
||||
showError('请输入人体图片和衣服图片的URL');
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置按钮为加载状态
|
||||
submitBtn.disabled = true;
|
||||
submitBtn.classList.add('button-loading');
|
||||
submitBtn.textContent = '处理中...';
|
||||
|
||||
try {
|
||||
// 发送POST请求
|
||||
const response = await fetch('http://112.126.94.241:18888/change_cloth', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
human_url: humanUrl,
|
||||
cloth_url: clothUrl,
|
||||
output_format: 'url'
|
||||
})
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data.ret === 0 && data.url) {
|
||||
// 显示处理结果
|
||||
const resultUrl = document.getElementById('result-url');
|
||||
const resultImage = document.getElementById('result-image');
|
||||
|
||||
resultUrl.href = data.url;
|
||||
resultUrl.textContent = data.url;
|
||||
resultImage.src = data.url;
|
||||
|
||||
document.getElementById('result').style.display = 'block';
|
||||
} else {
|
||||
showError('处理失败: ' + (data.message || '未知错误'));
|
||||
}
|
||||
} catch (error) {
|
||||
showError('请求出错: ' + error.message);
|
||||
} finally {
|
||||
// 恢复按钮状态
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.classList.remove('button-loading');
|
||||
submitBtn.textContent = '提交处理';
|
||||
}
|
||||
});
|
||||
|
||||
function showError(message) {
|
||||
const errorElement = document.getElementById('error-message');
|
||||
errorElement.textContent = message;
|
||||
errorElement.style.display = 'block';
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user