Spaces:
Runtime error
Runtime error
Update with sendgrid
Browse files
app.py
CHANGED
@@ -5,11 +5,10 @@ from azure.storage.blob import BlobServiceClient
|
|
5 |
import io
|
6 |
from PyPDF2 import PdfReader
|
7 |
import json
|
8 |
-
import smtplib
|
9 |
-
from email.mime.text import MIMEText
|
10 |
-
from email.mime.multipart import MIMEMultipart
|
11 |
-
from email.mime.application import MIMEApplication
|
12 |
import os
|
|
|
|
|
|
|
13 |
|
14 |
os_connection_string = os.getenv("CONNECTION")
|
15 |
os_mail_password = os.getenv("MAIL_PASSWORD")
|
@@ -128,7 +127,7 @@ def bot(history, job, resume, job_params):
|
|
128 |
yield history
|
129 |
return
|
130 |
|
131 |
-
system = sys_prompt.format(job=job, resume=resume, n=
|
132 |
messages = [{"role": "system", "content": system}]
|
133 |
for user, assistant in history:
|
134 |
if user:
|
@@ -154,7 +153,6 @@ def bot(history, job, resume, job_params):
|
|
154 |
return
|
155 |
|
156 |
def send_evaluation(history, job, resume, job_params):
|
157 |
-
|
158 |
# Chatverlauf in einen Textstring umwandeln
|
159 |
chat_text = ""
|
160 |
for entry in history:
|
@@ -163,37 +161,34 @@ def send_evaluation(history, job, resume, job_params):
|
|
163 |
if entry[1]:
|
164 |
chat_text += "Chatbot: " + entry[1] + "\n"
|
165 |
|
166 |
-
# Einstellungen für
|
167 |
-
|
168 |
-
smtp_port = 587
|
169 |
-
smtp_username = "[email protected]"
|
170 |
-
smtp_password = os_mail_password
|
171 |
|
172 |
# Sender- und Empfänger-E-Mail-Adressen
|
173 |
-
sender_email = "
|
174 |
receiver_email = job_params[1]
|
175 |
print(receiver_email)
|
176 |
|
177 |
ai_summary = "TEST Summary"
|
178 |
-
prompt = "You are a professional recruiter who has been given a CV and a job description and has created 10 questions based on that. The eventual applicant has entered his answers to the questions. Now you have to evaluate on the basis of the answers if the applicant fits the job in principle. This is the case when about
|
|
|
179 |
res = openai.ChatCompletion.create(
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
)
|
|
|
191 |
ai_summary = res.choices[0]["message"]["content"]
|
192 |
-
print(ai_summary)
|
193 |
# E-Mail-Nachricht erstellen
|
194 |
-
subject = "Evaluation for the job: "+job_params[0]
|
195 |
-
message = f"""
|
196 |
-
Dear Recruiter,
|
197 |
|
198 |
Please find attached the complete chat history for this evaluation and resume.
|
199 |
|
@@ -205,41 +200,47 @@ Sincerely,
|
|
205 |
Your Evaluation Tool
|
206 |
"""
|
207 |
|
208 |
-
msg = MIMEMultipart()
|
209 |
-
msg['From'] = sender_email
|
210 |
-
msg['To'] = receiver_email
|
211 |
-
msg['Subject'] = subject
|
212 |
-
msg.attach(MIMEText(message, 'plain'))
|
213 |
-
|
214 |
# Chatverlauf in eine Textdatei schreiben
|
215 |
chat_file_path = "chat_history.txt"
|
216 |
with open(chat_file_path, 'w', encoding='utf-8') as chat_file:
|
217 |
chat_file.write(chat_text)
|
218 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
# Chatverlauf als Anhang hinzufügen
|
220 |
-
with open(chat_file_path, '
|
221 |
-
|
222 |
-
chat_attachment
|
223 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
|
225 |
-
# Resume-Bytes in eine TXT-Datei schreiben und als Anhang hinzufügen
|
226 |
-
resume_file = io.BytesIO()
|
227 |
-
resume_file.write(resume.encode('utf-8'))
|
228 |
-
resume_file.seek(0)
|
229 |
-
resume_attachment = MIMEText(resume_file.read().decode('utf-8'), _subtype='plain')
|
230 |
-
resume_attachment.add_header('Content-Disposition', 'attachment', filename='resume.txt')
|
231 |
-
msg.attach(resume_attachment)
|
232 |
-
|
233 |
-
print("for der Mail")
|
234 |
-
# SMTP-Verbindung herstellen und E-Mail senden
|
235 |
try:
|
236 |
-
|
237 |
-
|
238 |
-
server.login(smtp_username, smtp_password)
|
239 |
-
text = msg.as_string()
|
240 |
-
server.sendmail(sender_email, receiver_email, text)
|
241 |
-
server.quit()
|
242 |
-
print("E-Mail wurde erfolgreich gesendet.")
|
243 |
except Exception as e:
|
244 |
print("Fehler beim Senden der E-Mail:", str(e))
|
245 |
|
|
|
5 |
import io
|
6 |
from PyPDF2 import PdfReader
|
7 |
import json
|
|
|
|
|
|
|
|
|
8 |
import os
|
9 |
+
import sendgrid
|
10 |
+
from sendgrid.helpers.mail import Mail, Attachment, FileContent, FileName, FileType, Disposition
|
11 |
+
import base64
|
12 |
|
13 |
os_connection_string = os.getenv("CONNECTION")
|
14 |
os_mail_password = os.getenv("MAIL_PASSWORD")
|
|
|
127 |
yield history
|
128 |
return
|
129 |
|
130 |
+
system = sys_prompt.format(job=job, resume=resume, n=10)
|
131 |
messages = [{"role": "system", "content": system}]
|
132 |
for user, assistant in history:
|
133 |
if user:
|
|
|
153 |
return
|
154 |
|
155 |
def send_evaluation(history, job, resume, job_params):
|
|
|
156 |
# Chatverlauf in einen Textstring umwandeln
|
157 |
chat_text = ""
|
158 |
for entry in history:
|
|
|
161 |
if entry[1]:
|
162 |
chat_text += "Chatbot: " + entry[1] + "\n"
|
163 |
|
164 |
+
# Einstellungen für SendGrid
|
165 |
+
sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API'))
|
|
|
|
|
|
|
166 |
|
167 |
# Sender- und Empfänger-E-Mail-Adressen
|
168 |
+
sender_email = "marcel.bosse@tensora.co"
|
169 |
receiver_email = job_params[1]
|
170 |
print(receiver_email)
|
171 |
|
172 |
ai_summary = "TEST Summary"
|
173 |
+
prompt = "You are a professional recruiter who has been given a CV and a job description and has created 10 questions based on that. The eventual applicant has entered his answers to the questions. Now you have to evaluate on the basis of the answers if the applicant fits the job in principle. This is the case when about 70 percent of all questions have been answered satisfactorily and positively. Keep in mind that an answer must always be fact-based, so if, for example, the question asks for examples, the potential applicant must also give such examples. Please also provide details of which questions were answered positively and why."
|
174 |
+
|
175 |
res = openai.ChatCompletion.create(
|
176 |
+
model="gpt-4",
|
177 |
+
temperature=0.2,
|
178 |
+
messages=[
|
179 |
+
{
|
180 |
+
"role": "system",
|
181 |
+
"content": prompt,
|
182 |
+
},
|
183 |
+
{"role": "system", "content": "Job description: "+job+"; Resume: "+resume},
|
184 |
+
{"role": "system", "content": "Chathistory: "+chat_text},
|
185 |
+
],
|
186 |
+
)
|
187 |
+
|
188 |
ai_summary = res.choices[0]["message"]["content"]
|
|
|
189 |
# E-Mail-Nachricht erstellen
|
190 |
+
subject = "Evaluation for the job: "+job_params[0]
|
191 |
+
message = f"""Dear Recruiter,
|
|
|
192 |
|
193 |
Please find attached the complete chat history for this evaluation and resume.
|
194 |
|
|
|
200 |
Your Evaluation Tool
|
201 |
"""
|
202 |
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
# Chatverlauf in eine Textdatei schreiben
|
204 |
chat_file_path = "chat_history.txt"
|
205 |
with open(chat_file_path, 'w', encoding='utf-8') as chat_file:
|
206 |
chat_file.write(chat_text)
|
207 |
|
208 |
+
# Resume-Bytes in eine TXT-Datei schreiben und als Anhang hinzufügen
|
209 |
+
resume_file_path = "resume.txt"
|
210 |
+
with open(resume_file_path, 'wb') as resume_file:
|
211 |
+
resume_file.write(resume.encode('utf-8'))
|
212 |
+
|
213 |
+
# SendGrid-E-Mail erstellen
|
214 |
+
message = Mail(
|
215 |
+
from_email=sender_email,
|
216 |
+
to_emails=receiver_email,
|
217 |
+
subject=subject,
|
218 |
+
plain_text_content=message,
|
219 |
+
)
|
220 |
+
|
221 |
# Chatverlauf als Anhang hinzufügen
|
222 |
+
with open(chat_file_path, 'rb') as chat_file:
|
223 |
+
encode_file_chat = base64.b64encode(chat_file.read()).decode()
|
224 |
+
chat_attachment = Attachment()
|
225 |
+
chat_attachment.file_content = FileContent(encode_file_chat)
|
226 |
+
chat_attachment.file_name = FileName('chat_history.txt')
|
227 |
+
chat_attachment.file_type = FileType('text/plain')
|
228 |
+
chat_attachment.disposition = Disposition('attachment')
|
229 |
+
message.attachment = chat_attachment
|
230 |
+
|
231 |
+
# Resume als Anhang hinzufügen
|
232 |
+
with open(resume_file_path, 'rb') as resume_file:
|
233 |
+
encode_file_resume = base64.b64encode(resume_file.read()).decode()
|
234 |
+
resume_attachment = Attachment()
|
235 |
+
resume_attachment.file_content = FileContent(encode_file_resume)
|
236 |
+
resume_attachment.file_name = FileName('resume.txt')
|
237 |
+
resume_attachment.file_type = FileType('text/plain')
|
238 |
+
resume_attachment.disposition = Disposition('attachment')
|
239 |
+
message.attachment = resume_attachment
|
240 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
try:
|
242 |
+
response = sg.send(message)
|
243 |
+
print("E-Mail wurde erfolgreich gesendet. Statuscode:", response.status_code)
|
|
|
|
|
|
|
|
|
|
|
244 |
except Exception as e:
|
245 |
print("Fehler beim Senden der E-Mail:", str(e))
|
246 |
|