Update app.py
Browse files
app.py
CHANGED
@@ -1,98 +1,69 @@
|
|
1 |
-
import
|
2 |
import requests
|
3 |
-
from io import BytesIO
|
4 |
from requests.exceptions import ConnectionError, SSLError, Timeout
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
st.title("📢 Voice Cloning Application")
|
14 |
-
st.write("Enter the details below and upload an audio file to clone the voice.")
|
15 |
-
|
16 |
-
# Create a form for input
|
17 |
-
with st.form("voice_clone_form"):
|
18 |
-
# Text input
|
19 |
-
text = st.text_input("Text", value="مرحباً بكم في تطبيق استنساخ الصوت. يمكنك استخدام هذا التطبيق لإنشاء نسخة من صوتك باللغة العربية.")
|
20 |
-
|
21 |
-
# Language selection
|
22 |
-
language = st.selectbox("Language", options=["ar"], index=0)
|
23 |
|
24 |
-
|
25 |
-
|
|
|
|
|
26 |
|
27 |
-
|
28 |
-
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
#
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
}
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
with st.spinner("Sending request to the API..."):
|
50 |
try:
|
51 |
-
response
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
timeout=30 # Set timeout to 30 seconds
|
57 |
-
)
|
58 |
-
response.raise_for_status()
|
59 |
-
except ConnectionError as e:
|
60 |
-
st.error("Connection error. Please check your internet connection and try again.")
|
61 |
-
st.stop()
|
62 |
-
except SSLError as e:
|
63 |
-
st.error("SSL Error occurred. Please try again later.")
|
64 |
-
st.stop()
|
65 |
-
except Timeout as e:
|
66 |
-
st.error("Request timed out. Please try again later.")
|
67 |
-
st.stop()
|
68 |
-
except Exception as e:
|
69 |
-
st.error(f"An unexpected error occurred: {str(e)}")
|
70 |
-
st.stop()
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
content_type = response.headers.get('Content-Type')
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
error_data = response.json()
|
94 |
-
st.error(error_data)
|
95 |
-
except ValueError:
|
96 |
-
st.error(response.text)
|
97 |
-
except Exception as e:
|
98 |
-
st.error(f"An error occurred: {e}")
|
|
|
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 |
+
try:
|
7 |
+
# Prepare the payload
|
8 |
+
payload = {
|
9 |
+
'text': text,
|
10 |
+
'language': 'ar' # Fixed to Arabic as per original app
|
11 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
# Prepare the files
|
14 |
+
files = {
|
15 |
+
'audio_file': ('audio.wav', audio_file, 'audio/wav')
|
16 |
+
}
|
17 |
|
18 |
+
# API endpoint
|
19 |
+
api_url = "https://tellergen.com/api/clone-voice"
|
20 |
|
21 |
+
# Make the request
|
22 |
+
response = requests.post(
|
23 |
+
api_url,
|
24 |
+
data=payload,
|
25 |
+
files=files,
|
26 |
+
verify=False, # Disable SSL verification
|
27 |
+
timeout=30 # Set timeout to 30 seconds
|
28 |
+
)
|
29 |
+
response.raise_for_status()
|
|
|
30 |
|
31 |
+
# Check if the request was successful
|
32 |
+
if response.status_code == 200:
|
33 |
+
content_type = response.headers.get('Content-Type')
|
34 |
+
if 'audio' in content_type:
|
35 |
+
# Save the audio response to a temporary file
|
36 |
+
return response.content
|
37 |
+
else:
|
|
|
|
|
38 |
try:
|
39 |
+
return str(response.json())
|
40 |
+
except ValueError:
|
41 |
+
return response.text
|
42 |
+
else:
|
43 |
+
return f"API request failed with status code {response.status_code}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
+
except ConnectionError:
|
46 |
+
return "Connection error. Please check your internet connection and try again."
|
47 |
+
except SSLError:
|
48 |
+
return "SSL Error occurred. Please try again later."
|
49 |
+
except Timeout:
|
50 |
+
return "Request timed out. Please try again later."
|
51 |
+
except Exception as e:
|
52 |
+
return f"An unexpected error occurred: {str(e)}"
|
53 |
|
54 |
+
# Create Gradio interface
|
55 |
+
default_text = "مرحباً بكم في تطبيق استنساخ الصوت. يمكنك استخدام هذا التطبيق لإنشاء نسخة من صوتك باللغة العربية."
|
|
|
56 |
|
57 |
+
demo = gr.Interface(
|
58 |
+
fn=clone_voice,
|
59 |
+
inputs=[
|
60 |
+
gr.Textbox(label="Text", value=default_text),
|
61 |
+
gr.Audio(label="Upload Audio File", type="filepath")
|
62 |
+
],
|
63 |
+
outputs=gr.Audio(label="Cloned Voice"),
|
64 |
+
title="📢 Voice Cloning Application",
|
65 |
+
description="Enter the details below and upload an audio file to clone the voice."
|
66 |
+
)
|
67 |
+
|
68 |
+
if __name__ == "__main__":
|
69 |
+
demo.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|