Extended TTS generation timeout in Gradio

extended the timeout to await a TTS generation response, just to help with Google colab
This commit is contained in:
erew123 authored and GitHub committed 2024-06-13 12:21:08 +01:00
1 parent 6f75ab9f60
commit 6f4bec7ab2
1 file changed
+9 -2
+9 -2
View File
@@ -1408,7 +1408,7 @@ if gradio_enabled == True:
# Restart the subprocess # Restart the subprocess
restart_subprocess() restart_subprocess()
# Wait for the engine to be ready with error handling and retries # Wait for the engine to be ready with error handling and retries
max_retries = 140 max_retries = 80
retry_delay = 1 # seconds retry_delay = 1 # seconds
retries = 0 retries = 0
while retries < max_retries: while retries < max_retries:
@@ -1654,8 +1654,12 @@ if gradio_enabled == True:
"repetition_penalty": str(gen_repetition), "repetition_penalty": str(gen_repetition),
} }
#print(f"Debug: Generate request param:", data) if params["debug_tts"] else None #print(f"Debug: Generate request param:", data) if params["debug_tts"] else None
max_retries = 180 #3 minutes
retry_delay = 1 # seconds
retries = 0
while retries < max_retries:
try: try:
response = requests.post(api_url, data=data) response = requests.post(api_url, data=data, timeout=60)
response.raise_for_status() # Raise an exception for 4xx or 5xx status codes response.raise_for_status() # Raise an exception for 4xx or 5xx status codes
result = response.json() result = response.json()
if gen_autopl == "true": if gen_autopl == "true":
@@ -1673,11 +1677,14 @@ if gradio_enabled == True:
output_file_url = f"{protocol}{my_current_url}{result['output_file_url']}" output_file_url = f"{protocol}{my_current_url}{result['output_file_url']}"
return output_file_url, str("TTS Audio Generated") return output_file_url, str("TTS Audio Generated")
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
retries += 1
if retries == max_retries:
error_message = "An error occurred. Please see console output." error_message = "An error occurred. Please see console output."
print(f"[{branding}TTS] \033[91mError:\033[0m {error_message}") print(f"[{branding}TTS] \033[91mError:\033[0m {error_message}")
print(f"[{branding}TTS] \033[91mError Details:\033[0m {str(e)}") print(f"[{branding}TTS] \033[91mError Details:\033[0m {str(e)}")
# Handle the error or return an appropriate error message # Handle the error or return an appropriate error message
return None, str(error_message) return None, str(error_message)
time.sleep(retry_delay)
def alltalk_gradio(): def alltalk_gradio():
global languages_list, at_settings global languages_list, at_settings