File size: 2,666 Bytes
61ba537
e60a003
61ba537
0223aa3
e60a003
61ba537
 
 
 
0223aa3
 
 
 
 
 
 
 
 
61ba537
 
 
 
 
 
 
 
 
0223aa3
61ba537
 
 
 
 
 
0223aa3
61ba537
 
 
 
 
 
 
11a4759
61ba537
11a4759
61ba537
 
 
 
 
 
 
 
e60a003
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61ba537
e60a003
 
 
61ba537
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import os
import shutil
import sys
import requests
from gradio_client import Client

from main import call_wav2lip, call_gfpgan, merge

root_dir = '/content/jobs'
os.makedirs(root_dir, exist_ok=True)


def download_file(url, local_filename):
    response = requests.get(url, stream=True)
    with open(local_filename, 'wb') as file:
        for chunk in response.iter_content(chunk_size=8192):
            if chunk:
                file.write(chunk)


def main(job_id, video_url, audio_url):
    job_path = os.path.join(root_dir, job_id)
    os.makedirs(job_path, exist_ok=True)

    if video_url.startswith('http'):
        video_file = os.path.basename(video_url)
        video_path = os.path.join(job_path, video_file)
        download_file(video_url, video_path)
    else:
        video_path = video_url

    if audio_url.startswith('http'):
        audio_file = os.path.basename(audio_url)
        audio_path = os.path.join(job_path, audio_file)
        download_file(audio_url, audio_path)
    else:
        audio_path = audio_url

    assert os.path.isfile(video_path), f'Video {video_path} not exist.'
    assert os.path.isfile(audio_path), f'Audio {audio_path} not exist.'

    wav2lip_mp4 = os.path.join(job_path, 'wav2lip.mp4')
    print('='*40)
    call_wav2lip(video_path, audio_path, wav2lip_mp4)
    print('='*40)
    call_gfpgan(wav2lip_mp4)

    output_filename = 'output.mp4'
    output_mp4 = os.path.join(job_path, output_filename)
    merge(job_path, audio_path, output_mp4)
    return output_mp4


def generate_audio(text):
    client = Client("https://digitalxingtong-xingtong-3da-bert-vits2.hf.space/")
    result = client.predict(
        text,  # str  in 'Text' Textbox component
        "ign",  # str (Option from: ['ign']) in 'Speaker' Dropdown component
        0.2,  # int | float (numeric value between 0 and 1) in 'θ―­θ°ƒε˜εŒ–' Slider component
        0.6,  # int | float (numeric value between 0.1 and 1.5) in 'ζ„Ÿζƒ…ε˜εŒ–' Slider component
        0.8,  # int | float (numeric value between 0.1 and 1.4) in 'ιŸ³θŠ‚ε‘ιŸ³ι•ΏεΊ¦ε˜εŒ–' Slider component
        1,  # int | float (numeric value between 0.1 and 2) in 'θ―­ι€Ÿ' Slider component
        fn_index=0
    )
    print(result)
    success, audio_file, ogg_file = result
    print(success, audio_file, ogg_file)
    shutil.move(audio_file)

if __name__ == '__main__':
    """
    ! python run.py 2 'http://1.com.1.jpg' /content/wav2lip-gfpgan/inputs/kimk_audio.mp3
    """
    job_id = sys.argv[1]
    video_url = sys.argv[2]
    audio_url = sys.argv[3]

    output_mp4 = main(job_id, video_url, audio_url)

    from google.colab import files

    files.download(output_mp4)