diff --git a/dsLightRag/JiMeng/Kit/__pycache__/JmTxt2ImgUtil.cpython-310.pyc b/dsLightRag/JiMeng/Kit/__pycache__/JmTxt2ImgUtil.cpython-310.pyc new file mode 100644 index 00000000..7990fa66 Binary files /dev/null and b/dsLightRag/JiMeng/Kit/__pycache__/JmTxt2ImgUtil.cpython-310.pyc differ diff --git a/dsLightRag/Routes/JiMengRoute.py b/dsLightRag/Routes/JiMengRoute.py index 00beceed..cad42929 100644 --- a/dsLightRag/Routes/JiMengRoute.py +++ b/dsLightRag/Routes/JiMengRoute.py @@ -41,6 +41,9 @@ async def prompt_input(request: fastapi.Request): "image_url": image_url } } + except HTTPException as e: + logger.error(f"请求参数错误: {str(e.detail)}") + raise e except Exception as e: logger.error(f"图片生成失败: {str(e)}") raise HTTPException(status_code=500, detail=f"图片生成失败: {str(e)}") diff --git a/dsLightRag/Routes/__pycache__/JiMengRoute.cpython-310.pyc b/dsLightRag/Routes/__pycache__/JiMengRoute.cpython-310.pyc new file mode 100644 index 00000000..6a16ad1f Binary files /dev/null and b/dsLightRag/Routes/__pycache__/JiMengRoute.cpython-310.pyc differ diff --git a/dsLightRag/Routes/__pycache__/QA.cpython-310.pyc b/dsLightRag/Routes/__pycache__/QA.cpython-310.pyc index 26fd0ed9..754c6454 100644 Binary files a/dsLightRag/Routes/__pycache__/QA.cpython-310.pyc and b/dsLightRag/Routes/__pycache__/QA.cpython-310.pyc differ diff --git a/dsLightRag/static/JiMeng/image_preview.html b/dsLightRag/static/JiMeng/image_preview.html new file mode 100644 index 00000000..cb452d8f --- /dev/null +++ b/dsLightRag/static/JiMeng/image_preview.html @@ -0,0 +1,243 @@ + + + + + + 首帧预览 + + + +
+

首帧预览

+
+
加载中...
+ +
+
+ + + +
+
+ + +
+
+
+
正在生成图片,请稍候...
+
+
+ + + + \ No newline at end of file diff --git a/dsLightRag/static/JiMeng/prompt_input.html b/dsLightRag/static/JiMeng/prompt_input.html index 8de0705f..e007ef94 100644 --- a/dsLightRag/static/JiMeng/prompt_input.html +++ b/dsLightRag/static/JiMeng/prompt_input.html @@ -144,6 +144,188 @@ margin-bottom: 10px; } +
@@ -191,7 +373,7 @@
- +
请描述画面想要传达的整体氛围或情绪
@@ -369,7 +551,6 @@ const creationMethod = document.querySelector('input[name="creationMethod"]:checked').value; if (creationMethod === 'prompt') { - // 原有的提示词生成逻辑 // 收集表单数据 const formData = { timeWeatherLight: document.getElementById('timeWeatherLight').value, @@ -391,11 +572,10 @@ } prompt += `,氛围${formData.atmosphere}。`; - // 在实际应用中,这里应该发送数据到后端 - console.log('生成的提示词:', prompt); - alert('提示词已生成:\n' + prompt + '\n\n下一步将生成首帧图片'); + // 调用 API 生成图片 + generateImage(prompt); } else { - // 新增的图片上传逻辑 + // 图片上传逻辑 if (imageUpload.files.length === 0) { alert('请先选择要上传的图片'); return; @@ -403,10 +583,55 @@ const file = imageUpload.files[0]; 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() { // 清空标签 @@ -423,4 +648,81 @@ }); + + +
+
+
+
正在生成图片,请稍候...
+
+
+ + + \ No newline at end of file