asset_script_generation.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Copyright (C) 2025 AIDC-AI
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS,
  9. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. # See the License for the specific language governing permissions and
  11. # limitations under the License.
  12. """
  13. Asset-based video script generation prompt
  14. For generating video scripts based on user-provided assets.
  15. """
  16. ASSET_SCRIPT_GENERATION_PROMPT = """You are a professional video script creator. Based on the user's video intent and available assets, generate a {duration}-second video script. Before doing so, you need to detect the user's input language - if it's English, then all copy must be in English. Strictly follow the user's input language type as the standard, ensuring consistent and corresponding copy!
  17. ## Requirements
  18. {title_section}- Video Intent: {intent}
  19. - Target Duration: {duration} seconds
  20. ## Available Assets (use exact paths in output)
  21. {assets_text}
  22. ## Creation Guidelines
  23. 1. Strictly output copy according to the user's input language type - if input is English, output must be English, and so on
  24. 2. Determine the number of scenes based on target duration (typically 5-15 seconds per scene)
  25. 3. Assign one asset from available assets to each scene
  26. 4. Each scene can contain 1-3 narration sentences
  27. 5. Try to use all available assets, but assets can be reused if needed
  28. 6. Total duration of all scenes should approximately equal {duration} seconds
  29. {title_instruction}
  30. ## Language Consistency Requirements (Strictly Enforce)
  31. - Narration language must match the user's input video intent
  32. - If video intent is in Chinese, narration must be in Chinese
  33. - If video intent is in English, narration must be in English
  34. - Unless the video intent explicitly specifies an output language, strictly follow the original language of the intent
  35. ## Output Requirements
  36. Provide for each scene:
  37. - scene_number: Scene number (starting from 1)
  38. - asset_path: Exact path selected from available assets list
  39. - narrations: Array containing 1-3 narration sentences
  40. - duration: Estimated duration (seconds)
  41. Now please begin generating the video script:"""
  42. def build_asset_script_prompt(
  43. intent: str,
  44. duration: int,
  45. assets_text: str,
  46. title: str = ""
  47. ) -> str:
  48. """
  49. Build asset-based script generation prompt
  50. Args:
  51. intent: Video intent/purpose
  52. duration: Target duration in seconds
  53. assets_text: Formatted text of available assets with descriptions
  54. title: Optional video title
  55. Returns:
  56. Formatted prompt
  57. """
  58. title_section = f"- Video Title: {title}\n" if title else ""
  59. title_instruction = f"6. Narration content should be consistent with the video title: {title}\n" if title else ""
  60. return ASSET_SCRIPT_GENERATION_PROMPT.format(
  61. duration=duration,
  62. title_section=title_section,
  63. intent=intent,
  64. assets_text=assets_text,
  65. title_instruction=title_instruction
  66. )