diff --git a/outputs/generated_code.jsx b/outputs/generated_code.jsx
deleted file mode 100644
index 6f04287..0000000
--- a/outputs/generated_code.jsx
+++ /dev/null
@@ -1,47 +0,0 @@
-```jsx
-import React from 'react';
-
-const DragonBoatFestivalPoster = () => {
- return (
-
- {/* 背景图层 */}
-
-
- {/* 主体图层 */}
-
-
-
-
-
- {/* 活动亮点 */}
-
-
- {/* 页脚 */}
-
-
- );
-};
-
-export default DragonBoatFestivalPoster;
-```
\ No newline at end of file
diff --git a/outputs/generated_code.vue b/outputs/generated_code.vue
new file mode 100644
index 0000000..6678248
--- /dev/null
+++ b/outputs/generated_code.vue
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
![]()
+
+
+
+
+
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..2cc43e7
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,11 @@
+# 基础依赖
+python-dotenv # 用于加载.env文件中的环境变量
+pyyaml # 用于解析YAML配置文件
+
+# API客户端
+openai == 1.82.1 # 用于调用OpenAI/Moonshot/DeepSeek API
+
+# 图像处理
+Pillow # PIL库,用于基础图像处理
+psd-tools # 用于PSD文件的创建和操作
+
diff --git a/scripts/generate_layout.py b/scripts/generate_layout.py
index 56906c4..8bea5d3 100644
--- a/scripts/generate_layout.py
+++ b/scripts/generate_layout.py
@@ -2,8 +2,6 @@ import os
from openai import OpenAI
from dotenv import load_dotenv
import time
-import logging
-
# === Config LLM call ===
load_dotenv()
@@ -12,12 +10,6 @@ deepseek_api = os.getenv("DEEPSEEK_API_KEY")
if not deepseek_api:
raise ValueError("DEEPSEEK_API_KEY not set!")
-# 配置日志
-logging.basicConfig(level=logging.INFO)
-logger = logging.getLogger(__name__)
-
-
-# === prompts and parameters ===
def call_deepseek(
messages=None,
system_prompt="你是一个擅长前端开发的AI,专注于生成Vue.js代码。",
@@ -99,37 +91,33 @@ def call_deepseek(
return content, response.usage
except Exception as e:
- if hasattr(e, 'status_code') and e.status_code == 429: # 限流
- logger.warning(f"请求过于频繁,正在重试... (尝试 {attempt + 1}/{max_retries})")
+ if hasattr-------------('status_code') and e.status_code == 429: # 限流
+ print(f"请求过于频繁,正在重试... (尝试 {attempt + 1}/{max_retries})")
time.sleep(2 ** attempt) # 指数退避
else:
- logger.error(f"API 调用失败:{str(e)}")
raise
raise Exception("达到最大重试次数,API 调用失败")
def generate_vue_code(prompt=None):
prompt = (
- "生成一个React组件代码,用于端午节活动海报,包含以下部分并指定排版位置:"
+ "生成一个Vue组件代码,用于端午节活动海报,包含以下部分并指定排版位置:"
"1. 背景图层:div,占据整个组件区域。"
"2. 主体图层:div,位于顶部1/4处,居中,包含标题和副标题。"
"3. 活动亮点:div,位于底部1/4处,居中,使用网格布局展示三项活动(每项包含图标、标题和描述)。"
"4. 页脚:div,位于底部,居中,包含主办单位信息和logo图片。"
"组件尺寸为1080x1920px,布局使用absolute定位,仅关注排版位置,不包含任何样式描述(如颜色、字体、阴影、动画等)。"
- "仅生成React代码本身,不包含说明性文字、注释或Markdown格式。"
+ "仅生成Vue代码本身,不包含说明性文字、注释或Markdown格式。"
)
system_prompt = (
- "你是一个擅长前端开发的AI,专注于生成React.js代码。"
+ "你是一个擅长前端开发的AI,专注于生成Vue.js代码。"
"生成的代码仅关注排版位置,使用absolute定位,不包含任何样式描述(如颜色、字体、阴影、动画等)。"
- "确保代码符合React最佳实践,仅生成代码本身。"
+ "确保代码符合Vue最佳实践,仅生成代码本身。"
)
-
- result,usage = call_deepseek(prompt=prompt, system_prompt=system_prompt,temperature=0.4)
- # print(result)
- # print(usage)
+ result, usage = call_deepseek(prompt=prompt, system_prompt=system_prompt, temperature=0.4)
return result
-def save_code(code,file_path="../outputs/generated_code.jsx"):
+def save_code(code, file_path="../outputs/generated_code.vue"):
os.makedirs(os.path.dirname(file_path), exist_ok=True)
with open(file_path, "w", encoding="utf-8") as f:
f.write(code)
@@ -137,4 +125,4 @@ def save_code(code,file_path="../outputs/generated_code.jsx"):
if __name__ == "__main__":
vue_code = generate_vue_code()
save_code(vue_code)
- print("React组件代码已生成并保存到outputs/generated_code.jsx")
\ No newline at end of file
+ print("Vue组件代码已生成并保存到outputs/generated_code.vue")
\ No newline at end of file