pragnakalp commited on
Commit
e5bc2ed
·
1 Parent(s): 4aa0c77

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -3
app.py CHANGED
@@ -96,10 +96,33 @@ def one_shot(image,input_text,gender):
96
  f.seek(0)
97
  sound = AudioSegment.from_file(f.name, format="mp3")
98
  sound.export("/content/audio.wav", format="wav")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
 
100
- result = one_shot_talking(image,'/content/audio.wav')
101
- return result
102
- exit()
103
  elif gender == 'Male' or gender == 'male':
104
  print(gender)
105
  models, cfg, task = load_model_ensemble_and_task_from_hf_hub(
 
96
  f.seek(0)
97
  sound = AudioSegment.from_file(f.name, format="mp3")
98
  sound.export("/content/audio.wav", format="wav")
99
+
100
+ waveform, sample_rate = torchaudio.load(audio_in)
101
+ torchaudio.save("/content/audio.wav", waveform, sample_rate, encoding="PCM_S", bits_per_sample=16)
102
+ image = Image.open(image_in)
103
+ image = pad_image(image)
104
+ image.save("/content/image_pre.png")
105
+ pocketsphinx_run = subprocess.run(['pocketsphinx', '-phone_align', 'yes', 'single', '/content/audio.wav'], check=True, capture_output=True)
106
+ 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)
107
+ with open("test.json", "w") as f:
108
+ f.write(jq_run.stdout.decode('utf-8').strip())
109
+
110
+ 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")
111
+
112
+ #1. Extract the frames from the video file using PyVideoFramesExtractor
113
+ os.system(f"python /content/PyVideoFramesExtractor/extract.py --video=/content/train/image_pre_audio.mp4")
114
+
115
+ #2. Improve image quality using GFPGAN on each frames
116
+ os.system(f"python /content/GFPGAN/inference_gfpgan.py --upscale 2 -i /content/extracted_frames/ -o /content/video_results --bg_upsampler realesrgan")
117
+
118
+ #3. Merge all the frames to a one video using imageio
119
+ path = '/content/video_results/restored_imgs'
120
+ image_folder = os.fsencode(path)
121
+ print(image_folder)
122
+ filenames = []
123
+
124
+ return "/content/audio.wav"
125
 
 
 
 
126
  elif gender == 'Male' or gender == 'male':
127
  print(gender)
128
  models, cfg, task = load_model_ensemble_and_task_from_hf_hub(