poemsforaphrodite commited on
Commit
156d04e
1 Parent(s): 76c52c3

Update openvoice_app.py

Browse files
Files changed (1) hide show
  1. openvoice_app.py +44 -39
openvoice_app.py CHANGED
@@ -2,12 +2,7 @@ import os
2
  import torch
3
  import argparse
4
  import gradio as gr
5
- import requests
6
- from email.mime.text import MIMEText
7
- from email.mime.multipart import MIMEMultipart
8
- from email.mime.application import MIMEApplication
9
- from openvoice import se_extractor
10
- from openvoice.api import BaseSpeakerTTS, ToneColorConverter
11
  from dotenv import load_dotenv
12
  from openai import OpenAI
13
  from elevenlabs.client import ElevenLabs
@@ -31,49 +26,57 @@ os.makedirs(output_dir, exist_ok=True)
31
  api_key = os.environ.get("ELEVENLABS_API_KEY")
32
  supported_languages = ['zh', 'en']
33
 
34
- # Mailgun configuration
35
- MAILGUN_DOMAIN = "sandbox3785301d5591459ca8b5b5cd121edfb8.mailgun.org"
36
- MAILGUN_API_KEY = os.environ.get("MAILGUN_API_KEY")
 
 
37
 
38
- # Function to send email with downloadable file using Mailgun
39
  def send_email_with_file(recipient_email, file_path, subject, body):
40
  try:
41
- # Prepare the MIME message
42
- message = MIMEMultipart()
43
- message['From'] = f"Your App <mailgun@{MAILGUN_DOMAIN}>"
44
- message['To'] = recipient_email
45
- message['Subject'] = subject
46
-
47
- # Attach the text body
48
- message.attach(MIMEText(body))
49
-
50
- # Attach the file
 
51
  with open(file_path, "rb") as file:
52
- part = MIMEApplication(file.read(), Name=os.path.basename(file_path))
53
- part['Content-Disposition'] = f'attachment; filename="{os.path.basename(file_path)}"'
54
- message.attach(part)
55
-
56
- # Send the email using Mailgun API
57
- response = requests.post(
58
- f"https://api.mailgun.net/v3/{MAILGUN_DOMAIN}/messages",
59
- auth=("api", MAILGUN_API_KEY),
60
- files=[("attachment", (os.path.basename(file_path), open(file_path, "rb").read()))],
61
- data={
62
- "from": f"Your App <mailgun@{MAILGUN_DOMAIN}>",
63
- "to": recipient_email,
64
- "subject": subject,
65
- "text": body,
66
  }
 
 
 
 
 
 
 
 
 
 
 
 
67
  )
68
-
69
- if response.status_code == 200:
70
  print("Email sent successfully")
71
  return True
72
  else:
73
- print(f"Failed to send email. Status code: {response.status_code}")
74
- print(f"Response: {response.text}")
75
  return False
76
-
77
  except Exception as e:
78
  print(f"An error occurred while sending email: {e}")
79
  return False
@@ -109,6 +112,8 @@ def predict(prompt, style, audio_file_pth, voice_name, customer_email):
109
 
110
  return text_hint, save_path, audio_file_pth
111
 
 
 
112
  # Gradio interface setup
113
  with gr.Blocks(gr.themes.Glass()) as demo:
114
  with gr.Row():
 
2
  import torch
3
  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
 
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}"
33
+ MAILERSEND_SENDER_NAME = "Voice Clone App" # You can change this to your preferred sender name
34
 
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
+ mailer = emails.NewApiClient(MAILERSEND_API_KEY)
39
+
40
+ from_email = MAILERSEND_SENDER_EMAIL
41
+ from_name = MAILERSEND_SENDER_NAME
42
+ to_email = recipient_email
43
+ to_name = "Recipient"
44
+
45
+ html = f"<p>{body}</p>"
46
+ text = body
47
+
48
+ # Prepare the attachment
49
  with open(file_path, "rb") as file:
50
+ attachment_content = file.read()
51
+
52
+ attachments = [
53
+ {
54
+ "filename": os.path.basename(file_path),
55
+ "content": attachment_content,
56
+ "disposition": "attachment"
 
 
 
 
 
 
 
57
  }
58
+ ]
59
+
60
+ # Send the email
61
+ response = mailer.send(
62
+ from_email=from_email,
63
+ from_name=from_name,
64
+ to_email=to_email,
65
+ to_name=to_name,
66
+ subject=subject,
67
+ html=html,
68
+ text=text,
69
+ attachments=attachments
70
  )
71
+
72
+ if response.http_status_code == 202:
73
  print("Email sent successfully")
74
  return True
75
  else:
76
+ print(f"Failed to send email. Status code: {response.http_status_code}")
77
+ print(f"Response: {response.json()}")
78
  return False
79
+
80
  except Exception as e:
81
  print(f"An error occurred while sending email: {e}")
82
  return False
 
112
 
113
  return text_hint, save_path, audio_file_pth
114
 
115
+ # Gradio interface setup remains unchanged
116
+ # ...
117
  # Gradio interface setup
118
  with gr.Blocks(gr.themes.Glass()) as demo:
119
  with gr.Row():