'commit'
This commit is contained in:
BIN
dsLightRag/JiMeng/Kit/__pycache__/JmTxt2ImgUtil.cpython-310.pyc
Normal file
BIN
dsLightRag/JiMeng/Kit/__pycache__/JmTxt2ImgUtil.cpython-310.pyc
Normal file
Binary file not shown.
@@ -41,6 +41,9 @@ async def prompt_input(request: fastapi.Request):
|
|||||||
"image_url": image_url
|
"image_url": image_url
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
except HTTPException as e:
|
||||||
|
logger.error(f"请求参数错误: {str(e.detail)}")
|
||||||
|
raise e
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"图片生成失败: {str(e)}")
|
logger.error(f"图片生成失败: {str(e)}")
|
||||||
raise HTTPException(status_code=500, detail=f"图片生成失败: {str(e)}")
|
raise HTTPException(status_code=500, detail=f"图片生成失败: {str(e)}")
|
||||||
|
BIN
dsLightRag/Routes/__pycache__/JiMengRoute.cpython-310.pyc
Normal file
BIN
dsLightRag/Routes/__pycache__/JiMengRoute.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
243
dsLightRag/static/JiMeng/image_preview.html
Normal file
243
dsLightRag/static/JiMeng/image_preview.html
Normal file
@@ -0,0 +1,243 @@
|
|||||||
|
<!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>
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
background-color: #f5f7fa;
|
||||||
|
color: #333;
|
||||||
|
line-height: 1.6;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
max-width: 900px;
|
||||||
|
margin: 0 auto;
|
||||||
|
background: white;
|
||||||
|
border-radius: 10px;
|
||||||
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
||||||
|
padding: 30px;
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
color: #2c3e50;
|
||||||
|
}
|
||||||
|
.image-container {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
margin: 30px 0;
|
||||||
|
min-height: 400px;
|
||||||
|
align-items: center;
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
#previewImage {
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 600px;
|
||||||
|
border-radius: 6px;
|
||||||
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
||||||
|
}
|
||||||
|
.loading {
|
||||||
|
text-align: center;
|
||||||
|
font-size: 18px;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
.btn-group {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
margin-top: 30px;
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
.btn {
|
||||||
|
padding: 12px 25px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 6px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 16px;
|
||||||
|
transition: background 0.3s;
|
||||||
|
}
|
||||||
|
.btn-primary {
|
||||||
|
background-color: #3498db;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
.btn-primary:hover {
|
||||||
|
background-color: #2980b9;
|
||||||
|
}
|
||||||
|
.btn-secondary {
|
||||||
|
background-color: #95a5a6;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
.btn-secondary:hover {
|
||||||
|
background-color: #7f8c8d;
|
||||||
|
}
|
||||||
|
.btn-danger {
|
||||||
|
background-color: #e74c3c;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
.btn-danger:hover {
|
||||||
|
background-color: #c0392b;
|
||||||
|
}
|
||||||
|
/* 添加遮罩动画样式 */
|
||||||
|
.mask {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background-color: rgba(0, 0, 0, 0.7);
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
z-index: 1000;
|
||||||
|
opacity: 0;
|
||||||
|
visibility: hidden;
|
||||||
|
transition: opacity 0.3s, visibility 0.3s;
|
||||||
|
}
|
||||||
|
.mask.active {
|
||||||
|
opacity: 1;
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
|
.loader {
|
||||||
|
width: 50px;
|
||||||
|
height: 50px;
|
||||||
|
border: 5px solid rgba(255, 255, 255, 0.3);
|
||||||
|
border-radius: 50%;
|
||||||
|
border-top-color: #3498db;
|
||||||
|
animation: spin 1s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
@keyframes spin {
|
||||||
|
to { transform: rotate(360deg); }
|
||||||
|
}
|
||||||
|
.mask-text {
|
||||||
|
color: white;
|
||||||
|
margin-top: 20px;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
.mask-content {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>首帧预览</h1>
|
||||||
|
<div class="image-container">
|
||||||
|
<div class="loading" id="loading">加载中...</div>
|
||||||
|
<img id="previewImage" style="display: none;">
|
||||||
|
</div>
|
||||||
|
<div class="btn-group">
|
||||||
|
<button class="btn btn-danger" id="backBtn">返回修改</button>
|
||||||
|
<button class="btn btn-secondary" id="regenerateBtn">重新生成</button>
|
||||||
|
<button class="btn btn-primary" id="confirmBtn">确认满意</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 添加遮罩层 -->
|
||||||
|
<div class="mask" id="mask">
|
||||||
|
<div class="mask-content">
|
||||||
|
<div class="loader"></div>
|
||||||
|
<div class="mask-text" id="maskText">正在生成图片,请稍候...</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
const imageUrl = sessionStorage.getItem('generatedImageUrl');
|
||||||
|
const prompt = sessionStorage.getItem('lastPrompt');
|
||||||
|
const previewImage = document.getElementById('previewImage');
|
||||||
|
const loading = document.getElementById('loading');
|
||||||
|
const backBtn = document.getElementById('backBtn');
|
||||||
|
const regenerateBtn = document.getElementById('regenerateBtn');
|
||||||
|
const confirmBtn = document.getElementById('confirmBtn');
|
||||||
|
const mask = document.getElementById('mask');
|
||||||
|
const maskText = document.getElementById('maskText');
|
||||||
|
|
||||||
|
if (!imageUrl) {
|
||||||
|
alert('没有找到生成的图片,请返回重新生成');
|
||||||
|
window.location.href = 'prompt_input.html';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载图片
|
||||||
|
previewImage.onload = function() {
|
||||||
|
loading.style.display = 'none';
|
||||||
|
previewImage.style.display = 'block';
|
||||||
|
};
|
||||||
|
previewImage.onerror = function() {
|
||||||
|
loading.textContent = '图片加载失败';
|
||||||
|
};
|
||||||
|
previewImage.src = imageUrl;
|
||||||
|
|
||||||
|
// 返回修改按钮
|
||||||
|
backBtn.addEventListener('click', function() {
|
||||||
|
window.location.href = 'prompt_input.html';
|
||||||
|
});
|
||||||
|
|
||||||
|
// 重新生成按钮
|
||||||
|
regenerateBtn.addEventListener('click', function() {
|
||||||
|
// 显示遮罩动画
|
||||||
|
mask.classList.add('active');
|
||||||
|
maskText.textContent = '正在重新生成图片,请稍候...';
|
||||||
|
|
||||||
|
// 调用 API 重新生成图片
|
||||||
|
fetch('/api/jimeng/prompt_input', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ prompt: prompt })
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('网络响应异常');
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
// 隐藏遮罩动画
|
||||||
|
mask.classList.remove('active');
|
||||||
|
|
||||||
|
if (data.code === 200) {
|
||||||
|
// 更新图片 URL
|
||||||
|
const newImageUrl = data.data.image_url;
|
||||||
|
sessionStorage.setItem('generatedImageUrl', newImageUrl);
|
||||||
|
previewImage.src = newImageUrl;
|
||||||
|
} else {
|
||||||
|
alert('图片生成失败: ' + data.message);
|
||||||
|
loading.style.display = 'none';
|
||||||
|
previewImage.style.display = 'block';
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
// 隐藏遮罩动画
|
||||||
|
mask.classList.remove('active');
|
||||||
|
|
||||||
|
console.error('生成图片时出错:', error);
|
||||||
|
alert('生成图片时出错: ' + error.message);
|
||||||
|
loading.style.display = 'none';
|
||||||
|
previewImage.style.display = 'block';
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 确认满意按钮
|
||||||
|
confirmBtn.addEventListener('click', function() {
|
||||||
|
alert('首帧确认成功!即将进入下一环节');
|
||||||
|
// 这里可以添加跳转到下一步的逻辑
|
||||||
|
// window.location.href = 'next_step.html';
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@@ -144,6 +144,188 @@
|
|||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<style>
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
background-color: #f5f7fa;
|
||||||
|
color: #333;
|
||||||
|
line-height: 1.6;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
background: white;
|
||||||
|
border-radius: 10px;
|
||||||
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
||||||
|
padding: 30px;
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
color: #2c3e50;
|
||||||
|
}
|
||||||
|
.form-group {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #555;
|
||||||
|
}
|
||||||
|
input[type="text"], textarea {
|
||||||
|
width: 100%;
|
||||||
|
padding: 12px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 16px;
|
||||||
|
transition: border 0.3s;
|
||||||
|
}
|
||||||
|
input[type="text"]:focus, textarea:focus {
|
||||||
|
border-color: #3498db;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
.required::after {
|
||||||
|
content: ' *';
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
.tag-container {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
margin-top: 10px;
|
||||||
|
padding: 10px;
|
||||||
|
border: 1px dashed #ccc;
|
||||||
|
border-radius: 6px;
|
||||||
|
min-height: 50px;
|
||||||
|
}
|
||||||
|
.tag {
|
||||||
|
background-color: #3498db;
|
||||||
|
color: white;
|
||||||
|
padding: 5px 10px;
|
||||||
|
border-radius: 20px;
|
||||||
|
margin-right: 10px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.tag span {
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
|
.tag button {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
color: white;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
.add-tag {
|
||||||
|
display: flex;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
.add-tag input {
|
||||||
|
flex: 1;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
.btn {
|
||||||
|
padding: 12px 20px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 6px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 16px;
|
||||||
|
transition: background 0.3s;
|
||||||
|
}
|
||||||
|
.btn-primary {
|
||||||
|
background-color: #3498db;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
.btn-primary:hover {
|
||||||
|
background-color: #2980b9;
|
||||||
|
}
|
||||||
|
.btn-secondary {
|
||||||
|
background-color: #95a5a6;
|
||||||
|
color: white;
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
.btn-secondary:hover {
|
||||||
|
background-color: #7f8c8d;
|
||||||
|
}
|
||||||
|
.btn-group {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
margin-top: 30px;
|
||||||
|
}
|
||||||
|
.placeholder {
|
||||||
|
color: #999;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
.example-tip {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
padding: 15px;
|
||||||
|
border-radius: 6px;
|
||||||
|
margin-top: 5px;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
.sample-container {
|
||||||
|
margin-top: 10px;
|
||||||
|
padding: 15px;
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
border-radius: 6px;
|
||||||
|
border-left: 4px solid #3498db;
|
||||||
|
}
|
||||||
|
.sample-title {
|
||||||
|
font-weight: bold;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
/* 添加遮罩动画样式 */
|
||||||
|
.mask {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background-color: rgba(0, 0, 0, 0.7);
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
z-index: 1000;
|
||||||
|
opacity: 0;
|
||||||
|
visibility: hidden;
|
||||||
|
transition: opacity 0.3s, visibility 0.3s;
|
||||||
|
}
|
||||||
|
.mask.active {
|
||||||
|
opacity: 1;
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
|
.loader {
|
||||||
|
width: 50px;
|
||||||
|
height: 50px;
|
||||||
|
border: 5px solid rgba(255, 255, 255, 0.3);
|
||||||
|
border-radius: 50%;
|
||||||
|
border-top-color: #3498db;
|
||||||
|
animation: spin 1s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
@keyframes spin {
|
||||||
|
to { transform: rotate(360deg); }
|
||||||
|
}
|
||||||
|
.mask-text {
|
||||||
|
color: white;
|
||||||
|
margin-top: 20px;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
.mask-content {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
@@ -191,7 +373,7 @@
|
|||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="atmosphere" class="required">氛围-情绪</label>
|
<label for="atmosphere" class="required">氛围-情绪</label>
|
||||||
<input type="text" id="atmosphere" placeholder="例如:温馨" required>
|
<input type="text" id="atmosphere" placeholder="例如:温暖" required>
|
||||||
<div class="example-tip">请描述画面想要传达的整体氛围或情绪</div>
|
<div class="example-tip">请描述画面想要传达的整体氛围或情绪</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -369,7 +551,6 @@
|
|||||||
const creationMethod = document.querySelector('input[name="creationMethod"]:checked').value;
|
const creationMethod = document.querySelector('input[name="creationMethod"]:checked').value;
|
||||||
|
|
||||||
if (creationMethod === 'prompt') {
|
if (creationMethod === 'prompt') {
|
||||||
// 原有的提示词生成逻辑
|
|
||||||
// 收集表单数据
|
// 收集表单数据
|
||||||
const formData = {
|
const formData = {
|
||||||
timeWeatherLight: document.getElementById('timeWeatherLight').value,
|
timeWeatherLight: document.getElementById('timeWeatherLight').value,
|
||||||
@@ -391,11 +572,10 @@
|
|||||||
}
|
}
|
||||||
prompt += `,氛围${formData.atmosphere}。`;
|
prompt += `,氛围${formData.atmosphere}。`;
|
||||||
|
|
||||||
// 在实际应用中,这里应该发送数据到后端
|
// 调用 API 生成图片
|
||||||
console.log('生成的提示词:', prompt);
|
generateImage(prompt);
|
||||||
alert('提示词已生成:\n' + prompt + '\n\n下一步将生成首帧图片');
|
|
||||||
} else {
|
} else {
|
||||||
// 新增的图片上传逻辑
|
// 图片上传逻辑
|
||||||
if (imageUpload.files.length === 0) {
|
if (imageUpload.files.length === 0) {
|
||||||
alert('请先选择要上传的图片');
|
alert('请先选择要上传的图片');
|
||||||
return;
|
return;
|
||||||
@@ -403,10 +583,55 @@
|
|||||||
|
|
||||||
const file = imageUpload.files[0];
|
const file = imageUpload.files[0];
|
||||||
console.log('上传的图片:', file.name);
|
console.log('上传的图片:', file.name);
|
||||||
alert('图片已上传:\n' + file.name + '\n\n下一步将使用此图片作为首帧');
|
// 这里应该实现图片上传逻辑
|
||||||
|
alert('图片上传功能尚未实现');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 新增函数:调用 API 生成图片
|
||||||
|
function generateImage(prompt) {
|
||||||
|
// 显示遮罩动画
|
||||||
|
mask.classList.add('active');
|
||||||
|
maskText.textContent = '正在生成图片,请稍候...';
|
||||||
|
|
||||||
|
console.log('生成的提示词:', prompt);
|
||||||
|
|
||||||
|
// 发送请求到后端 API
|
||||||
|
fetch('/api/jimeng/prompt_input', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ prompt: prompt })
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('网络响应异常');
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
// 隐藏遮罩动画
|
||||||
|
mask.classList.remove('active');
|
||||||
|
|
||||||
|
if (data.code === 200) {
|
||||||
|
// 保存图片 URL 和提示词并跳转到预览页面
|
||||||
|
sessionStorage.setItem('generatedImageUrl', data.data.image_url);
|
||||||
|
sessionStorage.setItem('lastPrompt', prompt);
|
||||||
|
window.location.href = 'image_preview.html';
|
||||||
|
} else {
|
||||||
|
alert('图片生成失败: ' + data.message);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
// 隐藏遮罩动画
|
||||||
|
mask.classList.remove('active');
|
||||||
|
|
||||||
|
console.error('生成图片时出错:', error);
|
||||||
|
alert('生成图片时出错: ' + error.message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 表单重置事件
|
// 表单重置事件
|
||||||
promptForm.addEventListener('reset', function() {
|
promptForm.addEventListener('reset', function() {
|
||||||
// 清空标签
|
// 清空标签
|
||||||
@@ -423,4 +648,81 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
</html>
|
||||||
|
<!-- 添加遮罩层 -->
|
||||||
|
<div class="mask" id="mask">
|
||||||
|
<div class="mask-content">
|
||||||
|
<div class="loader"></div>
|
||||||
|
<div class="mask-text" id="maskText">正在生成图片,请稍候...</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
// ... existing code ...
|
||||||
|
const mask = document.getElementById('mask');
|
||||||
|
const maskText = document.getElementById('maskText');
|
||||||
|
|
||||||
|
// ... existing code ...
|
||||||
|
|
||||||
|
// 新增函数:调用 API 生成图片
|
||||||
|
function generateImage(prompt) {
|
||||||
|
// 显示遮罩动画
|
||||||
|
mask.classList.add('active');
|
||||||
|
maskText.textContent = '正在生成图片,请稍候...';
|
||||||
|
|
||||||
|
console.log('生成的提示词:', prompt);
|
||||||
|
|
||||||
|
// 发送请求到后端 API
|
||||||
|
fetch('/api/jimeng/prompt_input', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ prompt: prompt })
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('网络响应异常');
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
// 隐藏遮罩动画
|
||||||
|
mask.classList.remove('active');
|
||||||
|
|
||||||
|
if (data.code === 200) {
|
||||||
|
// 保存图片 URL 并跳转到预览页面
|
||||||
|
sessionStorage.setItem('generatedImageUrl', data.data.image_url);
|
||||||
|
window.location.href = 'image_preview.html';
|
||||||
|
} else {
|
||||||
|
alert('图片生成失败: ' + data.message);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
// 恢复按钮状态
|
||||||
|
submitBtn.disabled = false;
|
||||||
|
submitBtn.textContent = '确认并继续';
|
||||||
|
|
||||||
|
console.error('生成图片时出错:', error);
|
||||||
|
alert('生成图片时出错: ' + error.message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 表单重置事件
|
||||||
|
promptForm.addEventListener('reset', function() {
|
||||||
|
// 清空标签
|
||||||
|
while (tagContainer.firstChild) {
|
||||||
|
tagContainer.removeChild(tagContainer.firstChild);
|
||||||
|
}
|
||||||
|
tagContainer.appendChild(placeholder);
|
||||||
|
checkTagContainer();
|
||||||
|
sampleContainer.style.display = 'none';
|
||||||
|
});
|
||||||
|
|
||||||
|
// 初始化检查
|
||||||
|
checkTagContainer();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
Reference in New Issue
Block a user