Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -110,28 +110,46 @@ def check_for_new_links(sheet):
|
|
110 |
return [], f"Error reading sheet: {e}"
|
111 |
|
112 |
# Function to send email with transcription and summary
|
113 |
-
|
|
|
114 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
msg = MIMEMultipart()
|
116 |
msg['From'] = EMAIL_ADDRESS
|
117 |
msg['To'] = to_email
|
118 |
-
msg['Subject'] =
|
119 |
|
120 |
-
msg.attach(MIMEText(
|
121 |
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
part.add_header('Content-Disposition', 'attachment', filename=attachment)
|
127 |
-
msg.attach(part)
|
128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as server:
|
|
|
130 |
server.starttls()
|
|
|
131 |
server.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
|
|
|
132 |
server.sendmail(EMAIL_ADDRESS, to_email, msg.as_string())
|
133 |
|
134 |
print(f"Email sent successfully to {to_email}")
|
|
|
|
|
135 |
return "Email sent successfully"
|
136 |
except smtplib.SMTPAuthenticationError:
|
137 |
print("SMTP Authentication Error: Check your email address and password.")
|
@@ -146,6 +164,7 @@ def send_email(to_email, subject, body, attachments=None):
|
|
146 |
print(f"Error sending email: {e}")
|
147 |
return f"Error sending email: {e}"
|
148 |
|
|
|
149 |
# Function to update Google Sheet after processing
|
150 |
def update_sheet(sheet, file_url):
|
151 |
try:
|
|
|
110 |
return [], f"Error reading sheet: {e}"
|
111 |
|
112 |
# Function to send email with transcription and summary
|
113 |
+
|
114 |
+
def send_email(to_email, transcription, summary):
|
115 |
try:
|
116 |
+
transcription_file_path = os.path.join(OUTPUT_DIR, 'transcription.txt')
|
117 |
+
summary_file_path = os.path.join(OUTPUT_DIR, 'summary.txt')
|
118 |
+
|
119 |
+
with open(transcription_file_path, 'w') as file:
|
120 |
+
file.write(transcription)
|
121 |
+
with open(summary_file_path, 'w') as file:
|
122 |
+
file.write(summary)
|
123 |
+
|
124 |
msg = MIMEMultipart()
|
125 |
msg['From'] = EMAIL_ADDRESS
|
126 |
msg['To'] = to_email
|
127 |
+
msg['Subject'] = 'Your Audio Transcription and Summary'
|
128 |
|
129 |
+
msg.attach(MIMEText('Please find the attached transcription and summary of your audio file.', 'plain'))
|
130 |
|
131 |
+
with open(transcription_file_path, 'rb') as file:
|
132 |
+
attachment = MIMEApplication(file.read(), _subtype='txt')
|
133 |
+
attachment.add_header('Content-Disposition', 'attachment', filename='transcription.txt')
|
134 |
+
msg.attach(attachment)
|
|
|
|
|
135 |
|
136 |
+
with open(summary_file_path, 'rb') as file:
|
137 |
+
attachment = MIMEApplication(file.read(), _subtype='txt')
|
138 |
+
attachment.add_header('Content-Disposition', 'attachment', filename='summary.txt')
|
139 |
+
msg.attach(attachment)
|
140 |
+
|
141 |
+
print("Connecting to SMTP server...")
|
142 |
with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as server:
|
143 |
+
server.set_debuglevel(1) # Enable debug output for SMTP
|
144 |
server.starttls()
|
145 |
+
print("Logging in to SMTP server...")
|
146 |
server.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
|
147 |
+
print("Sending email...")
|
148 |
server.sendmail(EMAIL_ADDRESS, to_email, msg.as_string())
|
149 |
|
150 |
print(f"Email sent successfully to {to_email}")
|
151 |
+
os.remove(transcription_file_path)
|
152 |
+
os.remove(summary_file_path)
|
153 |
return "Email sent successfully"
|
154 |
except smtplib.SMTPAuthenticationError:
|
155 |
print("SMTP Authentication Error: Check your email address and password.")
|
|
|
164 |
print(f"Error sending email: {e}")
|
165 |
return f"Error sending email: {e}"
|
166 |
|
167 |
+
|
168 |
# Function to update Google Sheet after processing
|
169 |
def update_sheet(sheet, file_url):
|
170 |
try:
|