Spaces:
Runtime error
Runtime error
read text from .txt
Browse files- gfpgan/inference_gfpgan.py +4 -0
- requirements.txt +2 -1
- txt2video.py +14 -8
- voice2video.py +2 -0
- wav2lip/inference.py +4 -3
gfpgan/inference_gfpgan.py
CHANGED
@@ -96,6 +96,10 @@ def main():
|
|
96 |
arch = 'clean'
|
97 |
channel_multiplier = 2
|
98 |
model_name = 'GFPGANv1.3'
|
|
|
|
|
|
|
|
|
99 |
else:
|
100 |
raise ValueError(f'Wrong model version {args.version}.')
|
101 |
|
|
|
96 |
arch = 'clean'
|
97 |
channel_multiplier = 2
|
98 |
model_name = 'GFPGANv1.3'
|
99 |
+
elif args.version == '1.4':
|
100 |
+
arch = 'clean'
|
101 |
+
channel_multiplier = 2
|
102 |
+
model_name = 'GFPGANv1.4'
|
103 |
else:
|
104 |
raise ValueError(f'Wrong model version {args.version}.')
|
105 |
|
requirements.txt
CHANGED
@@ -21,4 +21,5 @@ ffmpy
|
|
21 |
flask_ngrok2
|
22 |
flask_ngrok
|
23 |
opencv-python
|
24 |
-
requests
|
|
|
|
21 |
flask_ngrok2
|
22 |
flask_ngrok
|
23 |
opencv-python
|
24 |
+
requests
|
25 |
+
gradio_client
|
txt2video.py
CHANGED
@@ -20,7 +20,7 @@ def download_file(url, local_filename):
|
|
20 |
file.write(chunk)
|
21 |
|
22 |
|
23 |
-
def main(job_id,
|
24 |
job_path = os.path.join(root_dir, job_id)
|
25 |
os.makedirs(job_path, exist_ok=True)
|
26 |
|
@@ -38,7 +38,9 @@ def main(job_id, video_url, text):
|
|
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'
|
@@ -68,14 +70,18 @@ def gen_voice(text, audio_path):
|
|
68 |
|
69 |
if __name__ == '__main__':
|
70 |
"""
|
71 |
-
|
|
|
|
|
|
|
72 |
"""
|
73 |
job_id = sys.argv[1]
|
74 |
-
|
75 |
-
|
76 |
|
77 |
-
|
|
|
|
|
|
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
files.download(output_mp4)
|
|
|
20 |
file.write(chunk)
|
21 |
|
22 |
|
23 |
+
def main(job_id, text, video_url):
|
24 |
job_path = os.path.join(root_dir, job_id)
|
25 |
os.makedirs(job_path, exist_ok=True)
|
26 |
|
|
|
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 |
+
print('=' * 40)
|
42 |
call_wav2lip(video_path, audio_path, wav2lip_mp4)
|
43 |
+
print('=' * 40)
|
44 |
call_gfpgan(wav2lip_mp4)
|
45 |
|
46 |
output_filename = 'output.mp4'
|
|
|
70 |
|
71 |
if __name__ == '__main__':
|
72 |
"""
|
73 |
+
job_id='2'
|
74 |
+
! python txt2video.py {job_id} 'https://image.tensorartassets.com/cdn-cgi/image/plain=true,w=1280/posts/images/631302687467566953/4873c256-c1bd-49ba-85ca-5821801f122f.jpg' 海狸今天我们出去走路么
|
75 |
+
from google.colab import files
|
76 |
+
files.download(f'/content/jobs/{job_id}/output.mp4')
|
77 |
"""
|
78 |
job_id = sys.argv[1]
|
79 |
+
text = sys.argv[2] # text or .txt file
|
80 |
+
video_url = sys.argv[3]
|
81 |
|
82 |
+
if os.path.isfile(text):
|
83 |
+
# read file as string
|
84 |
+
with open(text, 'r') as file:
|
85 |
+
text = file.read()
|
86 |
|
87 |
+
output_mp4 = main(job_id, text, video_url)
|
|
|
|
voice2video.py
CHANGED
@@ -40,7 +40,9 @@ def main(job_id, video_url, audio_url):
|
|
40 |
assert os.path.isfile(audio_path), f'Audio {audio_path} not exist.'
|
41 |
|
42 |
wav2lip_mp4 = os.path.join(job_path, 'wav2lip.mp4')
|
|
|
43 |
call_wav2lip(video_path, audio_path, wav2lip_mp4)
|
|
|
44 |
call_gfpgan(wav2lip_mp4)
|
45 |
|
46 |
output_filename = 'output.mp4'
|
|
|
40 |
assert os.path.isfile(audio_path), f'Audio {audio_path} not exist.'
|
41 |
|
42 |
wav2lip_mp4 = os.path.join(job_path, 'wav2lip.mp4')
|
43 |
+
print('='*40)
|
44 |
call_wav2lip(video_path, audio_path, wav2lip_mp4)
|
45 |
+
print('='*40)
|
46 |
call_gfpgan(wav2lip_mp4)
|
47 |
|
48 |
output_filename = 'output.mp4'
|
wav2lip/inference.py
CHANGED
@@ -225,8 +225,8 @@ def main():
|
|
225 |
print("Number of frames available for inference: " + str(len(full_frames)))
|
226 |
|
227 |
if not args.audio.endswith('.wav'):
|
228 |
-
print('Extracting raw audio
|
229 |
-
command = 'ffmpeg -y -i {} -strict -2 {}'.format(args.audio, f'{folder_path}/temp.wav')
|
230 |
|
231 |
subprocess.call(command, shell=True)
|
232 |
args.audio = f'{folder_path}/temp.wav'
|
@@ -284,7 +284,8 @@ def main():
|
|
284 |
|
285 |
out.release()
|
286 |
|
287 |
-
|
|
|
288 |
subprocess.call(command, shell=platform.system() != 'Windows')
|
289 |
|
290 |
|
|
|
225 |
print("Number of frames available for inference: " + str(len(full_frames)))
|
226 |
|
227 |
if not args.audio.endswith('.wav'):
|
228 |
+
print(f'Wav2Lip ffmpeg: Extracting raw audio {args.audio}')
|
229 |
+
command = 'ffmpeg -y -v error -stats -i {} -strict -2 {}'.format(args.audio, f'{folder_path}/temp.wav')
|
230 |
|
231 |
subprocess.call(command, shell=True)
|
232 |
args.audio = f'{folder_path}/temp.wav'
|
|
|
284 |
|
285 |
out.release()
|
286 |
|
287 |
+
print(f'Wav2Lip ffmpeg: merge into result.avi')
|
288 |
+
command = 'ffmpeg -y -v error -stats -i {} -i {} -strict -2 -q:v 1 {}'.format(args.audio, f'{folder_path}/result.avi', args.outfile)
|
289 |
subprocess.call(command, shell=platform.system() != 'Windows')
|
290 |
|
291 |
|