Commit ·
626d7ff
1
Parent(s): 6614b1a
Fix dependency issues and add some updates (#10)
Browse files- Fix (8dbbb4631700b4a6f463caad2bfb6d376de73131)
Co-authored-by: hysts <hysts@users.noreply.huggingface.co>
Files changed (3)
- README.md+1-1
- app.py+32-43
- requirements.txt+76-25
3 unmodified lines456789103 unmodified linescolorFrom: indigocolorTo: indigosdk: gradiosdk_version: 3.0.19app_file: app.pypinned: false---3 unmodified lines456789103 unmodified linescolorFrom: indigocolorTo: indigosdk: gradiosdk_version: 3.48.0app_file: app.pypinned: false---
12345678910111213141524 unmodified lines4041424344454647484950515253545556575859606162637 unmodified lines7172737475767778798081823 unmodified lines86878889909192939495969798991001011021 unmodified line1041051061071081091101 unmodified line112113114115116117118119120121122123124125126127128import gradio as grimport osimport shutilimport torchfrom PIL import Imageimport argparseimport pathlibos.system("git clone https://github.com/yoyo-nb/Thin-Plate-Spline-Motion-Model")os.chdir("Thin-Plate-Spline-Motion-Model")os.system("mkdir checkpoints")os.system("gdown 1-CKOjv_y_TzNe-dwQsjjeVxJUuyBAb5X -O checkpoints/vox.pth.tar")24 unmodified linesreturn gr.Markdown.update(value=text)def set_example_image(example: list) -> dict:return gr.Image.update(value=example[0])def set_example_video(example: list) -> dict:return gr.Video.update(value=example[0])def inference(img,vid):if not os.path.exists('temp'):os.system('mkdir temp')img.save("temp/image.jpg", "JPEG")os.system(f"python demo.py --config config/vox-256.yaml --checkpoint ./checkpoints/vox.pth.tar --source_image 'temp/image.jpg' --driving_video {vid} --result_video './temp/result.mp4' --cpu")return './temp/result.mp4'def main():with gr.Blocks(theme="huggingface", css='style.css') as demo:gr.Markdown(title)gr.Markdown(DESCRIPTION)7 unmodified lineswith gr.Row():input_image = gr.Image(label='Input Image',type="pil")with gr.Row():paths = sorted(pathlib.Path('assets').glob('*.png'))example_images = gr.Dataset(components=[input_image],samples=[[path.as_posix()]for path in paths])with gr.Box():gr.Markdown('''## Step 2 (Select Driving Video)3 unmodified lineswith gr.Column():with gr.Row():driving_video = gr.Video(label='Driving Video',format="mp4")with gr.Row():paths = sorted(pathlib.Path('assets').glob('*.mp4'))example_video = gr.Dataset(components=[driving_video],samples=[[path.as_posix()]for path in paths])with gr.Box():gr.Markdown('''## Step 3 (Generate Animated Image based on the Video)- Hit the **Generate** button. (Note: As it runs on the CPU, it takes ~ 3 minutes to generate final results.)''')with gr.Row():with gr.Column():1 unmodified linegenerate_button = gr.Button('Generate')with gr.Column():result = gr.Video(type="file", label="Output")gr.Markdown(FOOTER)generate_button.click(fn=inference,inputs=[1 unmodified linedriving_video],outputs=result)example_images.click(fn=set_example_image,inputs=example_images,outputs=example_images.components)example_video.click(fn=set_example_video,inputs=example_video,outputs=example_video.components)demo.launch(enable_queue=True,debug=True)if __name__ == '__main__':main()12345678910111213141516171824 unmodified lines4344454647484950515253545556575859606162637 unmodified lines71727374757677787980813 unmodified lines8586878889909192939495969798991001 unmodified line1021031041051061071081 unmodified line110111112113114115116117import osimport pathlibimport gradio as grimport torchfrom PIL import Imagerepo_dir = pathlib.Path("Thin-Plate-Spline-Motion-Model").absolute()if not repo_dir.exists():os.system("git clone https://github.com/yoyo-nb/Thin-Plate-Spline-Motion-Model")os.chdir(repo_dir.name)if not (repo_dir / "checkpoints").exists():os.system("mkdir checkpoints")if not (repo_dir / "checkpoints/vox.pth.tar").exists():os.system("gdown 1-CKOjv_y_TzNe-dwQsjjeVxJUuyBAb5X -O checkpoints/vox.pth.tar")24 unmodified linesreturn gr.Markdown.update(value=text)def inference(img, vid):if not os.path.exists('temp'):os.system('mkdir temp')img.save("temp/image.jpg", "JPEG")if torch.cuda.is_available():os.system(f"python demo.py --config config/vox-256.yaml --checkpoint ./checkpoints/vox.pth.tar --source_image 'temp/image.jpg' --driving_video {vid} --result_video './temp/result.mp4'")else:os.system(f"python demo.py --config config/vox-256.yaml --checkpoint ./checkpoints/vox.pth.tar --source_image 'temp/image.jpg' --driving_video {vid} --result_video './temp/result.mp4' --cpu")return './temp/result.mp4'def main():with gr.Blocks(css='style.css') as demo:gr.Markdown(title)gr.Markdown(DESCRIPTION)7 unmodified lineswith gr.Row():input_image = gr.Image(label='Input Image',type="pil")with gr.Row():paths = sorted(pathlib.Path('assets').glob('*.png'))gr.Examples(inputs=[input_image],examples=[[path.as_posix()] for path in paths])with gr.Box():gr.Markdown('''## Step 2 (Select Driving Video)3 unmodified lineswith gr.Column():with gr.Row():driving_video = gr.Video(label='Driving Video',format="mp4")with gr.Row():paths = sorted(pathlib.Path('assets').glob('*.mp4'))gr.Examples(inputs=[driving_video],examples=[[path.as_posix()] for path in paths])with gr.Box():gr.Markdown('''## Step 3 (Generate Animated Image based on the Video)- Hit the **Generate** button. (Note: On cpu-basic, it takes ~ 10 minutes to generate final results.)''')with gr.Row():with gr.Column():1 unmodified linegenerate_button = gr.Button('Generate')with gr.Column():result = gr.Video(label="Output")gr.Markdown(FOOTER)generate_button.click(fn=inference,inputs=[1 unmodified linedriving_video],outputs=result)demo.queue(max_size=10).launch()if __name__ == '__main__':main()
123456789101112131415161718192021222324252627cffi==1.14.6cycler==0.10.0decorator==5.1.0face-alignment==1.3.5imageio==2.9.0imageio-ffmpeg==0.4.5kiwisolver==1.3.2matplotlib==3.4.3networkx==2.6.3numpy==1.20.3pandas==1.3.3Pillowpycparser==2.20pyparsing==2.4.7python-dateutil==2.8.2pytz==2021.1PyWavelets==1.1.1PyYAMLscikit-imagescikit-learnscipysix==1.16.0torch==1.11.0torchvision==0.12.0tqdm==4.62.3gradiogdown123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778aiofiles==23.2.1altair==5.1.2annotated-types==0.6.0anyio==3.7.1attrs==23.1.0beautifulsoup4==4.12.2certifi==2023.7.22charset-normalizer==3.3.0click==8.1.7cmake==3.27.7contourpy==1.1.1cycler==0.12.1exceptiongroup==1.1.3fastapi==0.103.2ffmpy==0.3.1filelock==3.12.4fonttools==4.43.1fsspec==2023.9.2gdown==4.7.1gradio==3.48.0gradio_client==0.6.1h11==0.14.0httpcore==0.18.0httpx==0.25.0huggingface-hub==0.18.0idna==3.4imageio==2.31.5imageio-ffmpeg==0.4.9importlib-resources==6.1.0Jinja2==3.1.2jsonschema==4.19.1jsonschema-specifications==2023.7.1kiwisolver==1.4.5lazy_loader==0.3lit==17.0.3MarkupSafe==2.1.3matplotlib==3.8.0mpmath==1.3.0networkx==3.1numpy==1.25.2orjson==3.9.9packaging==23.2pandas==2.1.1Pillow==10.1.0psutil==5.9.6pydantic==2.4.2pydantic_core==2.10.1pydub==0.25.1pyparsing==3.1.1PySocks==1.7.1python-dateutil==2.8.2python-multipart==0.0.6pytz==2023.3.post1PyYAML==6.0.1referencing==0.30.2requests==2.31.0rpds-py==0.10.6scikit-image==0.22.0scipy==1.11.3semantic-version==2.10.0setuptools-scm==8.0.4six==1.16.0sniffio==1.3.0soupsieve==2.5starlette==0.27.0sympy==1.12tifffile==2023.9.26tomli==2.0.1toolz==0.12.0torch==2.0.0torchvision==0.15.1tqdm==4.66.1triton==2.0.0typing_extensions==4.8.0tzdata==2023.3urllib3==2.0.7uvicorn==0.23.2websockets==11.0.3
README.md+1-1
app.py+32-43
requirements.txt+76-25