artificialguybr commited on
Commit
aa9bb98
β€’
1 Parent(s): 349cabe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -21,6 +21,8 @@ from tqdm import tqdm
21
  from numba import jit
22
 
23
  os.environ["COQUI_TOS_AGREED"] = "1"
 
 
24
 
25
  ZipFile("ffmpeg.zip").extractall()
26
  st = os.stat('ffmpeg')
@@ -82,12 +84,17 @@ def process_video(radio, video, target_language, has_closeup_face):
82
 
83
  shell_command = f"ffmpeg -y -i {run_uuid}_output_audio.wav -af lowpass=3000,highpass=100 {run_uuid}_output_audio_final.wav".split(" ")
84
  subprocess.run([item for item in shell_command], capture_output=False, text=True, check=True)
85
-
86
- segments, info = model.transcribe(f"{run_uuid}_output_audio_final.wav", beam_size=5)
87
- whisper_text = " ".join(segment.text for segment in segments)
88
- whisper_language = info.language
89
- print(whisper_text)
90
-
 
 
 
 
 
91
  language_mapping = {'English': 'en', 'Spanish': 'es', 'French': 'fr', 'German': 'de', 'Italian': 'it', 'Portuguese': 'pt', 'Polish': 'pl', 'Turkish': 'tr', 'Russian': 'ru', 'Dutch': 'nl', 'Czech': 'cs', 'Arabic': 'ar', 'Chinese (Simplified)': 'zh-cn'}
92
  target_language_code = language_mapping[target_language]
93
  translator = Translator()
@@ -149,6 +156,9 @@ def process_video(radio, video, target_language, has_closeup_face):
149
 
150
  return output_video_path
151
 
 
 
 
152
 
153
  def swap(radio):
154
  if(radio == "Upload"):
 
21
  from numba import jit
22
 
23
  os.environ["COQUI_TOS_AGREED"] = "1"
24
+ api = HfApi(token=HF_TOKEN)
25
+ repo_id = "artificialguybr/video-dubbing"
26
 
27
  ZipFile("ffmpeg.zip").extractall()
28
  st = os.stat('ffmpeg')
 
84
 
85
  shell_command = f"ffmpeg -y -i {run_uuid}_output_audio.wav -af lowpass=3000,highpass=100 {run_uuid}_output_audio_final.wav".split(" ")
86
  subprocess.run([item for item in shell_command], capture_output=False, text=True, check=True)
87
+ try:
88
+ segments, info = model.transcribe(f"{run_uuid}_output_audio_final.wav", beam_size=5)
89
+ whisper_text = " ".join(segment.text for segment in segments)
90
+ whisper_language = info.language
91
+ print(whisper_text)
92
+ except RuntimeError as e:
93
+ if "CUDA failed with error device-side assert triggered" in str(e):
94
+ gr.Warning("Error. Space need to restart. Please retry in a minute")
95
+ # Restart the script
96
+ api.restart_space(repo_id=repo_id)
97
+
98
  language_mapping = {'English': 'en', 'Spanish': 'es', 'French': 'fr', 'German': 'de', 'Italian': 'it', 'Portuguese': 'pt', 'Polish': 'pl', 'Turkish': 'tr', 'Russian': 'ru', 'Dutch': 'nl', 'Czech': 'cs', 'Arabic': 'ar', 'Chinese (Simplified)': 'zh-cn'}
99
  target_language_code = language_mapping[target_language]
100
  translator = Translator()
 
156
 
157
  return output_video_path
158
 
159
+ except RuntimeError as e:
160
+ if "CUDA failed with error device-side assert triggered" in str(e):
161
+ gr.Warning("Unhandled Exception encountered, please retry in a minute")
162
 
163
  def swap(radio):
164
  if(radio == "Upload"):