scene-digit-human/main.py
2024-12-09 08:51:09 +08:00

76 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- encoding: utf-8 -*-
'''
@Email : liaoxiju@inspur.com
'''
import os
import re
import sys
sys.path.append("../")
sys.path.append("../..")
import datetime
from datetime import timedelta
import logging
import yaml
import uvicorn
from common import HAIRUO_ENV
from common import HairuoEnv
from fastapi import FastAPI, Request
from agent_common_utils.logger import get_logger
from agent_common_utils.function_monitor import log_function_call
from model_utils import audio_driven_video
logger = get_logger("digithuman")
dh_audio_driven_video = log_function_call(logger)(audio_driven_video)
app = FastAPI()
@app.post("/hairuo/digithuman")
async def digithuman(request: Request, req: dict):
'''
对输入文本文本描述生成wav音频然后调用dh-webui生成视频
'''
logger.info("<digithuman> Verification authorization.")
body_data = await request.body()
body_data = body_data.decode("utf-8")
logger.info("<body> {}".format(body_data))
logger.info("<digithuman> input text.")
try:
app_id = req.get("app_id")
prompt = req.get("text")
##edge tts生成音频上传oss获取音频url。 TODO:待实现
wav_url = 'xxx'
video_url, code = dh_audio_driven_video(wav_url)
if not code:
logger.info("<digithuman> dh model error")
resp = {
"code": "1",
"message": "dh model error",
"result": ''
}
return resp
resp = {
"app_id": app_id,
"code": "0",
"message": "success",
"result": video_url
}
return resp
except:
logger.info("<digithuman> model error")
resp = {
"code": "1",
"message": "dh model call error",
"result": ""
}
return resp
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=14040)