Spaces:
Running
Running
poemsforaphrodite
commited on
Commit
•
02c59ad
1
Parent(s):
63f4070
Update openvoice_app.py
Browse files- openvoice_app.py +85 -4
openvoice_app.py
CHANGED
@@ -30,7 +30,7 @@ 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):
|
@@ -38,7 +38,51 @@ def contains_blocked_words(text):
|
|
38 |
|
39 |
# Function to send email with downloadable file using MailerSend
|
40 |
def send_email_with_file(recipient_email, file_path, subject, body):
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
# Predict function
|
44 |
def predict(prompt, style, audio_file_pth, voice_name, customer_email):
|
@@ -74,11 +118,48 @@ def predict(prompt, style, audio_file_pth, voice_name, customer_email):
|
|
74 |
|
75 |
# Gradio interface setup
|
76 |
with gr.Blocks(gr.themes.Glass()) as demo:
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
css = """
|
80 |
footer {visibility: hidden}
|
81 |
audio .btn-container {display: none}
|
82 |
"""
|
83 |
|
84 |
-
|
|
|
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'] # Add more words as needed
|
34 |
|
35 |
# Function to check for blocked words
|
36 |
def contains_blocked_words(text):
|
|
|
38 |
|
39 |
# Function to send email with downloadable file using MailerSend
|
40 |
def send_email_with_file(recipient_email, file_path, subject, body):
|
41 |
+
try:
|
42 |
+
mailer = emails.NewEmail(MAILERSEND_API_KEY)
|
43 |
+
|
44 |
+
mail_body = {}
|
45 |
+
mail_from = {
|
46 |
+
"name": MAILERSEND_SENDER_NAME,
|
47 |
+
"email": MAILERSEND_SENDER_EMAIL,
|
48 |
+
}
|
49 |
+
recipients = [
|
50 |
+
{
|
51 |
+
"name": "Recipient",
|
52 |
+
"email": recipient_email,
|
53 |
+
}
|
54 |
+
]
|
55 |
+
|
56 |
+
mailer.set_mail_from(mail_from, mail_body)
|
57 |
+
mailer.set_mail_to(recipients, mail_body)
|
58 |
+
mailer.set_subject(subject, mail_body)
|
59 |
+
mailer.set_html_content(f"<p>{body}</p>", mail_body)
|
60 |
+
mailer.set_plaintext_content(body, mail_body)
|
61 |
+
|
62 |
+
with open(file_path, "rb") as file:
|
63 |
+
attachment_content = base64.b64encode(file.read()).decode('utf-8')
|
64 |
+
|
65 |
+
attachments = [
|
66 |
+
{
|
67 |
+
"filename": os.path.basename(file_path),
|
68 |
+
"content": attachment_content,
|
69 |
+
"disposition": "attachment"
|
70 |
+
}
|
71 |
+
]
|
72 |
+
mailer.set_attachments(attachments, mail_body)
|
73 |
+
|
74 |
+
response = mailer.send(mail_body)
|
75 |
+
|
76 |
+
if response[0] == 202:
|
77 |
+
print("Email sent successfully")
|
78 |
+
return True
|
79 |
+
else:
|
80 |
+
print(f"Failed to send email. Status code: {response[0]}")
|
81 |
+
print(f"Response: {response[1]}")
|
82 |
+
return False
|
83 |
+
except Exception as e:
|
84 |
+
print(f"An error occurred while sending email: {e}")
|
85 |
+
return False
|
86 |
|
87 |
# Predict function
|
88 |
def predict(prompt, style, audio_file_pth, voice_name, customer_email):
|
|
|
118 |
|
119 |
# Gradio interface setup
|
120 |
with gr.Blocks(gr.themes.Glass()) as demo:
|
121 |
+
with gr.Row():
|
122 |
+
with gr.Column():
|
123 |
+
input_text_gr = gr.Textbox(
|
124 |
+
label="Create This",
|
125 |
+
info="One or two sentences at a time is better. Up to 200 text characters.",
|
126 |
+
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.",
|
127 |
+
)
|
128 |
+
style_gr = gr.Dropdown(
|
129 |
+
label="Style",
|
130 |
+
choices=['default', 'whispering', 'cheerful', 'terrified', 'angry', 'sad', 'friendly'],
|
131 |
+
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.",
|
132 |
+
max_choices=1,
|
133 |
+
value="default",
|
134 |
+
)
|
135 |
+
ref_gr = gr.Audio(
|
136 |
+
label="Original Audio",
|
137 |
+
type="filepath",
|
138 |
+
sources=["upload"],
|
139 |
+
)
|
140 |
+
voice_name_gr = gr.Textbox(
|
141 |
+
label="Your name and Product you bought",
|
142 |
+
value="Sam"
|
143 |
+
)
|
144 |
+
customer_email_gr = gr.Textbox(
|
145 |
+
label="Your Email",
|
146 |
+
info="We'll send you a downloadable file to this email address."
|
147 |
+
)
|
148 |
+
tts_button = gr.Button("Start", elem_id="send-btn", visible=True)
|
149 |
+
|
150 |
+
with gr.Column():
|
151 |
+
out_text_gr = gr.Text(label="Info")
|
152 |
+
audio_gr = gr.Audio(label="Replicated Sound", autoplay=True)
|
153 |
+
ref_audio_gr = gr.Audio(label="Original Audio Used ")
|
154 |
+
|
155 |
+
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])
|
156 |
+
|
157 |
+
demo.queue()
|
158 |
+
demo.launch(debug=True, show_api=False, share=args.share)
|
159 |
|
160 |
css = """
|
161 |
footer {visibility: hidden}
|
162 |
audio .btn-container {display: none}
|
163 |
"""
|
164 |
|
165 |
+
demo.add_css(css)
|