tsurumure 1 mese fa
parent
commit
08b6e21fa7

+ 6 - 6
db/crt_drama_project_storyboard.sql

@@ -20,12 +20,12 @@ CREATE TABLE `crt_drama_project_storyboard` (
     `story_weather_time` VARCHAR(1000) COMMENT '天气/时间',
     `lora_figure_ids` VARCHAR(255) COMMENT '人物LoRA ID (创建时,跟随项目的人物LoRAID)(多个人物ID以逗号分隔)',
 
-    `param_image_count` INT DEFAULT '1' COMMENT '每次生成图片数量 (默认值:1,整数范围:1~4)',
-    `param_prompt_weight` FLOAT DEFAULT '3.5' COMMENT '提示词引导系数 (默认值:3.5,小数点后一位,范围:1~30)',
-    `param_sampling_method` VARCHAR(20) DEFAULT 'Euler' COMMENT '采样方法 (枚举)(Euler: euler, DPM++2M: dpmpp_2m)',
-    `param_step_count` INT DEFAULT '20' COMMENT '步数 (默认值:20,整数范围:1~30)',
-    `param_random_seed` TINYINT DEFAULT '1' COMMENT '随机种子 (默认值:1,范围:(1:随机, 2:自定义))',
-    `param_random_seed_custom` VARCHAR(255) COMMENT '随机种子自定义值 (长度: 0~64位整数)',
+    `param_batch_size` INT DEFAULT '1' COMMENT '每次生成图片数量 (默认值:1,整数范围:1~4)',
+    `param_prompt_flux_guidance` FLOAT DEFAULT '3.5' COMMENT '提示词引导系数 (默认值:3.5,小数点后一位,范围:1~30)',
+    `param_sampler` VARCHAR(20) DEFAULT 'Euler' COMMENT '采样方法 (枚举)(Euler: euler, DPM++2M: dpmpp_2m)',
+    `param_step` INT DEFAULT '20' COMMENT '步数 (默认值:20,整数范围:1~30)',
+    `param_seed` TINYINT DEFAULT '1' COMMENT '随机种子 (默认值:1,范围:(1:随机, 2:自定义))',
+    `param_seed_custom` VARCHAR(255) COMMENT '随机种子自定义值 (长度: 0~64位整数)',
     `text_to_image_prompt` VARCHAR(2000) COMMENT '文生图提示词 (生图时必填)',
 
     `param_video_reference_type` TINYINT DEFAULT '1' COMMENT '生视频模式 (1:首尾帧模式, 2:多图参考模式)',

+ 1 - 1
db/crt_model.sql

@@ -14,5 +14,5 @@ CREATE TABLE `crt_model` (
 ) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='短剧创作-风格LoRA表';
 
 INSERT INTO crt_model(id, name, model_name, model_path) VALUES
-    (1, 'F.1-dev.safetensors', 'F.1-dev.safetensors', '/etc/ComfyUI/custom_nodes/xxx/F.1-dev.safetensors')
+    (1, 'F.1-dev.safetensors', 'FLUX1/flux1-dev-fp8.safetensors', '/etc/ComfyUI/custom_nodes/xxx/F.1-dev.safetensors')
 ;

+ 9 - 0
src/main/java/com/backendsys/modules/crt/dao/CrtModelDao.java

@@ -0,0 +1,9 @@
+package com.backendsys.modules.crt.dao;
+
+import com.backendsys.modules.crt.entity.CrtModel;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface CrtModelDao extends BaseMapper<CrtModel> {
+}

+ 7 - 7
src/main/java/com/backendsys/modules/crt/entity/CrtDramaProjectStoryboard.java

@@ -63,27 +63,27 @@ public class CrtDramaProjectStoryboard {
 
     // 每次生成图片数量 (默认值:1,整数范围:1~4)
     @RangeArray(message="生成图片数量取值有误,范围应是(1, 2, 3, 4)", value = { "1", "2", "3", "4" }, groups = { Update.class })
-    private Integer param_image_count;
+    private Integer param_batch_size;
 
     // 提示词引导系数 (默认值:3.5,小数点后一位,范围:1~30)
     @Range(min = 1, max = 30, message = "提示词引导系数必须在 {min} 到 {max} 之间", groups = { Update.class })
-    private Float param_prompt_weight;
+    private Float param_prompt_flux_guidance;
 
-    // 采样方法 (枚举: SamplingMethodEnums)(Euler: euler, DPM++2M: dpmpp_2m)
+    // 采样方法 (枚举: SamplerEnums)(Euler: euler, DPM++2M: dpmpp_2m)
     @RangeStringArray(message="采样方法取值有误,范围应是(Euler, DPM++2M)", value = { "Euler", "DPM++2M" }, groups = { Update.class })
-    private String param_sampling_method;
+    private String param_sampler;
 
     // 步数 (默认值:20,整数范围:1~30)
     @Range(min = 1, max = 30, message = "步数必须在 {min} 到 {max} 之间", groups = { Update.class })
-    private Integer param_step_count;
+    private Integer param_step;
 
     // 随机种子 (默认值:1,范围:(1:随机, 2:自定义))
     @RangeArray(message="随机种子取值有误,范围应是(1, 2)", value = { "1", "2" }, groups = { Update.class })
-    private Integer param_random_seed;
+    private Integer param_seed;
 
     // 随机种子自定义值 (长度: 0~64位整数)
     @Size(max = 64, message = "随机种子自定义值长度不超过 {max} 个字符", groups = { Update.class })
-    private String param_random_seed_custom;
+    private String param_seed_custom;
 
     // 文生图提示词 (生图时必填)
     @Size(max = 2000, message = "文生图提示词 长度不超过 {max} 个字符", groups = { Update.class })

+ 16 - 0
src/main/java/com/backendsys/modules/crt/entity/CrtModel.java

@@ -0,0 +1,16 @@
+package com.backendsys.modules.crt.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+@Data
+@TableName("crt_model")
+public class CrtModel {
+    @TableId(type = IdType.AUTO)
+    private Long id;
+    private String name;
+    private String model_name;
+    private String model_path;
+}

+ 11 - 3
src/main/java/com/backendsys/modules/crt/enums/SamplingMethodEnums.java → src/main/java/com/backendsys/modules/crt/enums/SamplerEnums.java

@@ -3,16 +3,16 @@ package com.backendsys.modules.crt.enums;
 /**
  * 采样方法
  */
-public enum SamplingMethodEnums {
+public enum SamplerEnums {
 
-    EULER("Euler", "DPM++2M"),
+    EULER("Euler", "euler"),
     DPM2M("DPM++2M", "dpmpp_2m")
     ;
 
     private final String key;
     private final String value;
 
-    SamplingMethodEnums(String key, String value) {
+    SamplerEnums(String key, String value) {
         this.key = key;
         this.value = value;
     }
@@ -24,4 +24,12 @@ public enum SamplingMethodEnums {
         return this.key;
     }
 
+    public static String getValueByKey(String key) {
+        for (SamplerEnums enumValue : SamplerEnums.values()) {
+            if (enumValue.key.equals(key)) {
+                return enumValue.value;
+            }
+        }
+        return null;
+    }
 }

+ 68 - 9
src/main/java/com/backendsys/modules/crt/service/impl/CrtGenerateServiceImpl.java

@@ -1,21 +1,29 @@
 package com.backendsys.modules.crt.service.impl;
 
 import cn.hutool.core.convert.Convert;
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import com.backendsys.exception.CustException;
+import com.backendsys.modules.crt.dao.CrtDramaProjectSettingsDao;
 import com.backendsys.modules.crt.dao.CrtDramaProjectStoryboardDao;
+import com.backendsys.modules.crt.dao.CrtModelDao;
+import com.backendsys.modules.crt.entity.CrtDramaProjectSettings;
 import com.backendsys.modules.crt.entity.CrtDramaProjectStoryboard;
+import com.backendsys.modules.crt.entity.CrtModel;
+import com.backendsys.modules.crt.enums.SamplerEnums;
 import com.backendsys.modules.crt.service.CrtGenerateService;
 import com.backendsys.modules.sdk.comfyui.entity.CFPromptResponse;
 import com.backendsys.modules.sdk.comfyui.entity.CFQueue;
 import com.backendsys.modules.sdk.comfyui.service.ComfyUIService;
 import com.backendsys.modules.sdk.comfyui.service.ComfyUISocketService;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import reactor.core.publisher.Mono;
 
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
@@ -26,6 +34,11 @@ public class CrtGenerateServiceImpl implements CrtGenerateService {
     private ComfyUIService comfyUIService;
     @Autowired
     private ComfyUISocketService comfyUISocketService;
+
+    @Autowired
+    private CrtModelDao crtModelDao;
+    @Autowired
+    private CrtDramaProjectSettingsDao crtDramaProjectSettingsDao;
     @Autowired
     private CrtDramaProjectStoryboardDao crtDramaProjectStoryboardDao;
 
@@ -50,13 +63,59 @@ public class CrtGenerateServiceImpl implements CrtGenerateService {
     @Override
     public Map<String, Object> generateImage(CrtDramaProjectStoryboard crtDramaProjectStoryboard) {
 
-        String text_to_image_prompt = crtDramaProjectStoryboard.getText_to_image_prompt();
+        // 分镜ID
         Long drama_project_storyboard_id = crtDramaProjectStoryboard.getDrama_project_storyboard_id();
 
-        System.out.println("(文生图提示词) text_to_image_prompt = " + text_to_image_prompt);
+        CrtDramaProjectStoryboard storyboardDetail = crtDramaProjectStoryboardDao.selectById(drama_project_storyboard_id);
+        if (storyboardDetail == null) throw new CustException("分镜不存在");
+        System.out.println("分镜详情: " + JSONUtil.toJsonStr(storyboardDetail));
+
+        Long drama_project_id = storyboardDetail.getDrama_project_id();
+        LambdaQueryWrapper<CrtDramaProjectSettings> wrapperSettings = new LambdaQueryWrapper<>();
+        wrapperSettings.eq(CrtDramaProjectSettings::getDrama_project_id, drama_project_id);
+        List<CrtDramaProjectSettings> settingsDetail = crtDramaProjectSettingsDao.selectList(wrapperSettings);
+        if (settingsDetail == null) throw new CustException("项目配置不存在");
+        System.out.println("项目配置: " + JSONUtil.toJsonStr(settingsDetail));
+
+        // 项目配置类型 (1:生图配置, 2:生视频配置)
+        CrtDramaProjectSettings settings_image = settingsDetail.stream().filter(item -> item.getDrama_project_setting_type() == 1).findFirst().orElse(null);
+        CrtDramaProjectSettings settings_video = settingsDetail.stream().filter(item -> item.getDrama_project_setting_type() == 2).findFirst().orElse(null);
+        System.out.println("- 生图配置: " + JSONUtil.toJsonStr(settings_image));
+        System.out.println("- 生视频配置: " + JSONUtil.toJsonStr(settings_video));
+
+
+        // 文生图提示词
+        String text_to_image_prompt = crtDramaProjectStoryboard.getText_to_image_prompt();
+
+        // == 从 storboard detail 获取参数 =============================================================================
+        Integer param_batch_size = storyboardDetail.getParam_batch_size();                        // 生成图片数量
+        Float param_prompt_flux_guidance = storyboardDetail.getParam_prompt_flux_guidance();      // 提示词引导系数
+        String param_sampler = SamplerEnums.getValueByKey(storyboardDetail.getParam_sampler());   // 采样器
+
+        // 随机种子 (默认值:1,范围:(1:随机, 2:自定义))
+        Integer param_seed = storyboardDetail.getParam_seed();
+        String param_seed_custom = storyboardDetail.getParam_seed_custom();
+        if (param_seed == 1) {
+            param_seed_custom = Convert.toStr(DateUtil.current());   // 生成一个随机值 (毫秒时间戳)
+
+            // 【随机值,要保存到数据库】
+
+        }
+
+        // [db] 获取基础模型 (从项目配置)
+        Long model_id = settings_image.getModel_id();
+        CrtModel modelDetail = crtModelDao.selectById(model_id);
+        String model_name = modelDetail.getModel_name();
+
+
+        // 风格 Lora?
+        // 风格 Lora (阙值)?
+
+
+        // ===========================================================================================================
+
+
 
-        CrtDramaProjectStoryboard detail = crtDramaProjectStoryboardDao.selectById(drama_project_storyboard_id);
-        if (detail == null) throw new CustException("分镜不存在");
 
         // -- 前端生成的UUID ---------------------------------------------
         String client_id = Convert.toStr(UUID.randomUUID());
@@ -163,7 +222,7 @@ public class CrtGenerateServiceImpl implements CrtGenerateService {
                 "  },"+
                 "  \"13\": {"+
                 "    \"inputs\": {"+
-                "      \"guidance\": 3.5,"+
+                "      \"guidance\": " + param_prompt_flux_guidance + ","+
                 "      \"conditioning\": ["+
                 "        \"3\","+
                 "        0"+
@@ -236,7 +295,7 @@ public class CrtGenerateServiceImpl implements CrtGenerateService {
                 "  },"+
                 "  \"37\": {"+
                 "    \"inputs\": {"+
-                "      \"noise_seed\": 229229841277714"+
+                "      \"noise_seed\": " + param_seed_custom +
                 "    },"+
                 "    \"class_type\": \"RandomNoise\","+
                 "    \"_meta\": {"+
@@ -275,7 +334,7 @@ public class CrtGenerateServiceImpl implements CrtGenerateService {
                 "  },"+
                 "  \"84\": {"+
                 "    \"inputs\": {"+
-                "      \"sampler_name\": \"euler\""+
+                "      \"sampler_name\": \"" + param_sampler + "\""+
                 "    },"+
                 "    \"class_type\": \"KSamplerSelect\","+
                 "    \"_meta\": {"+
@@ -292,7 +351,7 @@ public class CrtGenerateServiceImpl implements CrtGenerateService {
                 "        \"122\","+
                 "        0"+
                 "      ],"+
-                "      \"batch_size\": 1"+
+                "      \"batch_size\": " + param_batch_size +
                 "    },"+
                 "    \"class_type\": \"EmptySD3LatentImage\","+
                 "    \"_meta\": {"+
@@ -406,7 +465,7 @@ public class CrtGenerateServiceImpl implements CrtGenerateService {
                 "  },"+
                 "  \"151\": {"+
                 "    \"inputs\": {"+
-                "      \"ckpt_name\": \"FLUX1/flux1-dev-fp8.safetensors\""+
+                "      \"ckpt_name\": \"" + model_name + "\""+
                 "    },"+
                 "    \"class_type\": \"CheckpointLoaderSimple\","+
                 "    \"_meta\": {"+

+ 6 - 6
src/main/resources/mapper/crt/drama/CrtDramaProjectStoryboardDao.xml

@@ -15,12 +15,12 @@
             <if test="story_scene != null and story_scene != ''">story_scene = #{story_scene},</if>
             <if test="story_weather_time != null and story_weather_time != ''">story_weather_time = #{story_weather_time},</if>
             <if test="lora_figure_ids != null and lora_figure_ids != ''">lora_figure_ids = #{lora_figure_ids},</if>
-            <if test="param_image_count != null and param_image_count != ''">param_image_count = #{param_image_count},</if>
-            <if test="param_prompt_weight != null and param_prompt_weight != ''">param_prompt_weight = #{param_prompt_weight},</if>
-            <if test="param_sampling_method != null and param_sampling_method != ''">param_sampling_method = #{param_sampling_method},</if>
-            <if test="param_step_count != null and param_step_count != ''">param_step_count = #{param_step_count},</if>
-            <if test="param_random_seed != null and param_random_seed != ''">param_random_seed = #{param_random_seed},</if>
-            <if test="param_random_seed_custom != null and param_random_seed_custom != ''">param_random_seed_custom = #{param_random_seed_custom},</if>
+            <if test="param_batch_size != null and param_batch_size != ''">param_batch_size = #{param_batch_size},</if>
+            <if test="param_prompt_flux_guidance != null and param_prompt_flux_guidance != ''">param_prompt_flux_guidance = #{param_prompt_flux_guidance},</if>
+            <if test="param_sampler != null and param_sampler != ''">param_sampler = #{param_sampler},</if>
+            <if test="param_step != null and param_step != ''">param_step = #{param_step},</if>
+            <if test="param_seed != null and param_seed != ''">param_seed = #{param_seed},</if>
+            <if test="param_seed_custom != null and param_seed_custom != ''">param_seed_custom = #{param_seed_custom},</if>
             <if test="text_to_image_prompt != null and text_to_image_prompt != ''">text_to_image_prompt = #{text_to_image_prompt},</if>
             <if test="param_video_reference_type != null and param_video_reference_type != ''">param_video_reference_type = #{param_video_reference_type},</if>
             <if test="param_video_reference_images != null and param_video_reference_images != ''">param_video_reference_images = #{param_video_reference_images},</if>