Ikaros-521 / digital_human_video_player

带HTTP API的数字人视频播放器,使用gradio api对接Easy-Wav2Lip、Sadtalker、GeneFacePlusPlus、MuseTalk,也可以用于播放本地视频
https://www.bilibili.com/video/BV1iW421P7si
GNU General Public License v3.0
85 stars 22 forks source link

api调用时候报错InvalidApiNameError #4

Open Xingeqwd opened 1 month ago

Xingeqwd commented 1 month ago

这边是linux,x86平台

确认了wav2lip正常(毕竟是不久前刚刚搭的),api页面也能进得去,网络也都是通的, 上github对了一下,文件也都是对的 但就是莫名其妙地报了这个错,太怪了

Google查了一通,发现竟然没有跟我一样的, 看到网上说,函数调用要用fn_index,api调用可以用api_name。。。"gradio_api_type"那边也的确是这样配的 ——毕竟其他人都没出问题啊,证明肯定不是程序的问题,但是文件也没动过,wav2lip又挺正常。。。 文件肯定也是存在的,权限之类的也没问题

至少可以确定,应该肯定是gradio方面问题了。。。

—————————— 附POST请求语句

curl -H "Content-Type: application/json" -X POST -d  '{"type":"easy_wav2lip","audio_path":"/data2/Luna-AI-Vtuber/out/edge_tts_5.mp3"}'  http://192.168.188.xxx:28191/show

api_server.py那边的附近段落如下(22-58行附近)

