Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -97,8 +97,29 @@ def generate_speech_from_text(message: str, huggingface_token: str) -> None:
|
|
97 |
API_URL = "https://api-inference.huggingface.co/models/espnet/kan-bayashi_ljspeech_vits"
|
98 |
headers = {"Authorization": f"Bearer {huggingface_token}"}
|
99 |
payloads = {"inputs": message}
|
100 |
-
|
101 |
response = requests.post(API_URL, headers=headers, json=payloads)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
with open("generated_audio.flac", "wb") as file:
|
103 |
file.write(response.content)
|
104 |
|
|
|
97 |
API_URL = "https://api-inference.huggingface.co/models/espnet/kan-bayashi_ljspeech_vits"
|
98 |
headers = {"Authorization": f"Bearer {huggingface_token}"}
|
99 |
payloads = {"inputs": message}
|
100 |
+
|
101 |
response = requests.post(API_URL, headers=headers, json=payloads)
|
102 |
+
|
103 |
+
# Handle model loading
|
104 |
+
if response.status_code == 503:
|
105 |
+
try:
|
106 |
+
info = response.json()
|
107 |
+
wait_time = round(info.get("estimated_time", 10))
|
108 |
+
except Exception:
|
109 |
+
wait_time = 10
|
110 |
+
st.warning(f"Model is loading... please wait ~{wait_time} seconds and try again.")
|
111 |
+
return
|
112 |
+
|
113 |
+
# Handle other errors
|
114 |
+
if response.status_code != 200:
|
115 |
+
try:
|
116 |
+
error_message = response.json().get("error", "Unknown error")
|
117 |
+
except Exception:
|
118 |
+
error_message = "Unknown error"
|
119 |
+
st.error(f"⚠️ Audio generation failed: {response.status_code} - {error_message}")
|
120 |
+
return
|
121 |
+
|
122 |
+
# Save audio if successful
|
123 |
with open("generated_audio.flac", "wb") as file:
|
124 |
file.write(response.content)
|
125 |
|