Spaces:
Sleeping
Sleeping
gorkemgoknar
commited on
Commit
•
def995e
1
Parent(s):
63c2202
Update app.py
Browse filesrestart space on unhandled error
app.py
CHANGED
@@ -8,9 +8,19 @@ import langid
|
|
8 |
import gradio as gr
|
9 |
from TTS.api import TTS
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v1")
|
12 |
tts.to("cuda")
|
13 |
|
|
|
|
|
|
|
|
|
14 |
def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree):
|
15 |
if agree == True:
|
16 |
supported_languages=["en","es","fr","de","it","pt","pl","tr","ru","nl","cs","ar","zh-cn"]
|
@@ -28,7 +38,6 @@ def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree):
|
|
28 |
if language_predicted == "zh":
|
29 |
#we use zh-cn
|
30 |
language_predicted = "zh-cn"
|
31 |
-
#This is for identifying problems only.
|
32 |
print(f"Detected language:{language_predicted}, Chosen language:{language}")
|
33 |
|
34 |
if len(prompt)>10:
|
@@ -43,7 +52,6 @@ def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree):
|
|
43 |
None,
|
44 |
)
|
45 |
|
46 |
-
|
47 |
|
48 |
if use_mic == True:
|
49 |
if mic_file_path is not None:
|
@@ -70,6 +78,13 @@ def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree):
|
|
70 |
None,
|
71 |
None,
|
72 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
try:
|
74 |
tts.tts_to_file(
|
75 |
text=prompt,
|
@@ -78,14 +93,22 @@ def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree):
|
|
78 |
language=language,
|
79 |
)
|
80 |
except RuntimeError as e :
|
81 |
-
if "device-assert" in str(e):
|
82 |
# cannot do anything on cuda device side error, need tor estart
|
|
|
83 |
gr.Warning("Unhandled Exception encounter, please retry in a minute")
|
84 |
print("Cuda device-assert Runtime encountered need restart")
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
else:
|
|
|
87 |
raise e
|
88 |
-
|
89 |
return (
|
90 |
gr.make_waveform(
|
91 |
audio="output.wav",
|
|
|
8 |
import gradio as gr
|
9 |
from TTS.api import TTS
|
10 |
|
11 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
12 |
+
from huggingface_hub import HfApi
|
13 |
+
# will use api to restart space on a unrecoverable error
|
14 |
+
api = HfApi(token=HF_TOKEN)
|
15 |
+
repo_id = "coqui/xtts"
|
16 |
+
|
17 |
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v1")
|
18 |
tts.to("cuda")
|
19 |
|
20 |
+
DEVICE_ASSERT_DETECTED=0
|
21 |
+
DEVICE_ASSERT_PROMPT=None
|
22 |
+
DEVICE_ASSERT_LANG=None
|
23 |
+
|
24 |
def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree):
|
25 |
if agree == True:
|
26 |
supported_languages=["en","es","fr","de","it","pt","pl","tr","ru","nl","cs","ar","zh-cn"]
|
|
|
38 |
if language_predicted == "zh":
|
39 |
#we use zh-cn
|
40 |
language_predicted = "zh-cn"
|
|
|
41 |
print(f"Detected language:{language_predicted}, Chosen language:{language}")
|
42 |
|
43 |
if len(prompt)>10:
|
|
|
52 |
None,
|
53 |
)
|
54 |
|
|
|
55 |
|
56 |
if use_mic == True:
|
57 |
if mic_file_path is not None:
|
|
|
78 |
None,
|
79 |
None,
|
80 |
)
|
81 |
+
global DEVICE_ASSERT_DETECTED
|
82 |
+
if DEVICE_ASSERT_DETECTED:
|
83 |
+
global DEVICE_ASSERT_PROMPT
|
84 |
+
global DEVICE_ASSERT_LANG
|
85 |
+
#we want to know whos caused this error
|
86 |
+
print(f"Unrecoverable exception caused by language:{DEVICE_ASSERT_LANG} prompt:{DEVICE_ASSERT_PROMPT}")
|
87 |
+
|
88 |
try:
|
89 |
tts.tts_to_file(
|
90 |
text=prompt,
|
|
|
93 |
language=language,
|
94 |
)
|
95 |
except RuntimeError as e :
|
96 |
+
if "device-side assert" in str(e):
|
97 |
# cannot do anything on cuda device side error, need tor estart
|
98 |
+
print(f"Exit due to: Unrecoverable exception caused by language:{language} prompt:{prompt}", flush=True)
|
99 |
gr.Warning("Unhandled Exception encounter, please retry in a minute")
|
100 |
print("Cuda device-assert Runtime encountered need restart")
|
101 |
+
if not DEVICE_ASSERT_DETECTED:
|
102 |
+
DEVICE_ASSERT_DETECTED=1
|
103 |
+
DEVICE_ASSERT_PROMPT=prompt
|
104 |
+
DEVICE_ASSERT_LANG=language
|
105 |
+
|
106 |
+
|
107 |
+
# HF Space specific.. This error is unrecoverable need to restart space
|
108 |
+
api.restart_space(repo_id=repo_id)
|
109 |
else:
|
110 |
+
print("RuntimeError: non device-side assert error:", str(e))
|
111 |
raise e
|
|
|
112 |
return (
|
113 |
gr.make_waveform(
|
114 |
audio="output.wav",
|