def get_video(type: str, data: dict):
    from gradio_client import Client

    try:
        if type == "easy_wav2lip":
            client = Client(config.get("easy_wav2lip", "api_ip_port"))
            result = client.predict(
                config.get("easy_wav2lip", "video_file"),   # filepath  in '支持图片、视频格式' File component
                data['audio_path'], # filepath  in '支持mp3、wav格式' Audio component
                config.get("easy_wav2lip", "quality"),  # Literal['Fast', 'Improved', 'Enhanced', 'Experimental']  in '视频质量选项' Radio component
                config.get("easy_wav2lip", "output_height"),    # Literal['full resolution', 'half resolution']  in '分辨率选项' Radio component
                config.get("easy_wav2lip", "wav2lip_version"),  # Literal['Wav2Lip', 'Wav2Lip_GAN']  in 'Wav2Lip版本选项' Radio component
                config.get("easy_wav2lip", "use_previous_tracking_data"),   # Literal['True', 'False']  in '启用追踪旧数据' Radio component
                config.get("easy_wav2lip", "nosmooth"), # Literal['True', 'False']  in '启用脸部平滑' Radio component
                config.get("easy_wav2lip", "u"),    # float (numeric value between -100 and 100) in '嘴部mask上边缘' Slider component
                config.get("easy_wav2lip", "d"),    # float (numeric value between -100 and 100) in '嘴部mask下边缘' Slider component
                config.get("easy_wav2lip", "l"),    # float (numeric value between -100 and 100) in '嘴部mask左边缘' Slider component
                config.get("easy_wav2lip", "r"),    # float (numeric value between -100 and 100) in '嘴部mask右边缘' Slider component
                config.get("easy_wav2lip", "size"), # float (numeric value between -10 and 10) in 'mask尺寸' Slider component
                config.get("easy_wav2lip", "feathering"),   # float (numeric value between -100 and 100) in 'mask羽化' Slider component
                config.get("easy_wav2lip", "mouth_tracking"),   # Literal['True', 'False']  in '启用mask嘴部跟踪' Radio component
                config.get("easy_wav2lip", "debug_mask"),   # Literal['True', 'False']  in '启用mask调试' Radio component
                config.get("easy_wav2lip", "batch_process"),    # Literal['False']  in '批量处理多个视频' Radio component
                api_name="/execute_pipeline"
            )

            logging.info(f'合成成功,生成在:{result[0]["video"]}')

            return result[0]["video"]
        elif type == "sadtalker":
            client = Client(config.get("sadtalker", "api_ip_port"))

            if config.get("sadtalker", "gradio_api_type") == "api_name":
                result = client.predict(
                    config.get("sadtalker", "img_file"),    # filepath  in 'Source image' Image component
                    data['audio_path'], # filepath  in 'Input audio' Audio component
                    config.get("sadtalker", "preprocess"),  # Literal[crop, resize, full, extcrop, extfull]  in 'preprocess' Radio component
                    config.get("sadtalker", "still_mode"),  # bool  in 'Still Mode (fewer head motion, works with preprocess `full`)' Checkbox component
                    config.get("sadtalker", "GFPGAN"),  # bool  in 'GFPGAN as Face enhancer' Checkbox component
                    config.get("sadtalker", "batch_size"),  # float (numeric value between 0 and 10) in 'batch size in generation' Slider component

如果注释掉那一行,会变成

2024-05-10 18:13:27 - .../digital_human_video_player/api_server.py[line:110] - ERROR: Traceback (most recent call last):
  File ".../digital_human_video_player/api_server.py", line 28, in get_video
    result = client.predict(
  File "/usr/local/lib/python3.10/dist-packages/gradio_client/client.py", line 399, in predict
    inferred_fn_index = self._infer_fn_index(api_name, fn_index)
  File "/usr/local/lib/python3.10/dist-packages/gradio_client/client.py", line 716, in _infer_fn_index
    raise ValueError(
ValueError: This Gradio app might have multiple endpoints. Please specify an `api_name` or `fn_index`

以及最新一次的日志

2024-05-10 18:27:51 - .../digital_human_video_player/api_server.py[line:162] - INFO: 收到数据:{'type': 'easy_wav2lip', 'audio_path': '.../edge_tts_5.mp3'}
Loaded as API: http://127.0.0.1:27861/ ✔
2024-05-10 18:27:51 - /usr/local/lib/python3.10/dist-packages/httpx/_client.py[line:1027] - INFO: HTTP Request: GET http://127.0.0.1:27861/config "HTTP/1.1 200 OK"
2024-05-10 18:27:51 - /data2/digital_human_video_player/api_server.py[line:110] - ERROR: Traceback (most recent call last):
  File "/data2/digital_human_video_player/api_server.py", line 28, in get_video
    result = client.predict(
  File "/usr/local/lib/python3.10/dist-packages/gradio_client/client.py", line 399, in predict
    inferred_fn_index = self._infer_fn_index(api_name, fn_index)
  File "/usr/local/lib/python3.10/dist-packages/gradio_client/client.py", line 696, in _infer_fn_index
    raise ValueError(error_message)
ValueError: Cannot find a function with `api_name`: /execute_pipeline.

感谢各位大佬!各位大佬辛苦了,恭喜发财

Ikaros-521 commented 1 month ago

看着估计 别用api name 改fn index调用就行

Xingeqwd commented 1 month ago

看着估计 别用api name 改fn index调用就行

不会改啊,大佬,文档翻不出什么头绪 应该不会只是改api name吧,右边带的内容不知要写什么?

Ikaros-521 commented 1 month ago

看着估计 别用api name 改fn index调用就行

不会改啊,大佬,文档翻不出什么头绪 应该不会只是改api name吧,右边带的内容不知要写什么?

你不是已经截出源码了吗 在gradio api打开例程 适配一下就行了

Xingeqwd commented 1 month ago

看着估计 别用api name 改fn index调用就行

不会改啊,大佬,文档翻不出什么头绪 应该不会只是改api name吧,右边带的内容不知要写什么?

你不是已经截出源码了吗 在gradio api打开例程 适配一下就行了

大佬,不好意思,这几个词分开看都看得懂,加在一起就看不明白, 这两个应该没猜错: 你指的源码是那段出问题的吧,适配是把他改成fn index 有一个事情不太清楚,请教一下: 例程不知是指的什么?

Ikaros-521 commented 1 month ago

看着估计 别用api name 改fn index调用就行

不会改啊,大佬,文档翻不出什么头绪 应该不会只是改api name吧,右边带的内容不知要写什么?

你不是已经截出源码了吗 在gradio api打开例程 适配一下就行了

大佬,不好意思,这几个词分开看都看得懂,加在一起就看不明白, 这两个应该没猜错: 你指的源码是那段出问题的吧,适配是把他改成fn index 有一个事情不太清楚,请教一下: 例程不知是指的什么?

webui 最底下 api打开有文档

Xingeqwd commented 1 month ago

看着估计 别用api name 改fn index调用就行

不会改啊,大佬,文档翻不出什么头绪 应该不会只是改api name吧,右边带的内容不知要写什么?

你不是已经截出源码了吗 在gradio api打开例程 适配一下就行了

大佬,不好意思,这几个词分开看都看得懂,加在一起就看不明白, 这两个应该没猜错: 你指的源码是那段出问题的吧,适配是把他改成fn index 有一个事情不太清楚,请教一下: 例程不知是指的什么?

webui 最底下 api打开有文档

是了,我还以为是gradio的官方文档,会错意了

因为digital_human这边的port只有一个,放视频的界面,没有webui 我去wav2lip的webui那边找到了api文档

不过不知道适配怎么做,还是来请教一下。。。 我有试过直接把api_name改成fn_index带个0,不过可想而知的肯定是报错了 要把这么一大段塞到api_server.py里面,想不到什么好办法(还是gradio学的不到家,贻笑大方了)

(如图,文字下列) ———————————— image ————————————

fn_index: 0
copy
from gradio_client import Client

client = Client("http://192.168.188.223:27861/")
result = client.predict(
        "https://github.com/gradio-app/gradio/raw/main/test/test_files/sample_file.pdf",    # str (filepath on your computer (or URL) of file) in 'Video or Image' File component
        "https://github.com/gradio-app/gradio/raw/main/test/test_files/sample_file.pdf",    # str (filepath on your computer (or URL) of file) in 'Audio' File component
        "wav2lip",  # str  in 'Checkpoint' Radio component
        True,   # bool  in 'No Smooth' Checkbox component
        1,  # int | float (numeric value between 1 and 4) in 'Resize Factor' Slider component
        0,  # int | float (numeric value between 0 and 50) in 'Pad Top' Slider component
        0,  # int | float (numeric value between 0 and 50) in 'Pad Bottom (Often increasing this to 20 allows chin to be included' Slider component
        0,  # int | float (numeric value between 0 and 50) in 'Pad Left' Slider component
        0,  # int | float (numeric value between 0 and 50) in 'Pad Right' Slider component
        fn_index=0
)
print(result)
Return Type(s)
# str (filepath on your computer (or URL) of file) representing output in 'value_18' Video component

—————————— 咳咳咳,感谢大佬,大佬辛苦了,大佬威武——

Ikaros-521 commented 1 month ago

看着估计 别用api name 改fn index调用就行

不会改啊,大佬,文档翻不出什么头绪 应该不会只是改api name吧,右边带的内容不知要写什么?

你不是已经截出源码了吗 在gradio api打开例程 适配一下就行了

大佬,不好意思,这几个词分开看都看得懂,加在一起就看不明白, 这两个应该没猜错: 你指的源码是那段出问题的吧,适配是把他改成fn index 有一个事情不太清楚,请教一下: 例程不知是指的什么?

webui 最底下 api打开有文档

是了,我还以为是gradio的官方文档,会错意了

因为digital_human这边的port只有一个,放视频的界面,没有webui 我去wav2lip的webui那边找到了api文档

不过不知道适配怎么做,还是来请教一下。。。 我有试过直接把api_name改成fn_index带个0,不过可想而知的肯定是报错了 要把这么一大段塞到api_server.py里面,想不到什么好办法(还是gradio学的不到家,贻笑大方了)

(如图,文字下列) ———————————— image ————————————

fn_index: 0
copy
from gradio_client import Client

client = Client("http://192.168.188.223:27861/")
result = client.predict(
      "https://github.com/gradio-app/gradio/raw/main/test/test_files/sample_file.pdf",    # str (filepath on your computer (or URL) of file) in 'Video or Image' File component
      "https://github.com/gradio-app/gradio/raw/main/test/test_files/sample_file.pdf",    # str (filepath on your computer (or URL) of file) in 'Audio' File component
      "wav2lip",  # str  in 'Checkpoint' Radio component
      True,   # bool  in 'No Smooth' Checkbox component
      1,  # int | float (numeric value between 1 and 4) in 'Resize Factor' Slider component
      0,  # int | float (numeric value between 0 and 50) in 'Pad Top' Slider component
      0,  # int | float (numeric value between 0 and 50) in 'Pad Bottom (Often increasing this to 20 allows chin to be included' Slider component
      0,  # int | float (numeric value between 0 and 50) in 'Pad Left' Slider component
      0,  # int | float (numeric value between 0 and 50) in 'Pad Right' Slider component
      fn_index=0
)
print(result)
Return Type(s)
# str (filepath on your computer (or URL) of file) representing output in 'value_18' Video component

—————————— 咳咳咳,感谢大佬,大佬辛苦了,大佬威武——

单独跑例程先试试 参数按照webui的配置改上去 测一测先 然后改到播放器里去。 例程一般改改参数就能用 不能用的话 可能是gradio版本问题