poemsforaphrodite commited on
Commit
8cb17aa
1 Parent(s): ceb1a54

Update openvoice_app.py

Browse files
Files changed (1) hide show
  1. openvoice_app.py +3 -15
openvoice_app.py CHANGED
@@ -4,10 +4,8 @@ import argparse
4
  import gradio as gr
5
  from mailersend import emails
6
  from dotenv import load_dotenv
7
- from openai import OpenAI
8
  from elevenlabs.client import ElevenLabs
9
  from elevenlabs import play, save
10
- import time
11
 
12
  # Load environment variables
13
  load_dotenv()
@@ -23,10 +21,8 @@ device = 'cuda' if torch.cuda.is_available() else 'cpu'
23
  output_dir = 'outputs'
24
  os.makedirs(output_dir, exist_ok=True)
25
 
26
- api_key = os.environ.get("ELEVENLABS_API_KEY")
27
  supported_languages = ['zh', 'en']
28
 
29
- # MailerSend configuration
30
  MAILERSEND_API_KEY = "mlsn.f2b1bdff316b16becadbd8dc5db50a31bb0ef084388d6dd0a8ecc9860e552474"
31
  MAILERSEND_DOMAIN = "trial-x2p034709y9gzdrn.mlsender.net"
32
  MAILERSEND_SENDER_EMAIL = f"noreply@{MAILERSEND_DOMAIN}"
@@ -35,16 +31,13 @@ MAILERSEND_SENDER_NAME = "Voice Clone App"
35
  # Function to send email with downloadable file using MailerSend
36
  def send_email_with_file(recipient_email, file_path, subject, body):
37
  try:
38
- api_key = MAILERSEND_API_KEY
39
- mailer = emails.NewEmail(api_key)
40
 
41
  mail_body = {}
42
-
43
  mail_from = {
44
  "name": MAILERSEND_SENDER_NAME,
45
  "email": MAILERSEND_SENDER_EMAIL,
46
  }
47
-
48
  recipients = [
49
  {
50
  "name": "Recipient",
@@ -58,7 +51,6 @@ def send_email_with_file(recipient_email, file_path, subject, body):
58
  mailer.set_html_content(f"<p>{body}</p>", mail_body)
59
  mailer.set_plaintext_content(body, mail_body)
60
 
61
- # Prepare the attachment
62
  with open(file_path, "rb") as file:
63
  attachment_content = file.read()
64
 
@@ -71,7 +63,6 @@ def send_email_with_file(recipient_email, file_path, subject, body):
71
  ]
72
  mailer.set_attachments(attachments, mail_body)
73
 
74
- # Send the email
75
  response = mailer.send(mail_body)
76
 
77
  if response[0] == 202:
@@ -101,12 +92,10 @@ def predict(prompt, style, audio_file_pth, voice_name, customer_email):
101
  description="A trial voice model for testing",
102
  files=[audio_file_pth],
103
  )
104
- # Generate audio from text
105
  audio = client.generate(text=prompt, voice=voice)
106
  save_path = f'{output_dir}/output.wav'
107
  save(audio, save_path)
108
 
109
- # Send email with downloadable file
110
  subject = "Your Voice Clone File"
111
  body = "Thank you for using our Voice Clone service. Your file is attached."
112
  if send_email_with_file(customer_email, save_path, subject, body):
@@ -135,7 +124,7 @@ with gr.Blocks(gr.themes.Glass()) as demo:
135
  ref_gr = gr.Audio(
136
  label="Original Audio",
137
  type="filepath",
138
- sources=["upload"], # Allow only upload
139
  )
140
  voice_name_gr = gr.Textbox(
141
  label="Your name and Product you bought",
@@ -157,10 +146,9 @@ with gr.Blocks(gr.themes.Glass()) as demo:
157
  demo.queue()
158
  demo.launch(debug=True, show_api=False, share=args.share)
159
 
160
- # Hide Gradio footer and record button
161
  css = """
162
  footer {visibility: hidden}
163
  audio .btn-container {display: none}
164
  """
165
 
166
- demo.add_css(css)
 
4
  import gradio as gr
5
  from mailersend import emails
6
  from dotenv import load_dotenv
 
7
  from elevenlabs.client import ElevenLabs
8
  from elevenlabs import play, save
 
9
 
10
  # Load environment variables
11
  load_dotenv()
 
21
  output_dir = 'outputs'
22
  os.makedirs(output_dir, exist_ok=True)
23
 
 
24
  supported_languages = ['zh', 'en']
25
 
 
26
  MAILERSEND_API_KEY = "mlsn.f2b1bdff316b16becadbd8dc5db50a31bb0ef084388d6dd0a8ecc9860e552474"
27
  MAILERSEND_DOMAIN = "trial-x2p034709y9gzdrn.mlsender.net"
28
  MAILERSEND_SENDER_EMAIL = f"noreply@{MAILERSEND_DOMAIN}"
 
31
  # Function to send email with downloadable file using MailerSend
32
  def send_email_with_file(recipient_email, file_path, subject, body):
33
  try:
34
+ mailer = emails.NewEmail(MAILERSEND_API_KEY)
 
35
 
36
  mail_body = {}
 
37
  mail_from = {
38
  "name": MAILERSEND_SENDER_NAME,
39
  "email": MAILERSEND_SENDER_EMAIL,
40
  }
 
41
  recipients = [
42
  {
43
  "name": "Recipient",
 
51
  mailer.set_html_content(f"<p>{body}</p>", mail_body)
52
  mailer.set_plaintext_content(body, mail_body)
53
 
 
54
  with open(file_path, "rb") as file:
55
  attachment_content = file.read()
56
 
 
63
  ]
64
  mailer.set_attachments(attachments, mail_body)
65
 
 
66
  response = mailer.send(mail_body)
67
 
68
  if response[0] == 202:
 
92
  description="A trial voice model for testing",
93
  files=[audio_file_pth],
94
  )
 
95
  audio = client.generate(text=prompt, voice=voice)
96
  save_path = f'{output_dir}/output.wav'
97
  save(audio, save_path)
98
 
 
99
  subject = "Your Voice Clone File"
100
  body = "Thank you for using our Voice Clone service. Your file is attached."
101
  if send_email_with_file(customer_email, save_path, subject, body):
 
124
  ref_gr = gr.Audio(
125
  label="Original Audio",
126
  type="filepath",
127
+ sources=["upload"],
128
  )
129
  voice_name_gr = gr.Textbox(
130
  label="Your name and Product you bought",
 
146
  demo.queue()
147
  demo.launch(debug=True, show_api=False, share=args.share)
148
 
 
149
  css = """
150
  footer {visibility: hidden}
151
  audio .btn-container {display: none}
152
  """
153
 
154
+ demo.add_css(css)