Spaces:
Sleeping
Sleeping
poemsforaphrodite
commited on
Commit
•
0f6f40a
1
Parent(s):
b083629
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
3 |
from requests.exceptions import ConnectionError, SSLError, Timeout
|
4 |
|
|
|
|
|
|
|
|
|
5 |
def clone_voice(text, audio_file):
|
6 |
if audio_file is None:
|
7 |
raise gr.Error("Please upload an audio file.")
|
@@ -20,37 +25,58 @@ def clone_voice(text, audio_file):
|
|
20 |
|
21 |
# API endpoint
|
22 |
api_url = "https://tellergen.com/api/clone-voice"
|
23 |
-
|
|
|
|
|
24 |
# Make the request
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
response.raise_for_status()
|
33 |
|
34 |
# Check if the request was successful
|
35 |
if response.status_code == 200:
|
36 |
content_type = response.headers.get('Content-Type')
|
|
|
|
|
37 |
if 'audio' in content_type:
|
38 |
-
# Return the audio response
|
39 |
return response.content
|
40 |
else:
|
41 |
-
# If not audio response, raise an error
|
42 |
response_text = response.json() if response.headers.get('Content-Type') == 'application/json' else response.text
|
|
|
43 |
raise gr.Error(f"Unexpected response: {response_text}")
|
44 |
else:
|
|
|
45 |
raise gr.Error(f"API request failed with status code {response.status_code}")
|
46 |
|
47 |
-
except ConnectionError:
|
|
|
48 |
raise gr.Error("Connection error. Please check your internet connection and try again.")
|
49 |
-
except SSLError:
|
|
|
50 |
raise gr.Error("SSL Error occurred. Please try again later.")
|
51 |
-
except Timeout:
|
|
|
52 |
raise gr.Error("Request timed out. Please try again later.")
|
53 |
except Exception as e:
|
|
|
54 |
raise gr.Error(f"An unexpected error occurred: {str(e)}")
|
55 |
finally:
|
56 |
# Close the file if it was opened
|
@@ -75,4 +101,4 @@ demo = gr.Interface(
|
|
75 |
)
|
76 |
|
77 |
if __name__ == "__main__":
|
78 |
-
demo.launch(
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
+
import logging
|
4 |
from requests.exceptions import ConnectionError, SSLError, Timeout
|
5 |
|
6 |
+
# Set up logging
|
7 |
+
logging.basicConfig(level=logging.INFO)
|
8 |
+
logger = logging.getLogger(__name__)
|
9 |
+
|
10 |
def clone_voice(text, audio_file):
|
11 |
if audio_file is None:
|
12 |
raise gr.Error("Please upload an audio file.")
|
|
|
25 |
|
26 |
# API endpoint
|
27 |
api_url = "https://tellergen.com/api/clone-voice"
|
28 |
+
|
29 |
+
logger.info(f"Making request to {api_url}")
|
30 |
+
|
31 |
# Make the request
|
32 |
+
try:
|
33 |
+
# First try with SSL verification
|
34 |
+
response = requests.post(
|
35 |
+
api_url,
|
36 |
+
data=payload,
|
37 |
+
files=files,
|
38 |
+
timeout=30
|
39 |
+
)
|
40 |
+
except SSLError:
|
41 |
+
logger.warning("SSL verification failed, retrying without verification")
|
42 |
+
# If SSL fails, retry without verification
|
43 |
+
response = requests.post(
|
44 |
+
api_url,
|
45 |
+
data=payload,
|
46 |
+
files=files,
|
47 |
+
verify=False,
|
48 |
+
timeout=30
|
49 |
+
)
|
50 |
+
|
51 |
+
logger.info(f"Response status code: {response.status_code}")
|
52 |
response.raise_for_status()
|
53 |
|
54 |
# Check if the request was successful
|
55 |
if response.status_code == 200:
|
56 |
content_type = response.headers.get('Content-Type')
|
57 |
+
logger.info(f"Response content type: {content_type}")
|
58 |
+
|
59 |
if 'audio' in content_type:
|
|
|
60 |
return response.content
|
61 |
else:
|
|
|
62 |
response_text = response.json() if response.headers.get('Content-Type') == 'application/json' else response.text
|
63 |
+
logger.error(f"Unexpected response content type: {content_type}, response: {response_text}")
|
64 |
raise gr.Error(f"Unexpected response: {response_text}")
|
65 |
else:
|
66 |
+
logger.error(f"API request failed with status code {response.status_code}")
|
67 |
raise gr.Error(f"API request failed with status code {response.status_code}")
|
68 |
|
69 |
+
except ConnectionError as e:
|
70 |
+
logger.error(f"Connection error: {str(e)}")
|
71 |
raise gr.Error("Connection error. Please check your internet connection and try again.")
|
72 |
+
except SSLError as e:
|
73 |
+
logger.error(f"SSL Error: {str(e)}")
|
74 |
raise gr.Error("SSL Error occurred. Please try again later.")
|
75 |
+
except Timeout as e:
|
76 |
+
logger.error(f"Timeout error: {str(e)}")
|
77 |
raise gr.Error("Request timed out. Please try again later.")
|
78 |
except Exception as e:
|
79 |
+
logger.error(f"Unexpected error: {str(e)}")
|
80 |
raise gr.Error(f"An unexpected error occurred: {str(e)}")
|
81 |
finally:
|
82 |
# Close the file if it was opened
|
|
|
101 |
)
|
102 |
|
103 |
if __name__ == "__main__":
|
104 |
+
demo.launch()
|