| | |
| | | """ |
| | | 统一视频生成客户端 |
| | | 根据 model 名称自动路由到对应后端: |
| | | - wan* → WanVideoClient (DashScope VideoSynthesis) |
| | | - wan* → DashscopeVideoClient (DashScope VideoSynthesis) |
| | | - jimeng* → JiMengClient (火山引擎即梦) |
| | | - kling* → KlingVideoClient (可灵 AI) |
| | | """ |
| | |
| | | from config import Config |
| | | |
| | | try: |
| | | from tool.video_wan import WanVideoClient |
| | | from tool.video_dashscope import DashscopeVideoClient |
| | | from tool.image_jimeng import JiMengClient |
| | | from tool.video_kling import KlingVideoClient |
| | | from tool.video_seedance import SeedanceVideoClient |
| | | except ImportError: |
| | | from video_wan import WanVideoClient |
| | | from video_dashscope import DashscopeVideoClient |
| | | from image_jimeng import JiMengClient |
| | | from video_kling import KlingVideoClient |
| | | from video_seedance import SeedanceVideoClient |
| | |
| | | kling_base_url: Optional[str] = None, |
| | | ): |
| | | # 万象客户端 |
| | | self.wan_client = WanVideoClient( |
| | | self.Dashscope_client = DashscopeVideoClient( |
| | | api_key=dashscope_api_key, |
| | | base_url=dashscope_base_url, |
| | | ) |
| | |
| | | prompt: str, |
| | | image_path: str, |
| | | save_path: str, |
| | | model: str = "wan2.6-i2v-flash", |
| | | model: str = "wan2.7-i2v", |
| | | duration: int = 5, |
| | | shot_type: str = "multi", |
| | | sound: str = "", |
| | |
| | | RuntimeError: 生成或下载失败 |
| | | """ |
| | | if not model: |
| | | model = "wan2.6-i2v-flash" |
| | | model = "wan2.7-i2v" |
| | | |
| | | if Config.PRINT_MODEL_INPUT: |
| | | print("---- VIDEO GENERATION REQUEST ----") |
| | |
| | | return self._generate_kling(prompt, image_path, save_path, model, duration, sound) |
| | | elif "seedance" in model_lower: |
| | | return self._generate_seedance(prompt, image_path, save_path, model, duration) |
| | | else: |
| | | elif "wan" in model_lower or "happyhorse" in model_lower: |
| | | return self._generate_wan(prompt, image_path, save_path, model, duration, shot_type) |
| | | else: |
| | | raise ValueError(f"未知的视频生成模型: {model}") |
| | | |
| | | def _generate_wan( |
| | | self, |
| | |
| | | ) -> str: |
| | | """通过万象模型生成视频""" |
| | | logger.info(f"VideoClient: 路由至万象 model={model}") |
| | | return self.wan_client.generate_video( |
| | | return self.Dashscope_client.generate_video( |
| | | prompt=prompt, |
| | | image_path=image_path, |
| | | save_path=save_path, |