Spaces:
Running
Running
Amirizaniani
commited on
Commit
•
e3c3de3
1
Parent(s):
96de3d8
Update app.py
Browse files
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 |
-
#
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
FileContent(encoded_file),
|
176 |
-
FileName('questions.csv'),
|
177 |
-
FileType('text/csv'),
|
178 |
-
Disposition('attachment')
|
179 |
-
)
|
180 |
|
181 |
-
# Email the CSV file
|
182 |
-
sender_email = "
|
|
|
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 =
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
|
|
|
|
|
|
|
|
|
|
194 |
|
195 |
try:
|
196 |
-
|
197 |
-
|
|
|
|
|
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 |
|