generateLite2dGeneralVideo
Create digital human videos from uploaded recordings using general lip-sync animation for basic video production needs.
Instructions
#工具说明:根据上传真人录制的视频生成数字人像,仅可用于基础视频制作,数字人使用通用口型驱动。
样例1:
用户输入:用fileid为xxx的视频文件,生成数字人,命名为“zhangsan”,是个男生的形象。 思考过程: 1.用户想要生成数字人像,需要使用“generateLite2dGeneralVideo”工具。 2.工具需要参数,name,gender,keepBackground,templateVideoId四个参数。 3.用户提到了fileID为xxx,所以templateVideoid的值为xxx,name为zhangsan,男生的形象,gender的值为male,未提到是否保留背景所以keepBackground默认为false。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | No | 名称 | |
| gender | No | 性别 | FEMALE |
| templateVideoId | No | 视频:视频文件/底板视频,来自 uploadFiles 返回的fileId | |
| keepBackground | No | 是否保留背景 | |
| maskVideoId | No | 遮罩,底板视频对应的mask视频 |
Implementation Reference
- Main handler function that implements the core logic of the 'generateLite2dGeneralVideo' tool by constructing a Lite2dGenerateRequest and invoking the DH API client.
async def generateLite2dGeneralVideo( name: Annotated[str, Field(description="名称", default=None)], gender: Annotated[Literal["MALE", "FEMALE"], Field(description="性别", default="FEMALE")], templateVideoId: Annotated[str, Field(description="视频:视频文件/底板视频,来自 uploadFiles 返回的fileId", default=None)], keepBackground: Annotated[bool, Field(description="是否保留背景", default=False)], maskVideoId: Annotated[str, Field(description="遮罩,底板视频对应的mask视频", default=None)] ) -> MCPLite2DGenerateResponse: """ Generate a lite 2d general avatar video from template video file via the DH API. Args: name (str): 数字人名称 gender (str): 性别,MALE 或 FEMALE,来自 getGender keepBackground (bool): 是否保留背景 templateVideoId (str): 视频,视频文件,底板视频,来自 uploadFiles 返回的fileId maskVideoId (str): 遮罩,底板视频对应的mask视频,可选,来自 uploadFiles 返回的fileId """ try: client = await getDhClient() req = Lite2dGenerateRequest( name=name, customizeType="LITE_2D_GENERAL", gender=gender, keepBackground=keepBackground, templateVideoId=templateVideoId, maskVideoId=maskVideoId if maskVideoId != "" else None, ) ret = await client.generate_lite2d_video(req) return ret except Exception as e: return MCPLite2DGenerateResponse(error=str(e)) - src/mcp_server_baidu_digitalhuman/dhserver.py:417-429 (registration)MCP tool registration decorator defining the tool name, description, and input parameters via type annotations.
@mcp.tool( name="generateLite2dGeneralVideo", description=( """ #工具说明:根据上传真人录制的视频生成数字人像,仅可用于基础视频制作,数字人使用通用口型驱动。 # 样例1: 用户输入:用fileid为xxx的视频文件,生成数字人,命名为“zhangsan”,是个男生的形象。 思考过程: 1.用户想要生成数字人像,需要使用“generateLite2dGeneralVideo”工具。 2.工具需要参数,name,gender,keepBackground,templateVideoId四个参数。 3.用户提到了fileID为xxx,所以templateVideoid的值为xxx,name为zhangsan,男生的形象,gender的值为male,未提到是否保留背景所以keepBackground默认为false。 """) ) - Pydantic model defining the input schema (Lite2dGenerateRequest) used in the tool request to the DH API.
class Lite2dGenerateRequest(BaseModel): """ 通用口型驱动请求 """ name: str customizeType: str gender: str keepBackground: bool = True templateVideoId: str lipVideoId: Optional[str] = None maskVideoId: Optional[str] = None callbackUrl: Optional[str] = None - Pydantic model for the MCP response schema (MCPLite2DGenerateResponse) returned by the tool.
class MCPLite2DGenerateResponse(BaseDHResponse): """ MCP 2D小样本数字人响应 """ figureId: Optional[str] = None - DHApiClient helper method that performs the actual HTTP API call to generate the Lite 2D video.
async def generate_lite2d_video(self, video_request: Lite2dGenerateRequest) -> MCPLite2DGenerateResponse: """Generate a lite 2d avatar video from template video file via the DH API.""" async def api_call(): return await self._make_request( "api/digitalhuman/open/v1/figure/lite2d/train", method="POST", data=video_request.model_dump() ) ret = await self._handle_api_request( api_call=api_call, response_model_class=CommonDHResponse, mcp_response_class=MCPLite2DGenerateResponse, error_msg="No video generation data returned.", figureId=lambda d: d.get("figureId"), ) return ret