Amirizaniani commited on
Commit
e3c3de3
1 Parent(s): 96de3d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -22
app.py CHANGED
@@ -167,39 +167,41 @@ def process_inputs(llm, file, relevance, diversity, email):
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 = "your_verified_sendgrid_sender@example.com" # 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
-
203
 
204
  text_list = []
205
 
 
167
  csv_file = "questions.csv"
168
  df.to_csv(csv_file, index=False)
169
 
170
+ # Check network connectivity
171
+ try:
172
+ socket.create_connection(("smtp.gmail.com", 2525), timeout=10)
173
+ except OSError:
174
+ return "Network is unreachable. Unable to send email."
 
 
 
 
 
175
 
176
+ # Email the CSV file
177
+ sender_email = "auditllms@gmail.com"
178
+ sender_password = "opri fcxx crkh bvfj"
179
  receiver_email = email
180
  subject = "Your Submitted Questions"
181
  body = "Thank you for your submission. Please find attached the CSV file containing your questions."
182
 
183
+ message = MIMEMultipart()
184
+ message['From'] = sender_email
185
+ message['To'] = receiver_email
186
+ message['Subject'] = subject
187
+ message.attach(MIMEText(body, 'plain'))
188
+
189
+ with open(csv_file, "rb") as attachment:
190
+ part = MIMEBase('application', 'octet-stream')
191
+ part.set_payload(attachment.read())
192
+ encoders.encode_base64(part)
193
+ part.add_header('Content-Disposition', f"attachment; filename= questions.csv")
194
+ message.attach(part)
195
 
196
  try:
197
+ with smtplib.SMTP('smtp.gmail.com', 587) as server:
198
+ server.starttls()
199
+ server.login(sender_email, sender_password)
200
+ server.sendmail(sender_email, receiver_email, message.as_string())
201
  except Exception as e:
202
  return f"Failed to send email: {e}"
203
 
204
  return "Submitted"
 
205
 
206
  text_list = []
207