Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,7 +20,6 @@ os.system("python -m unidic download")
|
|
| 20 |
HF_TOKEN = None
|
| 21 |
api = HfApi(token=HF_TOKEN)
|
| 22 |
|
| 23 |
-
print("Downloading if not downloaded viXTTS")
|
| 24 |
checkpoint_dir = "model/"
|
| 25 |
repo_id = "capleaf/viXTTS"
|
| 26 |
use_deepspeed = False
|
|
@@ -87,7 +86,7 @@ def calculate_keep_len(text, lang):
|
|
| 87 |
return -1
|
| 88 |
|
| 89 |
|
| 90 |
-
@spaces.GPU
|
| 91 |
def predict(
|
| 92 |
prompt,
|
| 93 |
language,
|
|
@@ -139,7 +138,6 @@ def predict(
|
|
| 139 |
if normalize_text and language == "vi":
|
| 140 |
prompt = normalize_vietnamese_text(prompt)
|
| 141 |
|
| 142 |
-
print("Generando nuevo audio...")
|
| 143 |
t0 = time.time()
|
| 144 |
out = MODEL.inference(
|
| 145 |
prompt,
|
|
@@ -151,12 +149,10 @@ def predict(
|
|
| 151 |
enable_text_splitting=True,
|
| 152 |
)
|
| 153 |
inference_time = time.time() - t0
|
| 154 |
-
print(f"Tiempo de generaci贸n de audio: {round(inference_time*1000)} milisegundos")
|
| 155 |
metrics_text += (
|
| 156 |
f"Tiempo de generaci贸n de audio: {round(inference_time*1000)} milisegundos\n"
|
| 157 |
)
|
| 158 |
real_time_factor = (time.time() - t0) / out["wav"].shape[-1] * 24000
|
| 159 |
-
print(f"Factor de tiempo real (RTF): {real_time_factor}")
|
| 160 |
metrics_text += f"Factor de tiempo real (RTF): {real_time_factor:.2f}\n"
|
| 161 |
|
| 162 |
keep_len = calculate_keep_len(prompt, language)
|
|
@@ -166,13 +162,6 @@ def predict(
|
|
| 166 |
|
| 167 |
except RuntimeError as e:
|
| 168 |
if "device-side assert" in str(e):
|
| 169 |
-
print(
|
| 170 |
-
f"Exit due to: Unrecoverable exception caused by language:{language} prompt:{prompt}",
|
| 171 |
-
flush=True,
|
| 172 |
-
)
|
| 173 |
-
gr.Warning("Se ha producido un error. Por favor, int茅ntalo de nuevo en un minuto.")
|
| 174 |
-
print("Cuda device-assert Runtime encountered need restart")
|
| 175 |
-
|
| 176 |
error_time = datetime.datetime.now().strftime("%d-%m-%Y-%H:%M:%S")
|
| 177 |
error_data = [
|
| 178 |
error_time,
|
|
@@ -181,14 +170,11 @@ def predict(
|
|
| 181 |
audio_file_pth,
|
| 182 |
]
|
| 183 |
error_data = [str(e) if type(e) != str else e for e in error_data]
|
| 184 |
-
print(error_data)
|
| 185 |
-
print(speaker_wav)
|
| 186 |
write_io = StringIO()
|
| 187 |
csv.writer(write_io).writerows([error_data])
|
| 188 |
csv_upload = write_io.getvalue().encode()
|
| 189 |
|
| 190 |
filename = error_time + "_" + str(uuid.uuid4()) + ".csv"
|
| 191 |
-
print("Writing error csv")
|
| 192 |
error_api = HfApi()
|
| 193 |
error_api.upload_file(
|
| 194 |
path_or_fileobj=csv_upload,
|
|
@@ -197,7 +183,6 @@ def predict(
|
|
| 197 |
repo_type="dataset",
|
| 198 |
)
|
| 199 |
|
| 200 |
-
print("Writing error reference audio")
|
| 201 |
speaker_filename = error_time + "_reference_" + str(uuid.uuid4()) + ".wav"
|
| 202 |
error_api = HfApi()
|
| 203 |
error_api.upload_file(
|
|
@@ -210,17 +195,13 @@ def predict(
|
|
| 210 |
space = api.get_space_runtime(repo_id=repo_id)
|
| 211 |
if space.stage != "BUILDING":
|
| 212 |
api.restart_space(repo_id=repo_id)
|
| 213 |
-
else:
|
| 214 |
-
print("TRIED TO RESTART but space is building")
|
| 215 |
|
| 216 |
else:
|
| 217 |
if "Failed to decode" in str(e):
|
| 218 |
-
print("Speaker encoding error", str(e))
|
| 219 |
metrics_text = gr.Warning(
|
| 220 |
metrics_text="Parece que hay un problema con la referencia de audio. 驴Has activado el micr贸fono?"
|
| 221 |
)
|
| 222 |
else:
|
| 223 |
-
print("RuntimeError: non device-side assert error:", str(e))
|
| 224 |
metrics_text = gr.Warning(
|
| 225 |
"Se ha producido un error inesperado. Por favor, int茅ntalo de nuevo."
|
| 226 |
)
|
|
|
|
| 20 |
HF_TOKEN = None
|
| 21 |
api = HfApi(token=HF_TOKEN)
|
| 22 |
|
|
|
|
| 23 |
checkpoint_dir = "model/"
|
| 24 |
repo_id = "capleaf/viXTTS"
|
| 25 |
use_deepspeed = False
|
|
|
|
| 86 |
return -1
|
| 87 |
|
| 88 |
|
| 89 |
+
@spaces.GPU(duration=0)
|
| 90 |
def predict(
|
| 91 |
prompt,
|
| 92 |
language,
|
|
|
|
| 138 |
if normalize_text and language == "vi":
|
| 139 |
prompt = normalize_vietnamese_text(prompt)
|
| 140 |
|
|
|
|
| 141 |
t0 = time.time()
|
| 142 |
out = MODEL.inference(
|
| 143 |
prompt,
|
|
|
|
| 149 |
enable_text_splitting=True,
|
| 150 |
)
|
| 151 |
inference_time = time.time() - t0
|
|
|
|
| 152 |
metrics_text += (
|
| 153 |
f"Tiempo de generaci贸n de audio: {round(inference_time*1000)} milisegundos\n"
|
| 154 |
)
|
| 155 |
real_time_factor = (time.time() - t0) / out["wav"].shape[-1] * 24000
|
|
|
|
| 156 |
metrics_text += f"Factor de tiempo real (RTF): {real_time_factor:.2f}\n"
|
| 157 |
|
| 158 |
keep_len = calculate_keep_len(prompt, language)
|
|
|
|
| 162 |
|
| 163 |
except RuntimeError as e:
|
| 164 |
if "device-side assert" in str(e):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
error_time = datetime.datetime.now().strftime("%d-%m-%Y-%H:%M:%S")
|
| 166 |
error_data = [
|
| 167 |
error_time,
|
|
|
|
| 170 |
audio_file_pth,
|
| 171 |
]
|
| 172 |
error_data = [str(e) if type(e) != str else e for e in error_data]
|
|
|
|
|
|
|
| 173 |
write_io = StringIO()
|
| 174 |
csv.writer(write_io).writerows([error_data])
|
| 175 |
csv_upload = write_io.getvalue().encode()
|
| 176 |
|
| 177 |
filename = error_time + "_" + str(uuid.uuid4()) + ".csv"
|
|
|
|
| 178 |
error_api = HfApi()
|
| 179 |
error_api.upload_file(
|
| 180 |
path_or_fileobj=csv_upload,
|
|
|
|
| 183 |
repo_type="dataset",
|
| 184 |
)
|
| 185 |
|
|
|
|
| 186 |
speaker_filename = error_time + "_reference_" + str(uuid.uuid4()) + ".wav"
|
| 187 |
error_api = HfApi()
|
| 188 |
error_api.upload_file(
|
|
|
|
| 195 |
space = api.get_space_runtime(repo_id=repo_id)
|
| 196 |
if space.stage != "BUILDING":
|
| 197 |
api.restart_space(repo_id=repo_id)
|
|
|
|
|
|
|
| 198 |
|
| 199 |
else:
|
| 200 |
if "Failed to decode" in str(e):
|
|
|
|
| 201 |
metrics_text = gr.Warning(
|
| 202 |
metrics_text="Parece que hay un problema con la referencia de audio. 驴Has activado el micr贸fono?"
|
| 203 |
)
|
| 204 |
else:
|
|
|
|
| 205 |
metrics_text = gr.Warning(
|
| 206 |
"Se ha producido un error inesperado. Por favor, int茅ntalo de nuevo."
|
| 207 |
)
|