r3gm commited on
Commit
e0aa8ed
1 Parent(s): 204ab96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +251 -0
app.py CHANGED
@@ -0,0 +1,251 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #@title <font color='#fffff'>(1) Initialize External Code</font>
2
+ import time
3
+ import os
4
+ import subprocess
5
+ import shutil
6
+ from IPython.utils import capture
7
+ from subprocess import getoutput
8
+ from urllib.parse import unquote
9
+ from google.colab.output import eval_js
10
+ os.environ["colab_url"] = eval_js("google.colab.kernel.proxyPort(7860, {'cache': false})")
11
+ # Store the current working directory
12
+ current_path = os.getcwd()
13
+
14
+ # Clear the /content/ directory
15
+ # try:
16
+ # output
17
+ # except:
18
+ # print('\r\033[91m⌚ Checking GPU...', end='')
19
+ # output = getoutput('nvidia-smi --query-gpu=gpu_name --format=csv')
20
+ # if "name" in output:
21
+ # gpu_name = output[5:]
22
+ # print('\r\033[96m✅ GPU Actual:', gpu_name, flush=True)
23
+ # else:
24
+ # print('\r\033[91m❎ ERROR: No GPU detected. Please do step below to enable.\n', flush=True)
25
+ # print('\033[91m\nIf it says "Cannot connect to GPU backend", meaning you\'ve either reached free usage limit. OR there\'s no gpu available.\n\nDon\'t mind me... I\'m destroying your current session for your own good...')
26
+ # time.sleep(5)
27
+ # from google.colab import runtime
28
+ # runtime.unassign()
29
+
30
+ # Change the current working directory back to the original path
31
+ os.chdir(current_path)
32
+
33
+ start_time = time.time()
34
+
35
+ !nvidia-smi
36
+
37
+ # Clone the repository using the complete phrase as the folder name
38
+ maville = "R"
39
+ acat = "VC"
40
+ juxxn = maville + acat
41
+ !git clone https://github.com/IAHispano/Applio-Utilities ./Applio-$juxxn-Fork/utils
42
+
43
+ end_time = time.time()
44
+ elapsed_time = end_time - start_time
45
+ print(f'\r\033[96mTime taken for utils Download: {elapsed_time} seconds')
46
+
47
+
48
+ #@title <font color='#fffff'>(2) Fix dependencies</font>
49
+ import zipfile
50
+ from tqdm import tqdm
51
+ import threading
52
+ from IPython.display import HTML, clear_output
53
+ start_time = time.time()
54
+
55
+ maville = "R"
56
+ acat = "VC"
57
+ juxxn = maville + acat
58
+ complete_phrase = './Applio-'+juxxn+'-Fork/'
59
+ os.chdir(f'./Applio-{juxxn}-Fork/')
60
+ from utils.dependency import *
61
+ from utils.clonerepo_experimental import *
62
+ os.chdir("..")
63
+
64
+ end_time = time.time()
65
+ elapsed_time = end_time - start_time
66
+ print(f"Time taken for imports: {elapsed_time} seconds")
67
+
68
+
69
+ ForceUpdateDependencies = False
70
+
71
+ ForceTemporaryStorage = True
72
+
73
+ # Setup environment
74
+ print("Attempting to setup environment dependencies...")
75
+ print("\n----------------------------------------")
76
+
77
+ start_time_setup = time.time()
78
+ setup_environment(ForceUpdateDependencies, ForceTemporaryStorage)
79
+
80
+ # Apparently fastapi is getting errors as of writing according to #help-rvc
81
+ !pip install fastapi==0.88.0
82
+
83
+ end_time_setup = time.time()
84
+ elapsed_time_setup = end_time_setup - start_time_setup
85
+ print(f"Time taken for setup environment: {elapsed_time_setup} seconds")
86
+
87
+ print("----------------------------------------\n")
88
+ print("Attempting to clone necessary files...")
89
+ print("\n----------------------------------------")
90
+
91
+ start_time_clone = time.time()
92
+ clone_repository(True)
93
+ part2 = "I"
94
+ # Define the base URL without the prohibited phrase
95
+ base_url = f"https://huggingface.co/lj1995/VoiceConversionWebU{part2}"
96
+
97
+ # Add the missing "I" to create the complete URL
98
+ complete_url = base_url + "/resolve/main/rmvpe.pt"
99
+
100
+ # Download the file using the complete URL
101
+ !wget {complete_url} -P {complete_phrase}
102
+
103
+ end_time_clone = time.time()
104
+ elapsed_time_clone = end_time_clone - start_time_clone
105
+ print(f"Time taken for clone repository: {elapsed_time_clone} seconds")
106
+
107
+ print("----------------------------------------\n")
108
+ print("Cell completed.")
109
+
110
+ total_time = elapsed_time + elapsed_time_setup + elapsed_time_clone
111
+ print(f"Total time taken: {total_time} seconds")
112
+
113
+ !pip install -q stftpitchshift==1.5.1
114
+ !pip install gradio==3.34.0
115
+ !pip install yt-dlp
116
+ !pip install pedalboard
117
+ !pip install pathvalidate
118
+ !pip install nltk
119
+ !pip install edge-tts
120
+ !pip install git+https://github.com/suno-ai/bark.git
121
+ !pip install wget -q
122
+ !pip install unidecode -q
123
+ !pip install gtts
124
+ !pip install pip install tensorboardX
125
+ namepython = "infer-web.py"
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+ #@title <font color='#fffff'>(3) Run interface</font>
145
+ import time
146
+ import os
147
+ import random
148
+ import string
149
+ import subprocess
150
+ import shutil
151
+ import threading
152
+ import time
153
+ import zipfile
154
+ from IPython.display import HTML, clear_output
155
+ global namepython
156
+
157
+ maville = "RVC"
158
+ juxxn = maville
159
+ #@markdown **Settings:**
160
+ #@markdown Restore your backup from Google Drive.
161
+ LoadBackupDrive = False #@param{type:"boolean"}
162
+ #@markdown Make regular backups of your model's training.
163
+ AutoBackups = True #@param{type:"boolean"}
164
+
165
+ complete_phrase = './Applio-'+juxxn+'-Fork/'
166
+ os.chdir(f'./Applio-{juxxn}-Fork/')
167
+ from utils import backups
168
+
169
+ def generate_random_string(length=6):
170
+ characters = string.ascii_lowercase + string.digits
171
+ return ''.join(random.choice(characters) for _ in range(length))
172
+
173
+ parte_aleatoria = generate_random_string()
174
+
175
+ if namepython == "infer-web.py":
176
+ nuevo_nombre = f"AcatUI_{parte_aleatoria}.py"
177
+ os.rename(os.path.join(complete_phrase, "infer-web.py"), os.path.join(complete_phrase, nuevo_nombre))
178
+ namepython = nuevo_nombre
179
+
180
+ LOGS_FOLDER = './Applio-' + juxxn + '-Fork/logs'
181
+ if not os.path.exists(LOGS_FOLDER):
182
+ os.makedirs(LOGS_FOLDER)
183
+ clear_output()
184
+
185
+ WEIGHTS_FOLDER = './Applio-' + juxxn + '-Fork' + '/logs' + '/weights'
186
+ if not os.path.exists(WEIGHTS_FOLDER):
187
+ os.makedirs(WEIGHTS_FOLDER)
188
+ clear_output()
189
+
190
+ others_FOLDER = './Applio-' + juxxn + '-Fork' + '/audio-others'
191
+ if not os.path.exists(others_FOLDER):
192
+ os.makedirs(others_FOLDER)
193
+ clear_output()
194
+
195
+ audio_outputs_FOLDER = './Applio-' + juxxn + '-Fork' + '/audio-outputs'
196
+ if not os.path.exists(audio_outputs_FOLDER):
197
+ os.makedirs(audio_outputs_FOLDER)
198
+ clear_output()
199
+
200
+ #@markdown Choose the language in which you want the interface to be available.
201
+ i18n_path = './Applio-' + juxxn + '-Fork/' + 'i18n.py'
202
+ i18n_new_path = './Applio-' + juxxn + '-Fork/' + 'utils/i18n.py'
203
+ try:
204
+ if os.path.exists(i18n_path) and os.path.exists(i18n_new_path):
205
+ shutil.move(i18n_new_path, i18n_path)
206
+ except FileNotFoundError:
207
+ print("Translation couldn't be applied successfully. Please restart the environment and run the cell again.")
208
+ clear_output()
209
+ SelectedLanguage = "en_US" #@param ["es_ES", "en_US", "zh_CN", "ar_AR", "id_ID", "pt_PT", "pt_BR", "ru_RU", "ur_UR", "tr_TR", "it_IT", "de_DE"]
210
+ new_language_line = ' language = "' + SelectedLanguage + '"\n'
211
+
212
+ try:
213
+ with open(i18n_path, 'r') as file:
214
+ lines = file.readlines()
215
+
216
+ with open(i18n_path, 'w') as file:
217
+ for index, line in enumerate(lines):
218
+ if index == 14:
219
+ file.write(new_language_line)
220
+ else:
221
+ file.write(line)
222
+
223
+ except FileNotFoundError:
224
+ print("Translation couldn't be applied successfully. Please restart the environment and run the cell again.")
225
+ clear_output()
226
+
227
+
228
+
229
+ def tempus_killed_server():
230
+ %cd ./Retrieval-based-{complete_phrase}
231
+ %load_ext tensorboard
232
+ clear_output()
233
+ %tensorboard --logdir ./Applio-$juxxn-Fork/logs
234
+ !mkdir -p ./Applio-$juxxn-Fork/audios
235
+ print("Try")
236
+ arguments = "--colab --pycmd python3"
237
+ !python3 $namepython $arguments
238
+
239
+
240
+ if LoadBackupDrive:
241
+ backups.import_google_drive_backup()
242
+
243
+
244
+ server_thread = threading.Thread(target=tempus_killed_server)
245
+ server_thread.start()
246
+
247
+ if AutoBackups:
248
+ backups.backup_files()
249
+ else:
250
+ while True:
251
+ time.sleep(11) # sleep for 10 seconds