microservice / app.py
Danielsz's picture
Fix Gradio FFmpeg error: remove format parameter to prevent in-place re-encoding
b445b47
Raw
History Blame Contribute Delete
5.29 kB
import os, sys
import gradio as gr
import numpy as np
# Monkey patch for facexlib on NumPy 1.24+ / 2.0+
if not hasattr(np, 'float'):
np.float = float
from src.gradio_demo import SadTalker
try:
import webui # in webui
in_webui = True
except:
in_webui = False
import torch
# GPU Optimizations for Google Colab
if torch.cuda.is_available():
torch.backends.cudnn.benchmark = True
torch.backends.cudnn.deterministic = False
if os.cpu_count() is not None:
torch.set_num_threads(os.cpu_count())
def sadtalker_demo(checkpoint_path='checkpoints', config_path='src/config', warpfn=None):
sad_talker = SadTalker(checkpoint_path, config_path, lazy_load=True)
with gr.Blocks() as sadtalker_interface:
gr.Markdown("<div align='center'> <h2> 馃槶 SadTalker: Learning Realistic 3D Motion Coefficients for Stylized Audio-Driven Single Image Talking Face Animation (CVPR 2023) </span> </h2> \
<a style='font-size:18px;color: #efefef' href='https://arxiv.org/abs/2211.12194'>Arxiv</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
<a style='font-size:18px;color: #efefef' href='https://sadtalker.github.io'>Homepage</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
<a style='font-size:18px;color: #efefef' href='https://github.com/Winfredy/SadTalker'> Github </div>")
with gr.Row():
with gr.Column(variant='panel'):
with gr.Tabs(elem_id="sadtalker_source_image"):
with gr.Tab('Upload image'):
with gr.Row():
source_image = gr.Image(label="Source image", type="filepath", elem_id="img2img_image", width=512)
with gr.Tabs(elem_id="sadtalker_driven_audio"):
with gr.Tab('Upload OR TTS'):
with gr.Column(variant='panel'):
driven_audio = gr.Audio(label="Input audio", type="filepath")
if False: # Disabled TTS to avoid heavy TTS dependency
from src.utils.text2speech import TTSTalker
tts_talker = TTSTalker()
with gr.Column(variant='panel'):
input_text = gr.Textbox(label="Generating audio from text", lines=5, placeholder="please enter some text here, we genreate the audio from text using @Coqui.ai TTS.")
tts = gr.Button('Generate audio',elem_id="sadtalker_audio_generate", variant='primary')
tts.click(fn=tts_talker.test, inputs=[input_text], outputs=[driven_audio])
with gr.Column(variant='panel'):
with gr.Tabs(elem_id="sadtalker_checkbox"):
with gr.Tab('Settings'):
gr.Markdown("need help? please visit our [[best practice page](https://github.com/OpenTalker/SadTalker/blob/main/docs/best_practice.md)] for more detials")
with gr.Column(variant='panel'):
with gr.Row():
pose_style = gr.Slider(minimum=0, maximum=46, step=1, label="Estilo de movimiento de cabeza (Plantillas 0-46)", value=0)
exp_weight = gr.Slider(minimum=0, maximum=3, step=0.1, label="Fuerza de la expresi贸n facial (boca/ojos)", value=1)
with gr.Row():
size_of_image = gr.Radio([256, 512], value=256, label='Resoluci贸n del modelo de rostro')
preprocess_type = gr.Radio(['crop', 'resize','full', 'extcrop', 'extfull'], value='crop', label='Modo de recorte de imagen')
with gr.Row():
is_still_mode = gr.Checkbox(label="Modo Quieto (Congela la cabeza, ideal para avatares formales)")
batch_size = gr.Slider(label="Velocidad (Batch Size)", step=1, maximum=32, value=8)
enhancer = gr.Checkbox(label="Mejorar calidad del rostro (GFPGAN)")
submit = gr.Button('Generar Animaci贸n 馃殌', elem_id="sadtalker_generate", variant='primary')
with gr.Tabs(elem_id="sadtalker_genearted"):
with gr.Tab("Result"):
gen_video = gr.Video(label="Generated video", width=256)
submit.click(
fn=sad_talker.test,
inputs=[source_image,
driven_audio,
preprocess_type,
is_still_mode,
enhancer,
batch_size,
size_of_image,
pose_style,
exp_weight
],
outputs=[gen_video]
)
return sadtalker_interface
if __name__ == "__main__":
demo = sadtalker_demo()
demo.queue()
demo.launch(server_name="0.0.0.0", server_port=7860, share=True)