Spaces:
Runtime error
Runtime error
add txt2video
Browse files- txt2video.py +81 -0
- run.py β voice2video.py +21 -0
txt2video.py
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import shutil
|
3 |
+
import sys
|
4 |
+
from pathlib import Path
|
5 |
+
|
6 |
+
import requests
|
7 |
+
from gradio_client import Client
|
8 |
+
|
9 |
+
from main import call_wav2lip, call_gfpgan, merge
|
10 |
+
|
11 |
+
root_dir = '/content/jobs'
|
12 |
+
os.makedirs(root_dir, exist_ok=True)
|
13 |
+
|
14 |
+
|
15 |
+
def download_file(url, local_filename):
|
16 |
+
response = requests.get(url, stream=True)
|
17 |
+
with open(local_filename, 'wb') as file:
|
18 |
+
for chunk in response.iter_content(chunk_size=8192):
|
19 |
+
if chunk:
|
20 |
+
file.write(chunk)
|
21 |
+
|
22 |
+
|
23 |
+
def main(job_id, video_url, text):
|
24 |
+
job_path = os.path.join(root_dir, job_id)
|
25 |
+
os.makedirs(job_path, exist_ok=True)
|
26 |
+
|
27 |
+
if video_url.startswith('http'):
|
28 |
+
video_file = os.path.basename(video_url)
|
29 |
+
video_path = os.path.join(job_path, video_file)
|
30 |
+
download_file(video_url, video_path)
|
31 |
+
else:
|
32 |
+
video_path = video_url
|
33 |
+
|
34 |
+
audio_path = os.path.join(job_path, 'audio.mp3')
|
35 |
+
gen_voice(text, audio_path)
|
36 |
+
|
37 |
+
assert os.path.isfile(video_path), f'Video {video_path} not exist.'
|
38 |
+
assert os.path.isfile(audio_path), f'Audio {audio_path} not exist.'
|
39 |
+
|
40 |
+
wav2lip_mp4 = os.path.join(job_path, 'wav2lip.mp4')
|
41 |
+
call_wav2lip(video_path, audio_path, wav2lip_mp4)
|
42 |
+
call_gfpgan(wav2lip_mp4)
|
43 |
+
|
44 |
+
output_filename = 'output.mp4'
|
45 |
+
output_mp4 = os.path.join(job_path, output_filename)
|
46 |
+
merge(job_path, audio_path, output_mp4)
|
47 |
+
return output_mp4
|
48 |
+
|
49 |
+
|
50 |
+
def gen_voice(text, audio_path):
|
51 |
+
ogg_path = Path(audio_path).with_suffix('.ogg')
|
52 |
+
client = Client("https://digitalxingtong-xingtong-3da-bert-vits2.hf.space/")
|
53 |
+
result = client.predict(
|
54 |
+
text, # str in 'Text' Textbox component
|
55 |
+
"ign", # str (Option from: ['ign']) in 'Speaker' Dropdown component
|
56 |
+
0.2, # int | float (numeric value between 0 and 1) in 'θ―θ°εε' Slider component
|
57 |
+
0.6, # int | float (numeric value between 0.1 and 1.5) in 'ζζ
εε' Slider component
|
58 |
+
0.8, # int | float (numeric value between 0.1 and 1.4) in 'ι³θει³ιΏεΊ¦εε' Slider component
|
59 |
+
1, # int | float (numeric value between 0.1 and 2) in 'θ―ι' Slider component
|
60 |
+
fn_index=0
|
61 |
+
)
|
62 |
+
print(result)
|
63 |
+
success, audio_file, ogg_file = result
|
64 |
+
print(success, audio_file, ogg_file)
|
65 |
+
shutil.move(audio_file, audio_path)
|
66 |
+
shutil.move(ogg_file, ogg_path)
|
67 |
+
|
68 |
+
|
69 |
+
if __name__ == '__main__':
|
70 |
+
"""
|
71 |
+
! python run.py 2 'http://1.com.1.jpg' /content/wav2lip-gfpgan/inputs/kimk_audio.mp3
|
72 |
+
"""
|
73 |
+
job_id = sys.argv[1]
|
74 |
+
video_url = sys.argv[2]
|
75 |
+
audio_url = sys.argv[3]
|
76 |
+
|
77 |
+
output_mp4 = main(job_id, video_url, audio_url)
|
78 |
+
|
79 |
+
from google.colab import files
|
80 |
+
|
81 |
+
files.download(output_mp4)
|
run.py β voice2video.py
RENAMED
@@ -1,6 +1,8 @@
|
|
1 |
import os
|
|
|
2 |
import sys
|
3 |
import requests
|
|
|
4 |
|
5 |
from main import call_wav2lip, call_gfpgan, merge
|
6 |
|
@@ -47,7 +49,26 @@ def main(job_id, video_url, audio_url):
|
|
47 |
return output_mp4
|
48 |
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
if __name__ == '__main__':
|
|
|
|
|
|
|
51 |
job_id = sys.argv[1]
|
52 |
video_url = sys.argv[2]
|
53 |
audio_url = sys.argv[3]
|
|
|
1 |
import os
|
2 |
+
import shutil
|
3 |
import sys
|
4 |
import requests
|
5 |
+
from gradio_client import Client
|
6 |
|
7 |
from main import call_wav2lip, call_gfpgan, merge
|
8 |
|
|
|
49 |
return output_mp4
|
50 |
|
51 |
|
52 |
+
def generate_audio(text):
|
53 |
+
client = Client("https://digitalxingtong-xingtong-3da-bert-vits2.hf.space/")
|
54 |
+
result = client.predict(
|
55 |
+
text, # str in 'Text' Textbox component
|
56 |
+
"ign", # str (Option from: ['ign']) in 'Speaker' Dropdown component
|
57 |
+
0.2, # int | float (numeric value between 0 and 1) in 'θ―θ°εε' Slider component
|
58 |
+
0.6, # int | float (numeric value between 0.1 and 1.5) in 'ζζ
εε' Slider component
|
59 |
+
0.8, # int | float (numeric value between 0.1 and 1.4) in 'ι³θει³ιΏεΊ¦εε' Slider component
|
60 |
+
1, # int | float (numeric value between 0.1 and 2) in 'θ―ι' Slider component
|
61 |
+
fn_index=0
|
62 |
+
)
|
63 |
+
print(result)
|
64 |
+
success, audio_file, ogg_file = result
|
65 |
+
print(success, audio_file, ogg_file)
|
66 |
+
shutil.move(audio_file)
|
67 |
+
|
68 |
if __name__ == '__main__':
|
69 |
+
"""
|
70 |
+
! python run.py 2 'http://1.com.1.jpg' /content/wav2lip-gfpgan/inputs/kimk_audio.mp3
|
71 |
+
"""
|
72 |
job_id = sys.argv[1]
|
73 |
video_url = sys.argv[2]
|
74 |
audio_url = sys.argv[3]
|