Spaces:
Running
Running
poemsforaphrodite
commited on
Commit
•
63f4070
1
Parent(s):
4e6fada
Update openvoice_app.py
Browse files- openvoice_app.py +13 -85
openvoice_app.py
CHANGED
@@ -9,7 +9,6 @@ from elevenlabs import play, save
|
|
9 |
import base64
|
10 |
|
11 |
# Load environment variables
|
12 |
-
#test
|
13 |
load_dotenv()
|
14 |
|
15 |
# Argument parsing
|
@@ -30,53 +29,16 @@ MAILERSEND_DOMAIN = os.getenv("MAILERSEND_DOMAIN")
|
|
30 |
MAILERSEND_SENDER_EMAIL = f"noreply@{MAILERSEND_DOMAIN}"
|
31 |
MAILERSEND_SENDER_NAME = "Voice Clone App"
|
32 |
|
33 |
-
#
|
34 |
-
|
35 |
-
try:
|
36 |
-
mailer = emails.NewEmail(MAILERSEND_API_KEY)
|
37 |
-
|
38 |
-
mail_body = {}
|
39 |
-
mail_from = {
|
40 |
-
"name": MAILERSEND_SENDER_NAME,
|
41 |
-
"email": MAILERSEND_SENDER_EMAIL,
|
42 |
-
}
|
43 |
-
recipients = [
|
44 |
-
{
|
45 |
-
"name": "Recipient",
|
46 |
-
"email": recipient_email,
|
47 |
-
}
|
48 |
-
]
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
mailer.set_html_content(f"<p>{body}</p>", mail_body)
|
54 |
-
mailer.set_plaintext_content(body, mail_body)
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
attachments = [
|
60 |
-
{
|
61 |
-
"filename": os.path.basename(file_path),
|
62 |
-
"content": attachment_content,
|
63 |
-
"disposition": "attachment"
|
64 |
-
}
|
65 |
-
]
|
66 |
-
mailer.set_attachments(attachments, mail_body)
|
67 |
-
|
68 |
-
response = mailer.send(mail_body)
|
69 |
-
|
70 |
-
if response[0] == 202:
|
71 |
-
print("Email sent successfully")
|
72 |
-
return True
|
73 |
-
else:
|
74 |
-
print(f"Failed to send email. Status code: {response[0]}")
|
75 |
-
print(f"Response: {response[1]}")
|
76 |
-
return False
|
77 |
-
except Exception as e:
|
78 |
-
print(f"An error occurred while sending email: {e}")
|
79 |
-
return False
|
80 |
|
81 |
# Predict function
|
82 |
def predict(prompt, style, audio_file_pth, voice_name, customer_email):
|
@@ -87,6 +49,9 @@ def predict(prompt, style, audio_file_pth, voice_name, customer_email):
|
|
87 |
if len(prompt) > 200:
|
88 |
text_hint += "[ERROR] Text length limited to 200 characters. Please try shorter text.\n"
|
89 |
return text_hint, None, None
|
|
|
|
|
|
|
90 |
full_voice_name = f"{voice_name} - {customer_email}"
|
91 |
print(audio_file_pth)
|
92 |
voice = client.clone(
|
@@ -109,48 +74,11 @@ def predict(prompt, style, audio_file_pth, voice_name, customer_email):
|
|
109 |
|
110 |
# Gradio interface setup
|
111 |
with gr.Blocks(gr.themes.Glass()) as demo:
|
112 |
-
|
113 |
-
with gr.Column():
|
114 |
-
input_text_gr = gr.Textbox(
|
115 |
-
label="Create This",
|
116 |
-
info="One or two sentences at a time is better. Up to 200 text characters.",
|
117 |
-
value="He hoped there would be stew for dinner, turnips and carrots and bruised potatoes and fat mutton pieces to be ladled out in thick, peppered, flour-fattened sauce.",
|
118 |
-
)
|
119 |
-
style_gr = gr.Dropdown(
|
120 |
-
label="Style",
|
121 |
-
choices=['default', 'whispering', 'cheerful', 'terrified', 'angry', 'sad', 'friendly'],
|
122 |
-
info="Please upload a reference audio file that is at least 1 minute long. For best results, ensure the audio is clear. You can use Adobe Podcast Enhance(https://podcast.adobe.com/enhance) to improve the audio quality before uploading.",
|
123 |
-
max_choices=1,
|
124 |
-
value="default",
|
125 |
-
)
|
126 |
-
ref_gr = gr.Audio(
|
127 |
-
label="Original Audio",
|
128 |
-
type="filepath",
|
129 |
-
sources=["upload"],
|
130 |
-
)
|
131 |
-
voice_name_gr = gr.Textbox(
|
132 |
-
label="Your name and Product you bought",
|
133 |
-
value="Sam"
|
134 |
-
)
|
135 |
-
customer_email_gr = gr.Textbox(
|
136 |
-
label="Your Email",
|
137 |
-
info="We'll send you a downloadable file to this email address."
|
138 |
-
)
|
139 |
-
tts_button = gr.Button("Start", elem_id="send-btn", visible=True)
|
140 |
-
|
141 |
-
with gr.Column():
|
142 |
-
out_text_gr = gr.Text(label="Info")
|
143 |
-
audio_gr = gr.Audio(label="Replicated Sound", autoplay=True)
|
144 |
-
ref_audio_gr = gr.Audio(label="Original Audio Used ")
|
145 |
-
|
146 |
-
tts_button.click(predict, [input_text_gr, style_gr, ref_gr, voice_name_gr, customer_email_gr], outputs=[out_text_gr, audio_gr, ref_audio_gr])
|
147 |
-
|
148 |
-
demo.queue()
|
149 |
-
demo.launch(debug=True, show_api=False, share=args.share)
|
150 |
|
151 |
css = """
|
152 |
footer {visibility: hidden}
|
153 |
audio .btn-container {display: none}
|
154 |
"""
|
155 |
|
156 |
-
demo.add_css(css)
|
|
|
9 |
import base64
|
10 |
|
11 |
# Load environment variables
|
|
|
12 |
load_dotenv()
|
13 |
|
14 |
# Argument parsing
|
|
|
29 |
MAILERSEND_SENDER_EMAIL = f"noreply@{MAILERSEND_DOMAIN}"
|
30 |
MAILERSEND_SENDER_NAME = "Voice Clone App"
|
31 |
|
32 |
+
# List of blocked words
|
33 |
+
BLOCKED_WORDS = ['Kill','hurt','shoot','gun','rifle','AR','semi automatic','knife','blade','sword','punch harm','disrupt','blackmail','steal','bitch','cunt','fuck','freaking','nigger','nigga','niggas','cracker','jew','oriental','fag','faggot','account','money','transfer','urgent','help','scared','policy','frightened','accident','fear','scam','address','social security number','assault','injure','maim','destroy','damage','threaten','intimidate','bully','menace','blackmail','extort','exploit','defame','steal','rob','embezzle','defraud Harass','jerk','idiot','stupid','moron','asshole','con','trick','swindle','defraud','payment','credit card','bank account','urgent','immediate','afraid','phone number','email','password']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
+
# Function to check for blocked words
|
36 |
+
def contains_blocked_words(text):
|
37 |
+
return any(word.lower() in text.lower() for word in BLOCKED_WORDS)
|
|
|
|
|
38 |
|
39 |
+
# Function to send email with downloadable file using MailerSend
|
40 |
+
def send_email_with_file(recipient_email, file_path, subject, body):
|
41 |
+
# ... (rest of the function remains the same)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
# Predict function
|
44 |
def predict(prompt, style, audio_file_pth, voice_name, customer_email):
|
|
|
49 |
if len(prompt) > 200:
|
50 |
text_hint += "[ERROR] Text length limited to 200 characters. Please try shorter text.\n"
|
51 |
return text_hint, None, None
|
52 |
+
if contains_blocked_words(prompt):
|
53 |
+
text_hint += "[ERROR] Your text contains blocked words. Please remove them and try again.\n"
|
54 |
+
return text_hint, None, None
|
55 |
full_voice_name = f"{voice_name} - {customer_email}"
|
56 |
print(audio_file_pth)
|
57 |
voice = client.clone(
|
|
|
74 |
|
75 |
# Gradio interface setup
|
76 |
with gr.Blocks(gr.themes.Glass()) as demo:
|
77 |
+
# ... (rest of the code remains the same)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
css = """
|
80 |
footer {visibility: hidden}
|
81 |
audio .btn-container {display: none}
|
82 |
"""
|
83 |
|
84 |
+
demo.add_css(css)
|