Hev832 commited on
Commit
4027ab4
·
verified ·
1 Parent(s): a4338e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -10
app.py CHANGED
@@ -73,8 +73,6 @@ def play_audio(file_path):
73
 
74
 
75
 
76
-
77
-
78
  def download_audio(url):
79
  ydl_opts = {
80
  'format': 'bestaudio/best',
@@ -213,30 +211,38 @@ def extract_zip(extraction_folder, zip_name):
213
  if os.path.isdir(os.path.join(extraction_folder, filepath)):
214
  shutil.rmtree(os.path.join(extraction_folder, filepath))
215
 
216
- def download_online_model(url, dir_name):
 
217
  try:
218
  print(f'[~] Downloading voice model with name {dir_name}...')
219
  zip_name = url.split('/')[-1]
220
  extraction_folder = os.path.join(models_dir, dir_name)
 
221
  if os.path.exists(extraction_folder):
222
- raise Exception(f'Voice model directory {dir_name} already exists! Choose a different name for your voice model.')
223
 
 
224
  if 'pixeldrain.com' in url:
225
  url = f'https://pixeldrain.com/api/file/{zip_name}'
226
- if 'drive.google.com' in url:
227
- zip_name = dir_name + ".zip"
228
- gdown.download(url, output=zip_name, use_cookies=True, quiet=True, fuzzy=True)
 
 
229
  else:
 
230
  urllib.request.urlretrieve(url, zip_name)
231
 
232
  print(f'[~] Extracting zip file...')
233
  extract_zip(extraction_folder, zip_name)
234
  print(f'[+] {dir_name} Model successfully downloaded!')
 
 
 
235
 
236
  except Exception as e:
237
- raise Exception(str(e))
238
-
239
-
240
 
241
 
242
  if __name__ == '__main__':
 
73
 
74
 
75
 
 
 
76
  def download_audio(url):
77
  ydl_opts = {
78
  'format': 'bestaudio/best',
 
211
  if os.path.isdir(os.path.join(extraction_folder, filepath)):
212
  shutil.rmtree(os.path.join(extraction_folder, filepath))
213
 
214
+
215
+ def download_online_model(url, dir_name, models_dir='./models'):
216
  try:
217
  print(f'[~] Downloading voice model with name {dir_name}...')
218
  zip_name = url.split('/')[-1]
219
  extraction_folder = os.path.join(models_dir, dir_name)
220
+
221
  if os.path.exists(extraction_folder):
222
+ return f'[!] Voice model directory {dir_name} already exists! Choose a different name for your voice model.'
223
 
224
+ # Download from pixeldrain
225
  if 'pixeldrain.com' in url:
226
  url = f'https://pixeldrain.com/api/file/{zip_name}'
227
+ urllib.request.urlretrieve(url, zip_name)
228
+ # Download from Google Drive
229
+ elif 'drive.google.com' in url:
230
+ zip_name = dir_name + ".zip"
231
+ gdown.download(url, output=zip_name, use_cookies=True, quiet=True)
232
  else:
233
+ # General URL download
234
  urllib.request.urlretrieve(url, zip_name)
235
 
236
  print(f'[~] Extracting zip file...')
237
  extract_zip(extraction_folder, zip_name)
238
  print(f'[+] {dir_name} Model successfully downloaded!')
239
+
240
+ # Return success message after successful download
241
+ return f"[+] {dir_name} Model successfully downloaded!"
242
 
243
  except Exception as e:
244
+ # Return the error message instead of raising an exception
245
+ return f'[!] Error: {str(e)}'
 
246
 
247
 
248
  if __name__ == '__main__':