Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] [gradio] Web API not working #374

Open
wizd opened this issue Jun 8, 2023 · 0 comments
Open

[bug] [gradio] Web API not working #374

wizd opened this issue Jun 8, 2023 · 0 comments

Comments

@wizd
Copy link

wizd commented Jun 8, 2023

Command line work great:

%PYTHON% inference.py --driven_audio %1 --source_image %2

But the web api don't work. This is my client code running on nodejs:

import { client } from '@gradio/client';
import { promises as fs } from 'fs';
import path from 'path';

export async function callSadtalkerRemotely(url: string, imgfn: string, wavfn: string) {
    // 从本地文件系统读取 PNG 和 WAV 文件
    const localPngBuffer = await fs.readFile(path.resolve(imgfn));
    const localWavBuffer = await fs.readFile(path.resolve(wavfn));
    // 将 Buffer 转换为 Blob
    const localPngBlob = new Blob([localPngBuffer], { type: 'image/png' });
    const localWavBlob = new Blob([localWavBuffer], { type: 'audio/wav' });

    const app = await client(url);

    const app_info = await app.view_api();

    console.log(app_info);

    const result = await app.predict(0, [
        localPngBlob, // 使用本地 PNG 文件
        localWavBlob, // 使用本地 WAV 文件
        'crop',
        true,
        true,
        0,
        '256',
        0,
        0,
    ]);

    // 返回二进制数据
    return (result as any).data;
}

// 请使用您本地的 PNG 和 WAV 文件路径调用 callSadtalkerRemotely 函数
// callSadtalkerRemotely('path/to/your/gradioURL', 'path/to/your/pngfile.png', 'path/to/your/wavfile.wav')
//     .then((data) => console.log('Received data:', data))
//     .catch((error) => console.error('Error:', error));

I have the server logs bellow.

(venv) (sadtalker) D:\app\SadTalker>git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

(venv) (sadtalker) D:\app\SadTalker>git pull
Already up to date.

(venv) (sadtalker) D:\app\SadTalker>webui.bat
venv folder already exists, skipping creation...
venv "venv\Scripts\Python.exe"
Python 3.10.6 | packaged by conda-forge | (main, Oct 24 2022, 16:02:16) [MSC v.1916 64 bit (AMD64)]
Commit hash: a810cbe1f21df10dfa286feb037d82b77f82072d
Installing requirements for SadTalker WebUI (may take longer time in first time)
Launching SadTalker Web UI
Running on local URL:  http://0.0.0.0:7861

To create a public link, set `share=True` in `launch()`.
using safetensor as default
{'checkpoint': 'checkpoints\\SadTalker_V0.0.2_256.safetensors', 'dir_of_BFM_fitting': 'src/config', 'audio2pose_yaml_path': 'src/config\\auido2pose.yaml', 'audio2exp_yaml_path': 'src/config\\auido2exp.yaml', 'use_safetensor': True, 'mappingnet_checkpoint': 'checkpoints\\mapping_00229-model.pth.tar', 'facerender_yaml': 'src/config\\facerender.yaml'}
C:\Users\wizard\AppData\Local\Temp\gradio\732a9d525bb62cffcadd3fee82a67eda76b0b37d\image.png
Traceback (most recent call last):
  File "D:\app\SadTalker\venv\lib\site-packages\gradio\routes.py", line 427, in run_predict
    output = await app.get_blocks().process_api(
  File "D:\app\SadTalker\venv\lib\site-packages\gradio\blocks.py", line 1323, in process_api
    result = await self.call_function(
  File "D:\app\SadTalker\venv\lib\site-packages\gradio\blocks.py", line 1051, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "D:\app\SadTalker\venv\lib\site-packages\anyio\to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "D:\app\SadTalker\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "D:\app\SadTalker\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "D:\app\SadTalker\src\gradio_demo.py", line 75, in test
    first_coeff_path, crop_pic_path, crop_info = self.preprocess_model.generate(pic_path, first_frame_dir, preprocess, True, size)
  File "D:\app\SadTalker\src\utils\preprocess.py", line 113, in generate
    frames_pil = [Image.fromarray(cv2.resize(frame,(pic_size, pic_size))) for frame in x_full_frames]
  File "D:\app\SadTalker\src\utils\preprocess.py", line 113, in <listcomp>
    frames_pil = [Image.fromarray(cv2.resize(frame,(pic_size, pic_size))) for frame in x_full_frames]
cv2.error: OpenCV(4.7.0) :-1: error: (-5:Bad argument) in function 'resize'
> Overload resolution failed:
>  - Can't parse 'dsize'. Sequence item with index 0 has a wrong type
>  - Can't parse 'dsize'. Sequence item with index 0 has a wrong type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant