Update app.py
Browse files
app.py
CHANGED
@@ -45,10 +45,10 @@ def check_nsfw(prompt: str) -> bool:
|
|
45 |
|
46 |
except requests.exceptions.RequestException as e:
|
47 |
print(f"Error during NSFW check: {e}")
|
48 |
-
raise gr.Error(f"Failed to check prompt safety
|
49 |
except Exception as e:
|
50 |
print(f"Unexpected error during NSFW check: {e}")
|
51 |
-
raise gr.Error(f"An unexpected error occurred during safety check
|
52 |
|
53 |
|
54 |
def generate_audio(prompt: str, voice: str, emotion: str, seed: int) -> bytes:
|
@@ -73,7 +73,7 @@ def generate_audio(prompt: str, voice: str, emotion: str, seed: int) -> bytes:
|
|
73 |
if 'audio' not in content_type:
|
74 |
print(f"Warning: Unexpected content type received: {content_type}")
|
75 |
print(f"Response Text: {response.text[:500]}")
|
76 |
-
raise gr.Error(f"API did not return audio.
|
77 |
|
78 |
return response.content
|
79 |
|
@@ -82,10 +82,10 @@ def generate_audio(prompt: str, voice: str, emotion: str, seed: int) -> bytes:
|
|
82 |
error_details = ""
|
83 |
if hasattr(e, 'response') and e.response is not None:
|
84 |
error_details = e.response.text[:200]
|
85 |
-
raise gr.Error(f"Failed to generate audio
|
86 |
except Exception as e:
|
87 |
print(f"Unexpected error during audio generation: {e}")
|
88 |
-
raise gr.Error(f"An unexpected error occurred during audio generation
|
89 |
|
90 |
|
91 |
|
@@ -107,7 +107,7 @@ def text_to_speech_app(prompt: str, voice: str, emotion: str, use_random_seed: b
|
|
107 |
try:
|
108 |
is_nsfw = check_nsfw(prompt)
|
109 |
except gr.Error as e:
|
110 |
-
return None,
|
111 |
|
112 |
if is_nsfw:
|
113 |
print("Prompt flagged as inappropriate.")
|
|
|
45 |
|
46 |
except requests.exceptions.RequestException as e:
|
47 |
print(f"Error during NSFW check: {e}")
|
48 |
+
raise gr.Error(f"Failed to check prompt safety.")
|
49 |
except Exception as e:
|
50 |
print(f"Unexpected error during NSFW check: {e}")
|
51 |
+
raise gr.Error(f"An unexpected error occurred during safety check. Please wait for a second and try again.")
|
52 |
|
53 |
|
54 |
def generate_audio(prompt: str, voice: str, emotion: str, seed: int) -> bytes:
|
|
|
73 |
if 'audio' not in content_type:
|
74 |
print(f"Warning: Unexpected content type received: {content_type}")
|
75 |
print(f"Response Text: {response.text[:500]}")
|
76 |
+
raise gr.Error(f"API did not return audio.")
|
77 |
|
78 |
return response.content
|
79 |
|
|
|
82 |
error_details = ""
|
83 |
if hasattr(e, 'response') and e.response is not None:
|
84 |
error_details = e.response.text[:200]
|
85 |
+
raise gr.Error(f"Failed to generate audio. Please wait for a second and try again.")
|
86 |
except Exception as e:
|
87 |
print(f"Unexpected error during audio generation: {e}")
|
88 |
+
raise gr.Error(f"An unexpected error occurred during audio generation. Please wait for a second and try again.")
|
89 |
|
90 |
|
91 |
|
|
|
107 |
try:
|
108 |
is_nsfw = check_nsfw(prompt)
|
109 |
except gr.Error as e:
|
110 |
+
return None, f"There was an error. Please wait for a second and try again."
|
111 |
|
112 |
if is_nsfw:
|
113 |
print("Prompt flagged as inappropriate.")
|