🎬 火宝短剧 - 基于AI的一站式短剧生成平台 《一句话生成完整短剧,从剧本到成片全自动化》 Huobao Drama - An AI-Powered End-to-End Short Drama Generator "One Sentence to Complete Drama: Fully Automated from Script to Final Video"
TypeScript
feat: Introduce configurable style parameters for AI image generation, including character images and background extraction, with default style fallbacks.
fuyang513922099cba
diff --git a/api/handlers/character_library_gen.go b/api/handlers/character_library_gen.goindex b94ddf6..e5fbd55 100644--- a/api/handlers/character_library_gen.go+++ b/api/handlers/character_library_gen.go@@ -10,13 +10,14 @@ func (h *CharacterLibraryHandler) GenerateCharacterImage(c *gin.Context) {characterID := c.Param("id")- // 获取请求体中的model参数+ // 获取请求体中的model和style参数var req struct {Model string `json:"model"`+ Style string `json:"style"`}c.ShouldBindJSON(&req)- imageGen, err := h.libraryService.GenerateCharacterImage(characterID, h.imageService, req.Model)+ imageGen, err := h.libraryService.GenerateCharacterImage(characterID, h.imageService, req.Model, req.Style)if err != nil {if err.Error() == "character not found" {response.NotFound(c, "角色不存在")diff --git a/api/handlers/image_generation.go b/api/handlers/image_generation.goindex c595a14..75e6469 100644--- a/api/handlers/image_generation.go+++ b/api/handlers/image_generation.go@@ -16,6 +16,7 @@ type ImageGenerationHandler struct {imageService *services.ImageGenerationServicetaskService *services.TaskServicelog *logger.Logger+ config *config.Config}func NewImageGenerationHandler(db *gorm.DB, cfg *config.Config, log *logger.Logger, transferService *services.ResourceTransferService, localStorage *storage.LocalStorage) *ImageGenerationHandler {@@ -75,13 +76,19 @@ func (h *ImageGenerationHandler) GetBackgroundsForEpisode(c *gin.Context) {func (h *ImageGenerationHandler) ExtractBackgroundsForEpisode(c *gin.Context) {episodeID := c.Param("episode_id")- // 接收可选的 model 参数+ // 接收可选的 model 和 style 参数var req struct {Model string `json:"model"`+ Style string `json:"style"`}if err := c.ShouldBindJSON(&req); err != nil {- // 如果没有提供body或者解析失败,使用空字符串(使用默认模型)+ // 如果没有提供body或者解析失败,使用空字符串(使用默认模型和风格)req.Model = ""+ req.Style = ""+ }+ // 如果style为空,使用配置中的默认风格+ if req.Style == "" {+ req.Style = h.config.Style.DefaultSceneStyle}// 创建异步任务@@ -93,7 +100,7 @@ func (h *ImageGenerationHandler) ExtractBackgroundsForEpisode(c *gin.Context) {}// 启动后台goroutine处理- go h.processBackgroundExtraction(task.ID, episodeID, req.Model)+ go h.processBackgroundExtraction(task.ID, episodeID, req.Model, req.Style)// 立即返回任务IDresponse.Success(c, gin.H{@@ -104,8 +111,8 @@ func (h *ImageGenerationHandler) ExtractBackgroundsForEpisode(c *gin.Context) {}// processBackgroundExtraction 后台处理场景提取-func (h *ImageGenerationHandler) processBackgroundExtraction(taskID, episodeID, model string) {- h.log.Infow("Starting background extraction", "task_id", taskID, "episode_id", episodeID, "model", model)+func (h *ImageGenerationHandler) processBackgroundExtraction(taskID, episodeID, model, style string) {+ h.log.Infow("Starting background extraction", "task_id", taskID, "episode_id", episodeID, "model", model, "style", style)// 更新任务状态为处理中if err := h.taskService.UpdateTaskStatus(taskID, "processing", 10, "开始提取场景..."); err != nil {@@ -113,7 +120,7 @@ func (h *ImageGenerationHandler) processBackgroundExtraction(taskID, episodeID,}// 调用实际的提取逻辑- backgrounds, err := h.imageService.ExtractBackgroundsForEpisode(episodeID, model)+ backgrounds, err := h.imageService.ExtractBackgroundsForEpisode(episodeID, model, style)if err != nil {h.log.Errorw("Failed to extract backgrounds", "error", err, "task_id", taskID)if updateErr := h.taskService.UpdateTaskError(taskID, err); updateErr != nil {diff --git a/application/services/character_library_service.go b/application/services/character_library_service.goindex a7850b8..6782a47 100644--- a/application/services/character_library_service.go+++ b/application/services/character_library_service.go@@ -280,7 +280,7 @@ func (s *CharacterLibraryService) DeleteCharacter(characterID uint) error {}// GenerateCharacterImage AI生成角色形象-func (s *CharacterLibraryService) GenerateCharacterImage(characterID string, imageService *ImageGenerationService, modelName string) (*models.ImageGeneration, error) {+func (s *CharacterLibraryService) GenerateCharacterImage(characterID string, imageService *ImageGenerationService, modelName string, style string) (*models.ImageGeneration, error) {// 查找角色var character models.Characterif err := s.db.Where("id = ?", characterID).First(&character).Error; err != nil {@@ -319,7 +319,12 @@ func (s *CharacterLibraryService) GenerateCharacterImage(characterID string, imaprompt += ", studio lighting, professional photography"// 添加质量和风格要求- prompt += ", high quality, detailed, anime style, character design"+ if style != "" {+ prompt += ", " + style + ", high quality, detailed, character design"+ } else {+ // 默认风格+ prompt += ", high quality, detailed, anime style, character design"+ }prompt += ", no complex background, no scenery, focus on character"// 调用图片生成服务@@ -454,7 +459,7 @@ func (s *CharacterLibraryService) BatchGenerateCharacterImages(characterIDs []stfor _, characterID := range characterIDs {// 为每个角色启动单独的 goroutinego func(charID string) {- imageGen, err := s.GenerateCharacterImage(charID, imageService, modelName)+ imageGen, err := s.GenerateCharacterImage(charID, imageService, modelName, "") // 批量生成暂不支持自定义风格,使用默认值if err != nil {s.log.Errorw("Failed to generate character image in batch","character_id", charID,diff --git a/application/services/image_generation_service.go b/application/services/image_generation_service.goindex 7483086..6d00bce 100644--- a/application/services/image_generation_service.go+++ b/application/services/image_generation_service.go@@ -648,7 +648,7 @@ func (s *ImageGenerationService) GetScencesForEpisode(episodeID string) ([]*mode}// ExtractBackgroundsForEpisode 从剧本内容中提取场景并保存到项目级别数据库-func (s *ImageGenerationService) ExtractBackgroundsForEpisode(episodeID string, model string) ([]*models.Scene, error) {+func (s *ImageGenerationService) ExtractBackgroundsForEpisode(episodeID string, model string, style string) ([]*models.Scene, error) {var episode models.Episodeif err := s.db.Preload("Storyboards").First(&episode, episodeID).Error; err != nil {return nil, fmt.Errorf("episode not found")@@ -663,7 +663,7 @@ func (s *ImageGenerationService) ExtractBackgroundsForEpisode(episodeID string,dramaID := episode.DramaID// 使用AI从剧本内容中提取场景- backgroundsInfo, err := s.extractBackgroundsFromScript(*episode.ScriptContent, dramaID, model)+ backgroundsInfo, err := s.extractBackgroundsFromScript(*episode.ScriptContent, dramaID, model, style)if err != nil {s.log.Errorw("Failed to extract backgrounds from script", "error", err)return nil, err@@ -719,7 +719,7 @@ func (s *ImageGenerationService) ExtractBackgroundsForEpisode(episodeID string,}// extractBackgroundsFromScript 从剧本内容中使用AI提取场景信息-func (s *ImageGenerationService) extractBackgroundsFromScript(scriptContent string, dramaID uint, model string) ([]BackgroundInfo, error) {+func (s *ImageGenerationService) extractBackgroundsFromScript(scriptContent string, dramaID uint, model string, style string) ([]BackgroundInfo, error) {if scriptContent == "" {return []BackgroundInfo{}, nil}@@ -742,7 +742,7 @@ func (s *ImageGenerationService) extractBackgroundsFromScript(scriptContent stri}// 使用国际化提示词- systemPrompt := s.promptI18n.GetSceneExtractionPrompt()+ systemPrompt := s.promptI18n.GetSceneExtractionPrompt(style)contentLabel := s.promptI18n.FormatUserPrompt("script_content_label")// 根据语言构建不同的格式说明@@ -876,7 +876,7 @@ Please strictly follow the JSON format and ensure all fields use English.`}// extractBackgroundsWithAI 使用AI智能分析场景并提取唯一背景-func (s *ImageGenerationService) extractBackgroundsWithAI(storyboards []models.Storyboard) ([]BackgroundInfo, error) {+func (s *ImageGenerationService) extractBackgroundsWithAI(storyboards []models.Storyboard, style string) ([]BackgroundInfo, error) {if len(storyboards) == 0 {return []BackgroundInfo{}, nil}@@ -906,7 +906,7 @@ func (s *ImageGenerationService) extractBackgroundsWithAI(storyboards []models.S}// 使用国际化提示词- systemPrompt := s.promptI18n.GetSceneExtractionPrompt()+ systemPrompt := s.promptI18n.GetSceneExtractionPrompt(style)storyboardLabel := s.promptI18n.FormatUserPrompt("storyboard_list_label")// 根据语言构建不同的提示词diff --git a/application/services/prompt_i18n.go b/application/services/prompt_i18n.goindex 5f4fafd..5511ab6 100644--- a/application/services/prompt_i18n.go+++ b/application/services/prompt_i18n.go@@ -144,9 +144,23 @@ func (p *PromptI18n) GetStoryboardSystemPrompt() string {}// GetSceneExtractionPrompt 获取场景提取提示词-func (p *PromptI18n) GetSceneExtractionPrompt() string {+func (p *PromptI18n) GetSceneExtractionPrompt(style string) string {+ // 如果未指定风格,使用配置中的默认风格+ if style == "" {+ style = p.config.Style.DefaultSceneStyle+ }else{+ // 默认风格加style+ style = p.config.Style.DefaultSceneStyle + ", " + style+ }+ // 如果配置也没有,使用硬编码默认值+ if style == "" {+ style = "Modern Japanese anime style"+ }+ // default_image_ratio+ imageRatio := p.config.Style.DefaultImageRatio+if p.IsEnglish() {- return `[Task] Extract all unique scene backgrounds from the script+ return fmt.Sprintf(`[Task] Extract all unique scene backgrounds from the script[Requirements]1. Identify all different scenes (location + time combinations) in the script@@ -157,6 +171,9 @@ func (p *PromptI18n) GetSceneExtractionPrompt() string {- Detailed description of scene, time, atmosphere, style- Must explicitly specify "no people, no characters, empty scene"- Must match the drama's genre and tone+ - **Style Requirement**: %s+ - **Image Ratio**: %s+[Output Format]**CRITICAL: Return ONLY a valid JSON array. Do NOT include any markdown code blocks, explanations, or other text. Start directly with [ and end with ].**@@ -164,10 +181,10 @@ func (p *PromptI18n) GetSceneExtractionPrompt() string {Each element containing:- location: Location (e.g., "luxurious office")- time: Time period (e.g., "afternoon")-- prompt: Complete English image generation prompt (pure background, explicitly stating no people)`+- prompt: Complete English image generation prompt (pure background, explicitly stating no people)`, style,imageRatio)}- return `【任务】从剧本中提取所有唯一的场景背景+ return fmt.Sprintf(`【任务】从剧本中提取所有唯一的场景背景【要求】1. 识别剧本中所有不同的场景(地点+时间组合)@@ -178,6 +195,8 @@ Each element containing:- 详细描述场景、时间、氛围、风格- 必须明确说明"无人物、无角色、空场景"- 要符合剧本的题材和氛围+ - **风格要求**:%s+ - **图片比例**:%s【输出格式】**重要:必须只返回纯JSON数组,不要包含任何markdown代码块、说明文字或其他内容。直接以 [ 开头,以 ] 结尾。**@@ -185,13 +204,15 @@ Each element containing:每个元素包含:- location:地点(如"豪华办公室")- time:时间(如"下午")-- prompt:完整的中文图片生成提示词(纯背景,明确说明无人物)`+- prompt:完整的中文图片生成提示词(纯背景,明确说明无人物)`, style,imageRatio)}// GetFirstFramePrompt 获取首帧提示词func (p *PromptI18n) GetFirstFramePrompt() string {+ style := p.config.Style.DefaultStyle+ imageRatio := p.config.Style.DefaultImageRatioif p.IsEnglish() {- return `You are a professional image generation prompt expert. Please generate prompts suitable for AI image generation based on the provided shot information.+ return fmt.Sprintf(`You are a professional image generation prompt expert. Please generate prompts suitable for AI image generation based on the provided shot information.Important: This is the first frame of the shot - a completely static image showing the initial state before the action begins.@@ -201,14 +222,14 @@ Key Points:3. Describe the character's initial posture, position, and expression4. Can include scene atmosphere and environmental details5. Shot type determines composition and framing-+- **Style Requirement**: %s+- **Image Ratio**: %sOutput Format:Return a JSON object containing:- prompt: Complete English image generation prompt (detailed description, suitable for AI image generation)-- description: Simplified Chinese description (for reference)`- }+- description: Simplified Chinese description (for reference)`,style,imageRatio)}- return `你是一个专业的图像生成提示词专家。请根据提供的镜头信息,生成适合用于AI图像生成的提示词。+ return fmt.Sprintf(`你是一个专业的图像生成提示词专家。请根据提供的镜头信息,生成适合用于AI图像生成的提示词。重要:这是镜头的首帧 - 一个完全静态的画面,展示动作发生之前的初始状态。@@ -218,17 +239,19 @@ Return a JSON object containing:3. 描述角色的初始姿态、位置和表情4. 可以包含场景氛围和环境细节5. 景别决定构图和取景范围-+- **风格要求**:%s+- **图片比例**:%s输出格式:返回一个JSON对象,包含:- prompt:完整的中文图片生成提示词(详细描述,适合AI图像生成)-- description:简化的中文描述(供参考)`+- description:简化的中文描述(供参考)`,style,imageRatio)}-// GetKeyFramePrompt 获取关键帧提示词func (p *PromptI18n) GetKeyFramePrompt() string {+ style := p.config.Style.DefaultStyle+ imageRatio := p.config.Style.DefaultImageRatioif p.IsEnglish() {- return `You are a professional image generation prompt expert. Please generate prompts suitable for AI image generation based on the provided shot information.+ return fmt.Sprintf(`You are a professional image generation prompt expert. Please generate prompts suitable for AI image generation based on the provided shot information.Important: This is the key frame of the shot - capturing the most intense and exciting moment of the action.@@ -238,14 +261,14 @@ Key Points:3. Emphasize dynamic tension4. Show character actions and expressions at their climax5. Can include motion blur or dynamic effects-+- **Style Requirement**: %s+- **Image Ratio**: %sOutput Format:Return a JSON object containing:- prompt: Complete English image generation prompt (detailed description, suitable for AI image generation)-- description: Simplified Chinese description (for reference)`- }+- description: Simplified Chinese description (for reference)`,style,imageRatio)}- return `你是一个专业的图像生成提示词专家。请根据提供的镜头信息,生成适合用于AI图像生成的提示词。+ return fmt.Sprintf(`你是一个专业的图像生成提示词专家。请根据提供的镜头信息,生成适合用于AI图像生成的提示词。重要:这是镜头的关键帧 - 捕捉动作最激烈、最精彩的瞬间。@@ -255,17 +278,20 @@ Return a JSON object containing:3. 强调动态张力4. 展示角色动作和表情的高潮状态5. 可以包含动作模糊或动态效果-+- **风格要求**:%s+- **图片比例**:%s输出格式:返回一个JSON对象,包含:- prompt:完整的中文图片生成提示词(详细描述,适合AI图像生成)-- description:简化的中文描述(供参考)`+- description:简化的中文描述(供参考)`,style,imageRatio)}// GetLastFramePrompt 获取尾帧提示词func (p *PromptI18n) GetLastFramePrompt() string {+ style := p.config.Style.DefaultStyle+ imageRatio := p.config.Style.DefaultImageRatioif p.IsEnglish() {- return `You are a professional image generation prompt expert. Please generate prompts suitable for AI image generation based on the provided shot information.+ return fmt.Sprintf(`You are a professional image generation prompt expert. Please generate prompts suitable for AI image generation based on the provided shot information.Important: This is the last frame of the shot - a static image showing the final state and result after the action ends.@@ -275,14 +301,15 @@ Key Points:3. Describe character's final posture and expression after action4. Emphasize emotional state after action5. Capture the calm moment after action ends-+- **Style Requirement**: %s+- **Image Ratio**: %sOutput Format:Return a JSON object containing:- prompt: Complete English image generation prompt (detailed description, suitable for AI image generation)-- description: Simplified Chinese description (for reference)`+- description: Simplified Chinese description (for reference)`,style,imageRatio)}- return `你是一个专业的图像生成提示词专家。请根据提供的镜头信息,生成适合用于AI图像生成的提示词。+ return fmt.Sprintf(`你是一个专业的图像生成提示词专家。请根据提供的镜头信息,生成适合用于AI图像生成的提示词。重要:这是镜头的尾帧 - 一个静态画面,展示动作结束后的最终状态和结果。@@ -292,11 +319,12 @@ Return a JSON object containing:3. 描述角色在动作完成后的姿态和表情4. 强调动作后的情绪状态5. 捕捉动作结束后的平静瞬间-+- **风格要求**:%s+- **图片比例**:%s输出格式:返回一个JSON对象,包含:- prompt:完整的中文图片生成提示词(详细描述,适合AI图像生成)-- description:简化的中文描述(供参考)`+- description:简化的中文描述(供参考)`,style,imageRatio)}// GetOutlineGenerationPrompt 获取大纲生成提示词@@ -344,8 +372,10 @@ Return a JSON object containing:// GetCharacterExtractionPrompt 获取角色提取提示词func (p *PromptI18n) GetCharacterExtractionPrompt() string {+ style := p.config.Style.DefaultStyle+ imageRatio := p.config.Style.DefaultImageRatioif p.IsEnglish() {- return `You are a professional character analyst, skilled at extracting and analyzing character information from scripts.+ return fmt.Sprintf(`You are a professional character analyst, skilled at extracting and analyzing character information from scripts.Your task is to extract and organize detailed character settings for all characters appearing in the script based on the provided script content.@@ -359,13 +389,14 @@ Requirements:- description: Background story and character relationships (100-200 words)3. Appearance must be detailed enough for AI image generation, including: gender, age, body type, facial features, hairstyle, clothing style, etc.4. Main characters require more detailed descriptions, supporting characters can be simplified-+- **Style Requirement**: %s+- **Image Ratio**: %sOutput Format:**CRITICAL: Return ONLY a valid JSON array. Do NOT include any markdown code blocks, explanations, or other text. Start directly with [ and end with ].**-Each element is a character object containing the above fields.`+Each element is a character object containing the above fields.`,style,imageRatio)}- return `你是一个专业的角色分析师,擅长从剧本中提取和分析角色信息。+ return fmt.Sprintf(`你是一个专业的角色分析师,擅长从剧本中提取和分析角色信息。你的任务是根据提供的剧本内容,提取并整理剧中出现的所有角色的详细设定。@@ -379,10 +410,11 @@ Each element is a character object containing the above fields.`- description: 背景故事和角色关系(100-200字)3. 外貌描述要足够详细,适合AI生成图片,包括:性别、年龄、体型、面部特征、发型、服装风格等4. 主要角色需要更详细的描述,次要角色可以简化-+- **风格要求**:%s+- **图片比例**:%s输出格式:**重要:必须只返回纯JSON数组,不要包含任何markdown代码块、说明文字或其他内容。直接以 [ 开头,以 ] 结尾。**-每个元素是一个角色对象,包含上述字段。`+每个元素是一个角色对象,包含上述字段。`,style,imageRatio)}// GetEpisodeScriptPrompt 获取分集剧本生成提示词diff --git a/configs/config.example.yaml b/configs/config.example.yamlindex 080e768..62964fc 100644--- a/configs/config.example.yaml+++ b/configs/config.example.yaml@@ -27,3 +27,8 @@ ai:default_text_provider: "openai"default_image_provider: "openai"default_video_provider: "doubao"+style:+ default_style: "masterpiece, best quality, 8k, modern Japanese anime style"+ default_role_style: "Modern Japanese anime style, cel-shaded. The layout features a large full-body main illustration and three-view orthographic references (Front, Side, Back) neatly arranged on a single horizontal white canvas, high quality, detailed, anime style, character design, no complex background, no scenery, focus on character"+ default_scene_style: "Modern Japanese anime style, cel-shaded. The layout features a large main anime background scene illustration and three-view orthographic references (Front, Side, Back) of the scene neatly arranged on a single horizontal white canvas. "+ default_image_ratio: "16:9"diff --git a/pkg/config/config.go b/pkg/config/config.goindex 081db5d..4ccee66 100644--- a/pkg/config/config.go+++ b/pkg/config/config.go@@ -12,6 +12,7 @@ type Config struct {Database DatabaseConfig `mapstructure:"database"`Storage StorageConfig `mapstructure:"storage"`AI AIConfig `mapstructure:"ai"`+ Style StyleConfig `mapstructure:"style"`}type AppConfig struct {@@ -54,6 +55,18 @@ type AIConfig struct {DefaultVideoProvider string `mapstructure:"default_video_provider"`}+type StyleConfig struct {+ // 默认主风格+ DefaultStyle string `mapstructure:"default_style"`+ // 默认角色风格+ DefaultRoleStyle string `mapstructure:"default_role_style"`+ // 默认场景风格+ DefaultSceneStyle string `mapstructure:"default_scene_style"`++ // 默认图片比例+ DefaultImageRatio string `mapstructure:"default_image_ratio"`+}+func LoadConfig() (*Config, error) {viper.SetConfigName("config")viper.SetConfigType("yaml")