pragnakalp commited on
Commit
8e793e9
·
1 Parent(s): 2bc8f03

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -13,6 +13,8 @@ import cv2
13
  import imageio
14
  import os
15
  import ffmpeg
 
 
16
 
17
  from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf_hub
18
  from fairseq.models.text_to_speech.hub_interface import TTSHubInterface
@@ -88,7 +90,14 @@ def calculate(image_in, audio_in):
88
  waveform, sample_rate = torchaudio.load(audio_in)
89
  waveform = torch.mean(waveform, dim=0, keepdim=True)
90
  torchaudio.save("/content/audio.wav", waveform, sample_rate, encoding="PCM_S", bits_per_sample=16)
91
- image = Image.open(image_in)
 
 
 
 
 
 
 
92
  image = pad_image(image)
93
  # os.system(f"rm -rf /content/image.png")
94
  image.save("image.png")
@@ -144,7 +153,7 @@ def one_shot_talking(image_in,audio_in):
144
  os.makedirs("/content/results")
145
 
146
  #Improve quality of input image
147
- os.system(f"python /content/GFPGAN/inference_gfpgan.py --upscale 2 -i /content/image_pre.png -o /content/results --bg_upsampler realesrgan")
148
  # time.sleep(60)
149
 
150
  image_in_one_shot='/content/results/image_pre.png'
 
13
  import imageio
14
  import os
15
  import ffmpeg
16
+ from io import BytesIO
17
+ import requests
18
 
19
  from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf_hub
20
  from fairseq.models.text_to_speech.hub_interface import TTSHubInterface
 
90
  waveform, sample_rate = torchaudio.load(audio_in)
91
  waveform = torch.mean(waveform, dim=0, keepdim=True)
92
  torchaudio.save("/content/audio.wav", waveform, sample_rate, encoding="PCM_S", bits_per_sample=16)
93
+ if os.path.exists(image_in):
94
+ image = Image.open(image_in)
95
+ else:
96
+ print("image not exists reading web image")
97
+ image_url = "http://labelme.csail.mit.edu/Release3.0/Images/users/DNguyen91/face/m_unsexy_gr.jpg"
98
+ response = requests.get(image_url)
99
+ image = Image.open(BytesIO(response.content))
100
+
101
  image = pad_image(image)
102
  # os.system(f"rm -rf /content/image.png")
103
  image.save("image.png")
 
153
  os.makedirs("/content/results")
154
 
155
  #Improve quality of input image
156
+ os.system(f"python /content/GFPGAN/inference_gfpgan.py --upscale 2 -i /content/image_pre.png -o /content/results --bg_upsampler realesrgan")
157
  # time.sleep(60)
158
 
159
  image_in_one_shot='/content/results/image_pre.png'