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

是否支持API调用的方式生成视频? #379

Open
seaung opened this issue Jun 10, 2023 · 14 comments
Open

是否支持API调用的方式生成视频? #379

seaung opened this issue Jun 10, 2023 · 14 comments

Comments

@seaung
Copy link

seaung commented Jun 10, 2023

我想通过发送API接口的方式生成视频,发送的参数大概如下所示:
{
"text": "你好", # 需要生成语言的文本内容
"preprocess": "",
"is_still_mode": true,
"pose_style": ""
...
}
视频生成成功后只需返回视频的生成地址目录和其他元信息
{
"video_url": "/tmp/123.mp4",
"status": "ok"
...
}

@basakamars
Copy link

使用fastapi进行改造就可以了,这个我已经解决了,另外如果你使用python可以使用gradio_client这个包也是可以直接调用的。需要详细资料可以联系我。

@yonggangy
Copy link

请问如何解决的新手 @basakamars 希望提供一下测试代码

@superdreams
Copy link

使用fastapi进行改造就可以了,这个我已经解决了,另外如果你使用python可以使用gradio_client这个包也是可以直接调用的。需要详细资料可以联系我。

可以交流下

@seaung
Copy link
Author

seaung commented Jun 15, 2023

使用fastapi进行改造就可以了,这个我已经解决了,另外如果你使用python可以使用gradio_client这个包也是可以直接调用的。需要详细资料可以联系我。

如何联系到您呢?

@shihzenq
Copy link

@basakamars 您好,如何联系到您,我的微信: tt15652182014

@basakamars
Copy link

其实就是利用程序中inference.py,如我这个DEMO通过GET方法把audio和image的具体path传进去即可。
@seaung @shihzenq @yonggangy

import os
from fastapi import FastAPI
import uvicorn
import nest_asyncio
from fastapi.middleware.cors import CORSMiddleware
from datetime import datetime

app = FastAPI()

origins = ["*"]

