Spaces:
Runtime error
Runtime error
updating workflow without resume upload
Browse files
app.py
CHANGED
@@ -17,11 +17,11 @@ with open("sys_prompt.txt") as f:
|
|
17 |
sys_prompt = f.read()
|
18 |
|
19 |
get_window_url_params = """
|
20 |
-
function(job, job_params) {
|
21 |
console.log(job, job_params);
|
22 |
const params = new URLSearchParams(window.location.search);
|
23 |
job_params = Object.fromEntries(params);
|
24 |
-
return [job, job_params];
|
25 |
}
|
26 |
"""
|
27 |
|
@@ -76,21 +76,23 @@ def download_pdf_blob_as_text(storage_connection_string, container_name, blob_na
|
|
76 |
print(f"Fehler beim Herunterladen und Konvertieren der Datei: {str(e)}")
|
77 |
return None
|
78 |
|
79 |
-
def load_job_data(job, job_params):
|
80 |
if not job:
|
81 |
try:
|
82 |
print("Hello there")
|
83 |
print(job_params["job"])
|
84 |
-
|
|
|
85 |
json_filename = job_params["job"]+"_jsondata.json"
|
86 |
storage_connection_string = os_connection_string
|
87 |
container_name = "jobdescriptions" # Der Name des Blob-Containers
|
88 |
-
job = download_pdf_blob_as_text(storage_connection_string, container_name,
|
|
|
89 |
job_params = download_and_parse_json_blob(storage_connection_string,container_name,json_filename)
|
90 |
-
return job, job_params, gr.Label.update("Evaluation for the job: "+job_params[0])
|
91 |
except:
|
92 |
gr.Error("An error occurred, the job description could not be loaded. Please contact the recruiter.")
|
93 |
-
return job, job_params, gr.Label.update("An error occurred and the job description could not be loaded. Please contact the recruiter.", color="red")
|
94 |
# print(job)
|
95 |
# print(job_params)
|
96 |
|
@@ -165,7 +167,7 @@ def send_evaluation(history, job, resume, job_params):
|
|
165 |
sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API'))
|
166 |
|
167 |
# Sender- und Empfänger-E-Mail-Adressen
|
168 |
-
sender_email = "
|
169 |
receiver_email = job_params[1]
|
170 |
print(receiver_email)
|
171 |
|
@@ -189,13 +191,9 @@ def send_evaluation(history, job, resume, job_params):
|
|
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 |
-
|
195 |
The evaluation AI-supported summarized:
|
196 |
-
|
197 |
{ai_summary}
|
198 |
-
|
199 |
Sincerely,
|
200 |
Your Evaluation Tool
|
201 |
"""
|
@@ -210,6 +208,11 @@ Your Evaluation Tool
|
|
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,
|
@@ -238,13 +241,27 @@ Your Evaluation Tool
|
|
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 |
|
247 |
-
|
|
|
|
|
|
|
|
|
248 |
|
249 |
with gr.Blocks(css=css) as app:
|
250 |
job_params = gr.JSON({}, visible=False, label="URL Params")
|
@@ -253,22 +270,26 @@ with gr.Blocks(css=css) as app:
|
|
253 |
gr.Markdown(
|
254 |
f"<div style='display: flex; justify-content: space-between;align-items: center;margin-bottom: 1rem' ><h1>CV Evaluation</h1><img width='150' src='https://www.workgenius.com/wp-content/uploads/2023/03/WorkGenius_navy-1.svg' alt='WorkGeniusLogo' /></div>"
|
255 |
)
|
256 |
-
|
257 |
-
|
|
|
258 |
chat = gr.Chatbot(
|
259 |
-
[[None,
|
260 |
)
|
261 |
with gr.Row():
|
262 |
clr = gr.Button("Clear", scale=0)
|
263 |
msg = gr.Textbox(lines=1, show_label=False, scale=1)
|
264 |
-
|
|
|
265 |
msg.submit(user, [msg, chat], [msg, chat], queue=False).then(
|
266 |
bot, [chat, job, resume, job_params], chat
|
267 |
)
|
268 |
-
file.upload(
|
269 |
-
|
270 |
-
).then(bot, [chat, job, resume, job_params], chat)
|
|
|
|
|
271 |
clr.click(lambda: None, None, chat, queue=False)
|
272 |
|
273 |
app.queue()
|
274 |
-
app.launch()
|
|
|
17 |
sys_prompt = f.read()
|
18 |
|
19 |
get_window_url_params = """
|
20 |
+
function(job, resume, job_params) {
|
21 |
console.log(job, job_params);
|
22 |
const params = new URLSearchParams(window.location.search);
|
23 |
job_params = Object.fromEntries(params);
|
24 |
+
return [job, resume, job_params];
|
25 |
}
|
26 |
"""
|
27 |
|
|
|
76 |
print(f"Fehler beim Herunterladen und Konvertieren der Datei: {str(e)}")
|
77 |
return None
|
78 |
|
79 |
+
def load_job_data(job, resume, job_params):
|
80 |
if not job:
|
81 |
try:
|
82 |
print("Hello there")
|
83 |
print(job_params["job"])
|
84 |
+
pdf_filename_jobdescription = job_params["job"]+".pdf"
|
85 |
+
pdf_filename_cv = job_params["job"]+"_resume.pdf"
|
86 |
json_filename = job_params["job"]+"_jsondata.json"
|
87 |
storage_connection_string = os_connection_string
|
88 |
container_name = "jobdescriptions" # Der Name des Blob-Containers
|
89 |
+
job = download_pdf_blob_as_text(storage_connection_string, container_name, pdf_filename_jobdescription)
|
90 |
+
resume = download_pdf_blob_as_text(storage_connection_string, container_name, pdf_filename_cv)
|
91 |
job_params = download_and_parse_json_blob(storage_connection_string,container_name,json_filename)
|
92 |
+
return job, resume, job_params, gr.Label.update("Evaluation for the job: "+job_params[0])
|
93 |
except:
|
94 |
gr.Error("An error occurred, the job description could not be loaded. Please contact the recruiter.")
|
95 |
+
return job, resume, job_params, gr.Label.update("An error occurred and the job description could not be loaded. Please contact the recruiter.", color="red")
|
96 |
# print(job)
|
97 |
# print(job_params)
|
98 |
|
|
|
167 |
sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API'))
|
168 |
|
169 |
# Sender- und Empfänger-E-Mail-Adressen
|
170 |
+
sender_email = "workgeniusjobevaluation@gmail.com"
|
171 |
receiver_email = job_params[1]
|
172 |
print(receiver_email)
|
173 |
|
|
|
191 |
# E-Mail-Nachricht erstellen
|
192 |
subject = "Evaluation for the job: "+job_params[0]
|
193 |
message = f"""Dear Recruiter,
|
194 |
+
Please find attached the complete chat history for this evaluation, resume and summary.
|
|
|
|
|
195 |
The evaluation AI-supported summarized:
|
|
|
196 |
{ai_summary}
|
|
|
197 |
Sincerely,
|
198 |
Your Evaluation Tool
|
199 |
"""
|
|
|
208 |
with open(resume_file_path, 'wb') as resume_file:
|
209 |
resume_file.write(resume.encode('utf-8'))
|
210 |
|
211 |
+
# Summary in eine TXT Datei schreiben
|
212 |
+
summary_file_path = "summary.txt"
|
213 |
+
with open(summary_file_path, 'wb') as summary_file:
|
214 |
+
summary_file.write(ai_summary.encode('utf-8'))
|
215 |
+
|
216 |
# SendGrid-E-Mail erstellen
|
217 |
message = Mail(
|
218 |
from_email=sender_email,
|
|
|
241 |
resume_attachment.disposition = Disposition('attachment')
|
242 |
message.attachment = resume_attachment
|
243 |
|
244 |
+
# Resume als Anhang hinzufügen
|
245 |
+
with open(summary_file_path, 'rb') as summary_file:
|
246 |
+
encode_file_summary = base64.b64encode(summary_file.read()).decode()
|
247 |
+
summary_attachment = Attachment()
|
248 |
+
summary_attachment.file_content = FileContent(encode_file_summary)
|
249 |
+
summary_attachment.file_name = FileName('ai_summary.txt')
|
250 |
+
summary_attachment.file_type = FileType('text/plain')
|
251 |
+
summary_attachment.disposition = Disposition('attachment')
|
252 |
+
message.attachment = summary_attachment
|
253 |
+
|
254 |
try:
|
255 |
response = sg.send(message)
|
256 |
print("E-Mail wurde erfolgreich gesendet. Statuscode:", response.status_code)
|
257 |
except Exception as e:
|
258 |
print("Fehler beim Senden der E-Mail:", str(e))
|
259 |
|
260 |
+
def handle_start_click(welcome_label, start):
|
261 |
+
return gr.Label.update("", visible=False), gr.Button.update("Start Evaluation", scale=0,interactive=False)
|
262 |
+
|
263 |
+
|
264 |
+
css = "footer {visibility: hidden} #component-0{height: 90vh !important} #chatbot{height: 85vh !important} #welcome_label {text-align: center!important}"
|
265 |
|
266 |
with gr.Blocks(css=css) as app:
|
267 |
job_params = gr.JSON({}, visible=False, label="URL Params")
|
|
|
270 |
gr.Markdown(
|
271 |
f"<div style='display: flex; justify-content: space-between;align-items: center;margin-bottom: 1rem' ><h1>CV Evaluation</h1><img width='150' src='https://www.workgenius.com/wp-content/uploads/2023/03/WorkGenius_navy-1.svg' alt='WorkGeniusLogo' /></div>"
|
272 |
)
|
273 |
+
job_title_label = gr.Label("An error occurred and the job description could not be loaded. Please contact the recruiter.", show_label=False)
|
274 |
+
welcome_label = gr.Label("Welcome to the interview chatbot from WorkGenius. After clicking on the 'Start interview' button, you will be asked 10 questions to discuss whether you are a good fit for the job. Please answer the questions honestly and in detail. Good luck!", show_label=False, elem_id="welcome_label")
|
275 |
+
app.load(load_job_data,[job,resume, job_params], [job,resume, job_params, job_title_label], _js=get_window_url_params)
|
276 |
chat = gr.Chatbot(
|
277 |
+
[[None, None]], height=600, elem_id="chatbot"
|
278 |
)
|
279 |
with gr.Row():
|
280 |
clr = gr.Button("Clear", scale=0)
|
281 |
msg = gr.Textbox(lines=1, show_label=False, scale=1)
|
282 |
+
start = gr.Button("Start interview", scale=0)
|
283 |
+
# file = gr.UploadButton("Browse", file_types=[".pdf", ".txt"], scale=0)
|
284 |
msg.submit(user, [msg, chat], [msg, chat], queue=False).then(
|
285 |
bot, [chat, job, resume, job_params], chat
|
286 |
)
|
287 |
+
# file.upload(
|
288 |
+
# add_file, [file, chat, job, resume], [chat, job, resume], queue=False
|
289 |
+
# ).then(bot, [chat, job, resume, job_params], chat)
|
290 |
+
#().then
|
291 |
+
start.click(handle_start_click,[welcome_label, start],[welcome_label, start]).then(bot, [chat, job, resume, job_params], chat)
|
292 |
clr.click(lambda: None, None, chat, queue=False)
|
293 |
|
294 |
app.queue()
|
295 |
+
app.launch()
|