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

Update openvoice_app.py

Browse files
Files changed (1) hide show
  1. openvoice_app.py +39 -22
openvoice_app.py CHANGED
@@ -2,7 +2,7 @@ import os
2
  import torch
3
  import argparse
4
  import gradio as gr
5
- import smtplib
6
  from email.mime.text import MIMEText
7
  from email.mime.multipart import MIMEMultipart
8
  from email.mime.application import MIMEApplication
@@ -31,32 +31,49 @@ os.makedirs(output_dir, exist_ok=True)
31
  api_key = os.environ.get("ELEVENLABS_API_KEY")
32
  supported_languages = ['zh', 'en']
33
 
34
- # Gmail configuration
35
- GMAIL_USER = os.environ.get('GMAIL_USER')
36
- GMAIL_PASSWORD = os.environ.get('GMAIL_PASSWORD') # This should be an app password, not your regular password
37
 
38
- # Function to send email with downloadable file using Gmail SMTP
39
  def send_email_with_file(recipient_email, file_path, subject, body):
40
  try:
41
- msg = MIMEMultipart()
42
- msg['From'] = GMAIL_USER
43
- msg['To'] = recipient_email
44
- msg['Subject'] = subject
45
-
46
- msg.attach(MIMEText(body, 'plain'))
47
-
 
 
 
48
  with open(file_path, "rb") as file:
49
  part = MIMEApplication(file.read(), Name=os.path.basename(file_path))
50
  part['Content-Disposition'] = f'attachment; filename="{os.path.basename(file_path)}"'
51
- msg.attach(part)
52
-
53
- server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
54
- server.ehlo()
55
- server.login(GMAIL_USER, GMAIL_PASSWORD)
56
- server.send_message(msg)
57
- server.close()
58
-
59
- return True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  except Exception as e:
61
  print(f"An error occurred while sending email: {e}")
62
  return False
@@ -139,4 +156,4 @@ footer {visibility: hidden}
139
  audio .btn-container {display: none}
140
  """
141
 
142
- demo.add_css(css)
 
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
 
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
 
156
  audio .btn-container {display: none}
157
  """
158
 
159
+ demo.add_css(css)