pragnakalp commited on
Commit
4630d3c
·
1 Parent(s): 53663f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -4
app.py CHANGED
@@ -151,8 +151,19 @@ def one_shot_talking(image_in,audio_in):
151
 
152
  # image_in_one_shot='/content/results/restored_imgs/image_pre.png'
153
 
154
- #One Shot Talking Face algorithm
155
- result=calculate(image_in,audio_in)
 
 
 
 
 
 
 
 
 
 
 
156
 
157
  #Video Quality Improvement
158
 
@@ -163,9 +174,28 @@ def one_shot_talking(image_in,audio_in):
163
  os.system(f"python /content/GFPGAN/inference_gfpgan.py --upscale 2 -i /content/extracted_frames/ -o /content/video_results --bg_upsampler realesrgan")
164
 
165
  #3. Merge all the frames to a one video using imageio
166
- merge_frames()
 
 
 
 
 
 
 
 
167
 
168
- audio_video()
 
 
 
 
 
 
 
 
 
 
 
169
 
170
 
171
 
 
151
 
152
  # image_in_one_shot='/content/results/restored_imgs/image_pre.png'
153
 
154
+ waveform, sample_rate = torchaudio.load(audio_in)
155
+ torchaudio.save("/content/audio.wav", waveform, sample_rate, encoding="PCM_S", bits_per_sample=16)
156
+ image = Image.open(image_in)
157
+ image = pad_image(image)
158
+ image.save("image_pre.png")
159
+
160
+ pocketsphinx_run = subprocess.run(['pocketsphinx', '-phone_align', 'yes', 'single', '/content/audio.wav'], check=True, capture_output=True)
161
+ jq_run = subprocess.run(['jq', '[.w[]|{word: (.t | ascii_upcase | sub("<S>"; "sil") | sub("<SIL>"; "sil") | sub("\\\(2\\\)"; "") | sub("\\\(3\\\)"; "") | sub("\\\(4\\\)"; "") | sub("\\\[SPEECH\\\]"; "SIL") | sub("\\\[NOISE\\\]"; "SIL")), phones: [.w[]|{ph: .t | sub("\\\+SPN\\\+"; "SIL") | sub("\\\+NSN\\\+"; "SIL"), bg: (.b*100)|floor, ed: (.b*100+.d*100)|floor}]}]'], input=pocketsphinx_run.stdout, capture_output=True)
162
+ with open("test.json", "w") as f:
163
+ f.write(jq_run.stdout.decode('utf-8').strip())
164
+
165
+ os.system(f"cd /content/one-shot-talking-face && python3 -B test_script.py --img_path /content/image_pre.png --audio_path /content/audio.wav --phoneme_path /content/test.json --save_dir /content/train")
166
+
167
 
168
  #Video Quality Improvement
169
 
 
174
  os.system(f"python /content/GFPGAN/inference_gfpgan.py --upscale 2 -i /content/extracted_frames/ -o /content/video_results --bg_upsampler realesrgan")
175
 
176
  #3. Merge all the frames to a one video using imageio
177
+ path = '/content/video_results/restored_imgs'
178
+ image_folder = os.fsencode(path)
179
+ print(image_folder)
180
+ filenames = []
181
+
182
+ for file in os.listdir(image_folder):
183
+ filename = os.fsdecode(file)
184
+ if filename.endswith( ('.jpg', '.png', '.gif') ):
185
+ filenames.append(filename)
186
 
187
+ filenames.sort() # this iteration technique has no built in order, so sort the frames
188
+ images = list(map(lambda filename: imageio.imread("/content/video_results/restored_imgs/"+filename), filenames))
189
+
190
+
191
+ imageio.mimsave('/content/video_output.mp4', images, fps=25.0) # modify the frame duration as needed
192
+
193
+ input_video = ffmpeg.input('/content/video_output.mp4')
194
+
195
+ input_audio = ffmpeg.input('/content/audio.wav')
196
+
197
+ ffmpeg.concat(input_video, input_audio, v=1, a=1).output('final_output.mp4').run()
198
+ return "final_output.mp4"
199
 
200
 
201