Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -13,6 +13,8 @@ from email.mime.text import MIMEText
|
|
13 |
from email.mime.base import MIMEBase
|
14 |
from email import encoders
|
15 |
import os
|
|
|
|
|
16 |
|
17 |
nltk.download('punkt')
|
18 |
from nltk.tokenize import word_tokenize
|
@@ -165,30 +167,36 @@ def process_inputs(llm, file, relevance, diversity, email):
|
|
165 |
csv_file = "questions.csv"
|
166 |
df.to_csv(csv_file, index=False)
|
167 |
|
168 |
-
#
|
169 |
-
|
170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
receiver_email = email
|
172 |
subject = "Your Submitted Questions"
|
173 |
body = "Thank you for your submission. Please find attached the CSV file containing your questions."
|
174 |
|
175 |
-
message =
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
with smtplib.SMTP('smtp.gmail.com', 587) as server:
|
189 |
-
server.starttls()
|
190 |
-
server.login(sender_email, sender_password)
|
191 |
-
server.sendmail(sender_email, receiver_email, message.as_string())
|
192 |
|
193 |
return "Submitted"
|
194 |
|
|
|
13 |
from email.mime.base import MIMEBase
|
14 |
from email import encoders
|
15 |
import os
|
16 |
+
from sendgrid import SendGridAPIClient
|
17 |
+
from sendgrid.helpers.mail import Mail, Attachment, FileContent, FileName, FileType, Disposition
|
18 |
|
19 |
nltk.download('punkt')
|
20 |
from nltk.tokenize import word_tokenize
|
|
|
167 |
csv_file = "questions.csv"
|
168 |
df.to_csv(csv_file, index=False)
|
169 |
|
170 |
+
# Read the CSV file and encode it for email attachment
|
171 |
+
with open(csv_file, "rb") as f:
|
172 |
+
encoded_file = base64.b64encode(f.read()).decode()
|
173 |
+
|
174 |
+
attachment = Attachment(
|
175 |
+
FileContent(encoded_file),
|
176 |
+
FileName('questions.csv'),
|
177 |
+
FileType('text/csv'),
|
178 |
+
Disposition('attachment')
|
179 |
+
)
|
180 |
+
|
181 |
+
# Email the CSV file using SendGrid
|
182 |
+
sender_email = "[email protected]" # Your verified sender email in SendGrid
|
183 |
receiver_email = email
|
184 |
subject = "Your Submitted Questions"
|
185 |
body = "Thank you for your submission. Please find attached the CSV file containing your questions."
|
186 |
|
187 |
+
message = Mail(
|
188 |
+
from_email=sender_email,
|
189 |
+
to_emails=receiver_email,
|
190 |
+
subject=subject,
|
191 |
+
html_content=body
|
192 |
+
)
|
193 |
+
message.attachment = attachment
|
194 |
+
|
195 |
+
try:
|
196 |
+
sg = SendGridAPIClient('your_sendgrid_api_key') # Replace with your SendGrid API key
|
197 |
+
response = sg.send(message)
|
198 |
+
except Exception as e:
|
199 |
+
return f"Failed to send email: {e}"
|
|
|
|
|
|
|
|
|
200 |
|
201 |
return "Submitted"
|
202 |
|