app.add_middleware(CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"])

preset = "fast"

@app.get("/sync")
def lip_sync(audio:str,image:str):
    dir = datetime.now().strftime('%Y%m%d%H%M%S%f')
    dir = "result/" + dir
    print("start")
    os.system("python inference.py --driven_audio %s --source_image %s --enhancer gfpgan --result_dir %s --size 256 --preprocess crop" %(audio,image,dir))
    print("end")
    output = os.listdir(dir)
    return "D:/SadTalker/" + dir + "/" + output[0]

if __name__ == "__main__":
    PORT = 28000
    nest_asyncio.apply()
    uvicorn.run(app, host="127.0.0.1", port=PORT)

@shihzenq
Copy link

@basakamars 谢谢您,我添加上

@yonggangy
Copy link

yonggangy commented Jun 27, 2023

@basakamars 好的 谢谢 我看看如何添加这个 新手望理解 qq:291906351

@yonggangy
Copy link

其实就是利用程序中inference.py,如我这个DEMO通过GET方法把audio和image的具体path传进去即可。
@seaung @shihzenq @yonggangy

import os
from fastapi import FastAPI
import uvicorn
import nest_asyncio
from fastapi.middleware.cors import CORSMiddleware
from datetime import datetime

app = FastAPI()

origins = ["*"]

app.add_middleware(CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"])

preset = "fast"

@app.get("/sync")
def lip_sync(audio:str,image:str):
    dir = datetime.now().strftime('%Y%m%d%H%M%S%f')
    dir = "result/" + dir
    print("start")
    os.system("python inference.py --driven_audio %s --source_image %s --enhancer gfpgan --result_dir %s --size 256 --preprocess crop" %(audio,image,dir))
    print("end")
    output = os.listdir(dir)
    return "D:/SadTalker/" + dir + "/" + output[0]

if __name__ == "__main__":
    PORT = 28000
    nest_asyncio.apply()
    uvicorn.run(app, host="127.0.0.1", port=PORT)

远程地址是否可以呢 我测试好像不行

@seaung
Copy link
Author

seaung commented Jun 27, 2023

其实就是利用程序中inference.py,如我这个DEMO通过GET方法把audio和image的具体path传进去即可。
@seaung @shihzenq @yonggangy

import os
from fastapi import FastAPI
import uvicorn
import nest_asyncio
from fastapi.middleware.cors import CORSMiddleware
from datetime import datetime

app = FastAPI()

origins = ["*"]

app.add_middleware(CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"])

preset = "fast"

@app.get("/sync")
def lip_sync(audio:str,image:str):
    dir = datetime.now().strftime('%Y%m%d%H%M%S%f')
    dir = "result/" + dir
    print("start")
    os.system("python inference.py --driven_audio %s --source_image %s --enhancer gfpgan --result_dir %s --size 256 --preprocess crop" %(audio,image,dir))
    print("end")
    output = os.listdir(dir)
    return "D:/SadTalker/" + dir + "/" + output[0]

if __name__ == "__main__":
    PORT = 28000
    nest_asyncio.apply()
    uvicorn.run(app, host="127.0.0.1", port=PORT)

非常的感谢,我之前也是这么做的

@seaung
Copy link
Author

seaung commented Jun 27, 2023

其实就是利用程序中inference.py,如我这个DEMO通过GET方法把audio和image的具体path传进去即可。
@seaung @shihzenq @yonggangy

import os
from fastapi import FastAPI
import uvicorn
import nest_asyncio
from fastapi.middleware.cors import CORSMiddleware
from datetime import datetime

app = FastAPI()

origins = ["*"]

app.add_middleware(CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"])

preset = "fast"

@app.get("/sync")
def lip_sync(audio:str,image:str):
    dir = datetime.now().strftime('%Y%m%d%H%M%S%f')
    dir = "result/" + dir
    print("start")
    os.system("python inference.py --driven_audio %s --source_image %s --enhancer gfpgan --result_dir %s --size 256 --preprocess crop" %(audio,image,dir))
    print("end")
    output = os.listdir(dir)
    return "D:/SadTalker/" + dir + "/" + output[0]

if __name__ == "__main__":
    PORT = 28000
    nest_asyncio.apply()
    uvicorn.run(app, host="127.0.0.1", port=PORT)

非常的感谢,我之前也是这么做的

其实就是利用程序中inference.py,如我这个DEMO通过GET方法把audio和image的具体path传进去即可。
@seaung @shihzenq @yonggangy

import os
from fastapi import FastAPI
import uvicorn
import nest_asyncio
from fastapi.middleware.cors import CORSMiddleware
from datetime import datetime

app = FastAPI()

origins = ["*"]

app.add_middleware(CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"])

preset = "fast"

@app.get("/sync")
def lip_sync(audio:str,image:str):
    dir = datetime.now().strftime('%Y%m%d%H%M%S%f')
    dir = "result/" + dir
    print("start")
    os.system("python inference.py --driven_audio %s --source_image %s --enhancer gfpgan --result_dir %s --size 256 --preprocess crop" %(audio,image,dir))
    print("end")
    output = os.listdir(dir)
    return "D:/SadTalker/" + dir + "/" + output[0]

if __name__ == "__main__":
    PORT = 28000
    nest_asyncio.apply()
    uvicorn.run(app, host="127.0.0.1", port=PORT)

非常感谢,已用这种方式实现了简单的程序

@newstargo
Copy link

newstargo commented Aug 6, 2023

感谢各位的方法,做了个API能远程,就是API在webui启动后,不知为何里面的变量被锁定为常量,影响一些细节操作,而想inference.py只需要返回的合成文件名信息就够了,但会带一堆过程的信息,希望高手指点一下

@ifredom
Copy link

ifredom commented Aug 31, 2023

大佬 前端是一个项目,sadtalker是另一个,我本地传文件地址不在一个项目中,应该怎么传
前端 localhost:3000传递参数:

const testSadtalkerApi = async () => {
  const audio = '/assets/video/test.wav'
  const image = '/assets/images/advator.jpg'
  const params = {
    audio,
    image,
  }
  console.log(params)

  const response = await axios.get('http://127.0.0.1:28000/sync', {
    params,
  })

  console.log(response.data)
}

fastapi:

@app.get("/sync")
def lip_sync(audio:str,image:str):
    dir = datetime.now().strftime('%Y%m%d%H%M%S%f')
    dir = "result/" + dir
    print("start")
    print(f"audio:====={audio}")
    print(f"image:====={image}")
    os.system("python inference.py --driven_audio %s --source_image %s --enhancer gfpgan --result_dir %s --size 256 --preprocess crop" %(audio,image,dir))
    print("end")
    output = os.listdir(dir)
    return "D:/SadTalker/" + dir + "/" + output[0]

image

@Good0007
Copy link

Good0007 commented Sep 8, 2023

我用flask实现的

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

8 participants