Open joseph5227 opened 1 year ago
@johndpope @vinthony @thegenerativegeneration @johnephillips
代码不贴,定位不了
这个是webui 上的示例代码吧?我试了一下,也一样,你现在解决了吗?
我使用了这个方式,已经ok了,供兄弟们参考。
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, tmpdir:str):
#dir = datetime.now().strftime('%Y%m%d%H%M%S%f')
dir = "/data/digital/files/videos/" + tmpdir
print("start....audio=" + audio + ", image=" + image + ", tmpdir=" + tmpdir)
#os.system("python inference.py --driven_audio %s --source_image %s --enhancer gfpgan --result_dir %s --size 256 --preprocess crop" %(audio,image,dir))
os.system("python inference.py --driven_audio %s --source_image %s --result_dir %s --size 256 --preprocess full --still" %(audio,image,dir))
#os.system("python inference.py --driven_audio %s --source_image %s --enhancer gfpgan --result_dir %s --size 256 --preprocess full --still" %(audio,image,dir))
resultVideo = os.listdir(dir)[0]
print("end....return video: " + resultVideo)
os.system("chown -R $group:$user " + dir)
os.system("ffmpeg -i " + dir + "/" + resultVideo + " -vcodec h264 " + dir + "/temp.mp4")
os.system("rm -rf " + dir + "/" + resultVideo)
os.system("mv " + dir + "/temp.mp4 " + dir + "/" + resultVideo)
return resultVideo;
if __name__ == "__main__":
PORT = 37860
nest_asyncio.apply()
uvicorn.run(app, host="0.0.0.0", port=PORT)
我使用了这个方式,已经ok了,供兄弟们参考。
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, tmpdir:str): #dir = datetime.now().strftime('%Y%m%d%H%M%S%f') dir = "/data/digital/files/videos/" + tmpdir print("start....audio=" + audio + ", image=" + image + ", tmpdir=" + tmpdir) #os.system("python inference.py --driven_audio %s --source_image %s --enhancer gfpgan --result_dir %s --size 256 --preprocess crop" %(audio,image,dir)) os.system("python inference.py --driven_audio %s --source_image %s --result_dir %s --size 256 --preprocess full --still" %(audio,image,dir)) #os.system("python inference.py --driven_audio %s --source_image %s --enhancer gfpgan --result_dir %s --size 256 --preprocess full --still" %(audio,image,dir)) resultVideo = os.listdir(dir)[0] print("end....return video: " + resultVideo) os.system("chown -R $group:$user " + dir) os.system("ffmpeg -i " + dir + "/" + resultVideo + " -vcodec h264 " + dir + "/temp.mp4") os.system("rm -rf " + dir + "/" + resultVideo) os.system("mv " + dir + "/temp.mp4 " + dir + "/" + resultVideo) return resultVideo; if __name__ == "__main__": PORT = 37860 nest_asyncio.apply() uvicorn.run(app, host="0.0.0.0", port=PORT)
注意调整下授权的group和user。
from gradio_client import Client
client = Client("http://106.75.129.187:7861/") result = client.predict( "https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png", # str (filepath or URL to image) in 'Source image' Image component "https://github.com/gradio-app/gradio/raw/main/test/test_files/audio_sample.wav", # str (filepath or URL to file) in 'Input audio' Audio component "crop", # str in 'preprocess' Radio component True, # bool in 'Still Mode (fewer hand motion, works with preprocess
full
)' Checkbox component True, # bool in 'GFPGAN as Face enhancer' Checkbox component 0, # int | float (numeric value between 0 and 10) in 'batch size in generation' Slider component "256", # str in 'face model resolution' Radio component 0, # int | float (numeric value between 0 and 46) in 'Pose style' Slider component fn_index=1 ) print(result)API调用生成视频的时候提示下面错误
Traceback (most recent call last): File "/data/weiyj/sadTalker/inference.py", line 4, in
result = client.predict(
File "/home/ubuntu/anaconda3/lib/python3.10/site-packages/gradio_client/client.py", line 263, in predict
return self.submit(args, api_name=api_name, fn_index=fn_index).result()
File "/home/ubuntu/anaconda3/lib/python3.10/site-packages/gradio_client/client.py", line 954, in result
raise self.future._exception # type: ignore
File "/home/ubuntu/anaconda3/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(self.args, *self.kwargs)
File "/home/ubuntu/anaconda3/lib/python3.10/site-packages/gradio_client/client.py", line 622, in _inner
predictions = _predict(data)
File "/home/ubuntu/anaconda3/lib/python3.10/site-packages/gradio_client/client.py", line 653, in _predict
raise ValueError(result["error"])
ValueError: None