abdul168/Free-View_Expressive_Talking_Head_Video_Editing
0
1import os2import glob3import spaces4from natsort import natsorted5import gradio as gr6 7from inference_util import init_model, infenrece8from attributtes_utils import input_pose, input_emotion, input_blink9 10model = init_model()11 12@spaces.GPU13def process(input_vid, audio_path, pose_select, emotion_select, blink_select):14 pose = input_pose(pose_select)15 emotion = input_emotion(emotion_select)16 blink = input_blink(blink_select)17 18 print("input_vid: ", input_vid)19 result = infenrece(model, os.path.join("./assets/videos/", input_vid), os.path.join("./assets/audios/", audio_path), pose, emotion, blink)20 print("result: ", result)21 22 print("finished !")23 24 return result # , gr.Group.update(visible=True)25 26 27available_videos = natsorted(glob.glob("./assets/videos/*.mp4"))28available_videos = [os.path.basename(x) for x in available_videos]29 30# prepare audio31for video in available_videos:32 audio = video.replace(".mp4", ".wav")33 if not os.path.exists(os.path.join("./assets/audios/", audio)):34 os.system(f"ffmpeg -y -loglevel error -i ./assets/videos/{video} -vn -acodec pcm_s16le -ar 16000 -ac 1 ./assets/audios/{audio}")35available_audios = natsorted(glob.glob("./assets/audios/*.wav"))36available_audios = [os.path.basename(x) for x in available_audios]37 38 39with gr.Blocks() as demo:40 gr.HTML(41 """42 <h1 style="text-align: center; font-size: 40px; font-family: 'Times New Roman', Times, serif;">43 Free-View Expressive Talking Head Video Editing44 </h1>45 <p style="text-align: center; font-size: 20px; font-family: 'Times New Roman', Times, serif;">46 <a style="text-align: center; display:inline-block"47 href="https://sky24h.github.io/websites/icassp2023_free-view_video-editing">48 <img src="https://huggingface.co/datasets/huggingface/badges/raw/main/paper-page-sm.svg#center"49 alt="Project Page">50 </a>51 <a style="text-align: center; display:inline-block" href="https://huggingface.co/spaces/sky24h/Free-View_Expressive_Talking_Head_Video_Editing?duplicate=true">52 <img src="https://huggingface.co/datasets/huggingface/badges/raw/main/duplicate-this-space-sm.svg#center" alt="Duplicate Space">53 </a>54 </p>55 <p style="text-align: center; font-size: 16px; font-family: 'Times New Roman', Times, serif;">56 If you wish to use your custom input files, please duplicate this space or clone it to your local environment.</p>57 <p style="text-align: center; font-size: 16px; font-family: 'Times New Roman', Times, serif;">58 Alternatively, you can check our official <a href="https://github.com/sky24h/Free-View_Expressive_Talking_Head_Video_Editing">repository</a> on GitHub.59 </p>60 """61 )62 with gr.Column(elem_id="col-container"):63 with gr.Row():64 with gr.Column():65 # select and preview video from a list of examples66 video_preview = gr.Video(label="Video Preview", elem_id="video-preview", value="./assets/videos/sample1.mp4")67 video_input = gr.Dropdown(available_videos, label="Input Video", value="sample1.mp4")68 audio_preview = gr.Audio(label="Audio Preview", elem_id="audio-preview", value="./assets/audios/sample2.wav")69 audio_input = gr.Dropdown(available_audios, label="Input Audio", value="sample2.wav")70 pose_select = gr.Radio(["front", "left_right_shaking"], label="Pose", value="front")71 emotion_select = gr.Radio(["neutral", "happy", "angry", "surprised"], label="Emotion", value="neutral")72 blink_select = gr.Radio(["yes", "no"], label="Blink", value="yes")73 # with gr.Row():74 with gr.Column():75 video_out = gr.Video(label="Video Output", elem_id="video-output", height=360)76 submit_btn = gr.Button("Generate video")77 78 inputs = [video_input, audio_input, pose_select, emotion_select, blink_select]79 outputs = [video_out]80 81 video_preview_output = [video_preview]82 audio_preview_output = [audio_preview]83 84 video_input.select(lambda x: "./assets/videos/" + x, video_input, video_preview_output)85 audio_input.select(lambda x: "./assets/audios/" + x, audio_input, audio_preview_output)86 submit_btn.click(process, inputs, outputs)87 88demo.queue(max_size=10).launch()89 