Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -147,7 +147,6 @@ def answer_question(prompt):
|
|
147 |
return generated_answer
|
148 |
|
149 |
|
150 |
-
|
151 |
def process_inputs(llm, file, relevance, diversity, email):
|
152 |
# Check if file is uploaded
|
153 |
if file is not None:
|
@@ -170,46 +169,38 @@ def process_inputs(llm, file, relevance, diversity, email):
|
|
170 |
csv_file = "questions.csv"
|
171 |
df.to_csv(csv_file, index=False)
|
172 |
|
173 |
-
# Check network connectivity to
|
174 |
try:
|
175 |
-
socket.create_connection(("
|
176 |
except OSError:
|
177 |
return "Network is unreachable. Unable to send email."
|
178 |
|
179 |
-
# Email the CSV file
|
180 |
sender_email = "[email protected]"
|
|
|
181 |
receiver_email = email
|
182 |
subject = "Your Submitted Questions"
|
183 |
body = "Thank you for your submission. Please find attached the CSV file containing your questions."
|
184 |
|
185 |
-
message =
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
)
|
191 |
-
|
192 |
-
with open(csv_file, "rb") as f:
|
193 |
-
data = f.read()
|
194 |
-
encoded_file = base64.b64encode(data).decode()
|
195 |
-
|
196 |
-
attached_file = Attachment(
|
197 |
-
FileContent(encoded_file),
|
198 |
-
FileName('questions.csv'),
|
199 |
-
FileType('text/csv'),
|
200 |
-
Disposition('attachment')
|
201 |
-
)
|
202 |
|
203 |
-
|
|
|
|
|
|
|
|
|
|
|
204 |
|
205 |
try:
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
print(response.headers)
|
211 |
except Exception as e:
|
212 |
-
print(e.message)
|
213 |
return f"Failed to send email: {e}"
|
214 |
|
215 |
return "Submitted"
|
|
|
147 |
return generated_answer
|
148 |
|
149 |
|
|
|
150 |
def process_inputs(llm, file, relevance, diversity, email):
|
151 |
# Check if file is uploaded
|
152 |
if file is not None:
|
|
|
169 |
csv_file = "questions.csv"
|
170 |
df.to_csv(csv_file, index=False)
|
171 |
|
172 |
+
# Check network connectivity to the custom port
|
173 |
try:
|
174 |
+
socket.create_connection(("your.relay.server", 25), timeout=10) # Replace with your relay server and port
|
175 |
except OSError:
|
176 |
return "Network is unreachable. Unable to send email."
|
177 |
|
178 |
+
# Email the CSV file
|
179 |
sender_email = "[email protected]"
|
180 |
+
sender_password = "opri fcxx crkh bvfj"
|
181 |
receiver_email = email
|
182 |
subject = "Your Submitted Questions"
|
183 |
body = "Thank you for your submission. Please find attached the CSV file containing your questions."
|
184 |
|
185 |
+
message = MIMEMultipart()
|
186 |
+
message['From'] = sender_email
|
187 |
+
message['To'] = receiver_email
|
188 |
+
message['Subject'] = subject
|
189 |
+
message.attach(MIMEText(body, 'plain'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
|
191 |
+
with open(csv_file, "rb") as attachment:
|
192 |
+
part = MIMEBase('application', 'octet-stream')
|
193 |
+
part.set_payload(attachment.read())
|
194 |
+
encoders.encode_base64(part)
|
195 |
+
part.add_header('Content-Disposition', f"attachment; filename= questions.csv")
|
196 |
+
message.attach(part)
|
197 |
|
198 |
try:
|
199 |
+
with smtplib.SMTP('your.relay.server', 25) as server: # Use your relay server and custom port
|
200 |
+
server.starttls() # Upgrade the connection to a secure encrypted SSL/TLS connection
|
201 |
+
server.login(sender_email, sender_password)
|
202 |
+
server.sendmail(sender_email, receiver_email, message.as_string())
|
|
|
203 |
except Exception as e:
|
|
|
204 |
return f"Failed to send email: {e}"
|
205 |
|
206 |
return "Submitted"
|