Hev832 commited on
Commit
a0cc1ae
1 Parent(s): 72ae837

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -90
app.py CHANGED
@@ -1,28 +1,5 @@
1
- import os
2
- import re
3
- import random
4
- from scipy.io.wavfile import write
5
- from scipy.io.wavfile import read
6
- import numpy as np
7
- import gradio as gr
8
- import yt_dlp
9
- import subprocess
10
- from pydub import AudioSegment
11
- from audio_separator.separator import Separator
12
- from lib.infer import infer_audio
13
- import edge_tts
14
- import tempfile
15
- import anyio
16
- from pathlib import Path
17
- from lib.language_tts import language_dict
18
- import os
19
- import zipfile
20
- import shutil
21
- import urllib.request
22
- import gdown
23
- import subprocess
24
- import time
25
- from argparse import ArgumentParser
26
  main_dir = Path().resolve()
27
  print(main_dir)
28
 
@@ -46,8 +23,6 @@ def refresh_folders():
46
 
47
 
48
 
49
-
50
-
51
  # Function to get the list of audio files in the specified directory
52
  def get_audio_files():
53
  if not os.path.exists(AUDIO_DIR):
@@ -72,7 +47,6 @@ def play_audio(file_path):
72
 
73
 
74
 
75
-
76
  def download_audio(url):
77
  ydl_opts = {
78
  'format': 'bestaudio/best',
@@ -94,7 +68,6 @@ def download_audio(url):
94
 
95
 
96
 
97
-
98
  # Define a function to handle the entire separation process
99
  def separate_audio(input_audio, model_voc_inst, model_deecho, model_back_voc):
100
  output_dir = audio_separat_dir
@@ -183,67 +156,6 @@ async def text_to_speech_edge(text, language_code):
183
 
184
 
185
 
186
- def extract_zip(extraction_folder, zip_name):
187
- os.makedirs(extraction_folder)
188
- with zipfile.ZipFile(zip_name, 'r') as zip_ref:
189
- zip_ref.extractall(extraction_folder)
190
- os.remove(zip_name)
191
-
192
- index_filepath, model_filepath = None, None
193
- for root, dirs, files in os.walk(extraction_folder):
194
- for name in files:
195
- if name.endswith('.index') and os.stat(os.path.join(root, name)).st_size > 1024 * 100:
196
- index_filepath = os.path.join(root, name)
197
-
198
- if name.endswith('.pth') and os.stat(os.path.join(root, name)).st_size > 1024 * 1024 * 40:
199
- model_filepath = os.path.join(root, name)
200
-
201
- if not model_filepath:
202
- raise Exception(f'No .pth model file was found in the extracted zip. Please check {extraction_folder}.')
203
-
204
- # move model and index file to extraction folder
205
- os.rename(model_filepath, os.path.join(extraction_folder, os.path.basename(model_filepath)))
206
- if index_filepath:
207
- os.rename(index_filepath, os.path.join(extraction_folder, os.path.basename(index_filepath)))
208
-
209
- # remove any unnecessary nested folders
210
- for filepath in os.listdir(extraction_folder):
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='./rvc_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__':
249
  parser = ArgumentParser(description='Generate a AI song in the song_output/id directory.', add_help=True)
 
1
+
2
+ from module import *
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  main_dir = Path().resolve()
4
  print(main_dir)
5
 
 
23
 
24
 
25
 
 
 
26
  # Function to get the list of audio files in the specified directory
27
  def get_audio_files():
28
  if not os.path.exists(AUDIO_DIR):
 
47
 
48
 
49
 
 
50
  def download_audio(url):
51
  ydl_opts = {
52
  'format': 'bestaudio/best',
 
68
 
69
 
70
 
 
71
  # Define a function to handle the entire separation process
72
  def separate_audio(input_audio, model_voc_inst, model_deecho, model_back_voc):
73
  output_dir = audio_separat_dir
 
156
 
157
 
158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
 
160
  if __name__ == '__main__':
161
  parser = ArgumentParser(description='Generate a AI song in the song_output/id directory.', add_help=True)