- 实现AI多视角设计图生成功能,支持6个可选设计参数配置 - 集成SiliconFlow FLUX.1与火山引擎Seedream 4.5双模型切换 - 构建专业中文转英文prompt系统,提升AI生成质量 - 前端设计预览支持多视角切换与视角指示器展示 - 增加多视角设计图片DesignImage模型关联及存储 - 后端设计服务异步调用AI接口,失败时降级生成mock图 - 新增管理员后台管理路由及完整的权限校验机制 - 实现后台模块:仪表盘、系统配置、用户/品类/设计管理 - 配置数据库系统配置表,支持动态AI配置及热更新 - 增加用户管理员标识字段,管理后台登录鉴权支持 - 更新API接口支持多视角设计参数及后台管理接口 - 优化设计删除逻辑,删除多视角相关图片文件 - 前端新增管理后台页面与路由,布局样式独立分离 - 更新环境变量增加AI模型相关Key与参数配置说明 - 引入httpx异步HTTP客户端用于AI接口调用及图片下载 - README文档完善AI多视角生图与后台管理详细功能与流程说明
204 lines
11 KiB
Python
204 lines
11 KiB
Python
"""
|
|
初始化默认提示词模板和映射数据
|
|
将 prompt_builder.py 中硬编码的数据迁移到数据库
|
|
"""
|
|
import pymysql
|
|
|
|
conn = pymysql.connect(host='localhost', port=13306, user='yssjs', password='yssjs', database='yuzong', charset='utf8mb4')
|
|
cursor = conn.cursor()
|
|
|
|
# ===== 1. 提示词模板 =====
|
|
templates = [
|
|
("main_template",
|
|
"{subject}, {sub_type}, {color}, {motif}, {carving}, {style}, {finish}, {scene}, {size}, {user_prompt}, {view}, {quality}",
|
|
"主提示词模板 - 用变量拼接最终prompt。可用变量: {subject}品类主体, {sub_type}子类型, {color}颜色, {motif}题材, {carving}工艺, {style}风格, {finish}表面处理, {scene}用途, {size}尺寸, {user_prompt}用户描述, {view}视角, {quality}质量后缀"),
|
|
("quality_suffix",
|
|
"professional jewelry product photography, studio lighting setup, pure white background, ultra-detailed, sharp focus, 8K resolution, photorealistic rendering, high-end commercial quality",
|
|
"质量后缀标签 - 附加在prompt末尾的通用质量描述"),
|
|
("default_color",
|
|
"natural Hetian nephrite jade with warm luster",
|
|
"未选择颜色时的默认颜色描述"),
|
|
]
|
|
for key, val, desc in templates:
|
|
cursor.execute(
|
|
"INSERT IGNORE INTO prompt_templates (template_key, template_value, description) VALUES (%s, %s, %s)",
|
|
(key, val, desc))
|
|
print(f"✅ 插入 {len(templates)} 个提示词模板")
|
|
|
|
# ===== 2. 品类映射 (category) =====
|
|
categories = [
|
|
("牌子", "Chinese Hetian nephrite jade pendant plaque, rectangular tablet shape"),
|
|
("珠子", "Chinese Hetian nephrite jade bead, perfectly round sphere"),
|
|
("手把件", "Chinese Hetian nephrite jade hand piece (palm stone), ergonomic carved ornament for hand play"),
|
|
("雕刻件", "Chinese Hetian nephrite jade carving, intricate sculptural artwork"),
|
|
("摆件", "Chinese Hetian nephrite jade display sculpture, decorative art piece on wooden stand"),
|
|
("手镯", "Chinese Hetian nephrite jade bangle bracelet, smooth circular form"),
|
|
("耳钉", "Chinese Hetian nephrite jade stud earring, delicate small jewelry piece"),
|
|
("耳饰", "Chinese Hetian nephrite jade drop earring, elegant dangling jewelry"),
|
|
("手链", "Chinese Hetian nephrite jade bead bracelet, string of polished beads"),
|
|
("项链", "Chinese Hetian nephrite jade necklace, elegant pendant on chain"),
|
|
("戒指", "Chinese Hetian nephrite jade ring, polished jade mounted on band"),
|
|
("表带", "Chinese Hetian nephrite jade watch strap, segmented jade links"),
|
|
]
|
|
for i, (cn, en) in enumerate(categories):
|
|
cursor.execute(
|
|
"INSERT IGNORE INTO prompt_mappings (mapping_type, cn_key, en_value, sort_order) VALUES (%s, %s, %s, %s)",
|
|
("category", cn, en, i))
|
|
print(f"✅ 插入 {len(categories)} 个品类映射")
|
|
|
|
# ===== 3. 颜色映射 (color) =====
|
|
colors = [
|
|
("白玉", "pure white nephrite jade, milky translucent, warm ivory tone"),
|
|
("青白玉", "celadon-white nephrite jade, pale greenish-white, subtle cool tone"),
|
|
("青玉", "celadon nephrite jade, muted sage green, natural earthy green"),
|
|
("碧玉", "deep green jasper nephrite jade, rich forest green, vivid saturated"),
|
|
("翠青", "emerald-tinted nephrite jade, fresh spring green with blue undertone"),
|
|
("黄玉", "golden yellow nephrite jade, warm honey amber, rich golden hue"),
|
|
("糖玉", "sugar-brown nephrite jade, warm caramel brown with reddish tint"),
|
|
("墨玉", "ink-black nephrite jade, deep charcoal black, mysterious dark"),
|
|
("藕粉", "lotus-pink nephrite jade, soft blush pink, delicate pastel rose"),
|
|
("烟紫", "smoky purple nephrite jade, muted lavender grey, subtle violet"),
|
|
("糖白", "sugar-white nephrite jade, creamy white with light brown edges"),
|
|
]
|
|
for i, (cn, en) in enumerate(colors):
|
|
cursor.execute(
|
|
"INSERT IGNORE INTO prompt_mappings (mapping_type, cn_key, en_value, sort_order) VALUES (%s, %s, %s, %s)",
|
|
("color", cn, en, i))
|
|
print(f"✅ 插入 {len(colors)} 个颜色映射")
|
|
|
|
# ===== 4. 视角映射 (view) =====
|
|
views = [
|
|
("效果图", "three-quarter view, 45-degree angle, hero shot, dramatic perspective showing depth and dimension"),
|
|
("正面图", "front view, straight-on, flat lay centered, facing camera directly"),
|
|
("侧面图", "side profile view, 90-degree lateral angle, showing thickness and contour"),
|
|
("背面图", "back view, rear side, showing reverse surface and texture"),
|
|
]
|
|
for i, (cn, en) in enumerate(views):
|
|
cursor.execute(
|
|
"INSERT IGNORE INTO prompt_mappings (mapping_type, cn_key, en_value, sort_order) VALUES (%s, %s, %s, %s)",
|
|
("view", cn, en, i))
|
|
print(f"✅ 插入 {len(views)} 个视角映射")
|
|
|
|
# ===== 5. 雕刻工艺映射 (carving) =====
|
|
carvings = [
|
|
("浮雕", "relief carving with raised design emerging from surface"),
|
|
("圆雕", "full three-dimensional round carving, sculptural in the round"),
|
|
("镂空雕", "openwork pierced carving, intricate hollow cutout patterns"),
|
|
("阴刻", "intaglio engraving, incised lines carved into the surface"),
|
|
("线雕", "fine line engraving, delicate linear incised pattern"),
|
|
("俏色雕", "qiaose color-play carving utilizing natural jade skin color contrast"),
|
|
("薄意雕", "shallow thin-relief carving, subtle and understated surface design"),
|
|
("素面", "plain polished surface, smooth minimalist finish without carving"),
|
|
]
|
|
for i, (cn, en) in enumerate(carvings):
|
|
cursor.execute(
|
|
"INSERT IGNORE INTO prompt_mappings (mapping_type, cn_key, en_value, sort_order) VALUES (%s, %s, %s, %s)",
|
|
("carving", cn, en, i))
|
|
print(f"✅ 插入 {len(carvings)} 个雕刻工艺映射")
|
|
|
|
# ===== 6. 设计风格映射 (style) =====
|
|
styles = [
|
|
("古典传统", "classical traditional Chinese style, antique aesthetic, heritage craftsmanship"),
|
|
("新中式", "modern neo-Chinese style, contemporary Asian minimalism with traditional elements"),
|
|
("写实", "realistic naturalistic style, lifelike detailed representation"),
|
|
("抽象意境", "abstract artistic impression, fluid organic forms, poetic mood"),
|
|
("极简素面", "ultra-minimalist clean design, sleek smooth surface, zen aesthetic"),
|
|
]
|
|
for i, (cn, en) in enumerate(styles):
|
|
cursor.execute(
|
|
"INSERT IGNORE INTO prompt_mappings (mapping_type, cn_key, en_value, sort_order) VALUES (%s, %s, %s, %s)",
|
|
("style", cn, en, i))
|
|
print(f"✅ 插入 {len(styles)} 个设计风格映射")
|
|
|
|
# ===== 7. 题材纹样映射 (motif) =====
|
|
motifs = [
|
|
("观音", "Guanyin Bodhisattva figure, serene Buddhist deity of mercy"),
|
|
("弥勒", "Maitreya laughing Buddha, jovial happy Buddha figure"),
|
|
("莲花", "lotus flower motif, sacred Buddhist lotus blossom petals"),
|
|
("貔貅", "Pixiu mythical beast, Chinese fortune guardian creature"),
|
|
("龙凤", "dragon and phoenix motif, imperial auspicious dual creatures"),
|
|
("麒麟", "Qilin mythical unicorn, auspicious Chinese legendary beast"),
|
|
("山水", "Chinese mountain and water landscape, shanshui scenery"),
|
|
("花鸟", "flower and bird motif, traditional Chinese nature painting theme"),
|
|
("人物", "human figure motif, classical Chinese character portrayal"),
|
|
("回纹", "Greek key fret pattern, Chinese meander geometric border"),
|
|
("如意", "Ruyi scepter motif, auspicious cloud-head wish-granting symbol"),
|
|
("平安扣", "Ping'an buckle motif, smooth circular safety and peace symbol"),
|
|
]
|
|
for i, (cn, en) in enumerate(motifs):
|
|
cursor.execute(
|
|
"INSERT IGNORE INTO prompt_mappings (mapping_type, cn_key, en_value, sort_order) VALUES (%s, %s, %s, %s)",
|
|
("motif", cn, en, i))
|
|
print(f"✅ 插入 {len(motifs)} 个题材纹样映射")
|
|
|
|
# ===== 8. 表面处理映射 (finish) =====
|
|
finishes = [
|
|
("高光抛光", "high-gloss mirror polish, reflective glossy surface"),
|
|
("亚光/哑光", "matte satin finish, soft non-reflective surface"),
|
|
("磨砂", "frosted textured finish, fine granular surface"),
|
|
("保留皮色", "natural jade skin preserved, raw russet-brown outer skin layer retained"),
|
|
]
|
|
for i, (cn, en) in enumerate(finishes):
|
|
cursor.execute(
|
|
"INSERT IGNORE INTO prompt_mappings (mapping_type, cn_key, en_value, sort_order) VALUES (%s, %s, %s, %s)",
|
|
("finish", cn, en, i))
|
|
print(f"✅ 插入 {len(finishes)} 个表面处理映射")
|
|
|
|
# ===== 9. 用途场景映射 (scene) =====
|
|
scenes = [
|
|
("日常佩戴", "designed for daily wear, comfortable and practical"),
|
|
("收藏鉴赏", "museum-quality collector piece, exquisite showpiece"),
|
|
("送礼婚庆", "premium gift piece, ceremonial and auspicious"),
|
|
("把玩文玩", "tactile palm play piece, smooth hand-feel for meditation"),
|
|
]
|
|
for i, (cn, en) in enumerate(scenes):
|
|
cursor.execute(
|
|
"INSERT IGNORE INTO prompt_mappings (mapping_type, cn_key, en_value, sort_order) VALUES (%s, %s, %s, %s)",
|
|
("scene", cn, en, i))
|
|
print(f"✅ 插入 {len(scenes)} 个用途场景映射")
|
|
|
|
# ===== 10. 子类型映射 (sub_type) =====
|
|
sub_types = [
|
|
("二五牌", "2:5 ratio rectangular plaque"),
|
|
("三角牌", "triangular shaped pendant"),
|
|
("三五牌", "3:5 ratio rectangular plaque"),
|
|
("四六牌", "4:6 ratio rectangular plaque"),
|
|
("正方形", "square shaped plaque"),
|
|
("椭圆形", "oval shaped plaque"),
|
|
("平安镯", "flat interior round exterior classic bangle"),
|
|
("福镯", "round interior round exterior full-round bangle"),
|
|
("贵妃镯", "oval elliptical shape bangle fitting wrist contour"),
|
|
("美人镯", "slim delicate thin bangle, elegant refined"),
|
|
("方镯", "square cross-section angular bangle"),
|
|
("雕花镯", "carved decorative pattern bangle"),
|
|
("圆形耳钉", "round circular stud"),
|
|
("水滴形耳钉", "teardrop shaped stud"),
|
|
("方形耳钉", "square geometric stud"),
|
|
("花朵形耳钉", "flower blossom shaped stud"),
|
|
("心形耳钉", "heart shaped stud"),
|
|
("几何形耳钉", "abstract geometric stud"),
|
|
("耳环", "hoop earring"),
|
|
("耳坠", "drop dangle earring"),
|
|
("耳夹", "clip-on earring"),
|
|
("流苏耳饰", "tassel fringe long earring"),
|
|
("素面戒指", "plain smooth surface ring"),
|
|
("镶嵌戒指", "metal-set mounted jade ring"),
|
|
("雕花戒指", "carved decorative ring"),
|
|
("扳指", "traditional archer thumb ring"),
|
|
("指环", "simple band ring"),
|
|
("锁骨链", "short collarbone chain necklace"),
|
|
("吊坠项链", "pendant necklace with jade drop"),
|
|
("串珠项链", "beaded jade strand necklace"),
|
|
("编绳项链", "braided cord necklace with jade"),
|
|
("毛衣链", "long sweater chain necklace"),
|
|
]
|
|
for i, (cn, en) in enumerate(sub_types):
|
|
cursor.execute(
|
|
"INSERT IGNORE INTO prompt_mappings (mapping_type, cn_key, en_value, sort_order) VALUES (%s, %s, %s, %s)",
|
|
("sub_type", cn, en, i))
|
|
print(f"✅ 插入 {len(sub_types)} 个子类型映射")
|
|
|
|
conn.commit()
|
|
conn.close()
|
|
print("\n✅ 全部提示词数据初始化完成!")
|