WorkGenius / app.py
mbosse99's picture
Updating to full db support
000000e
raw
history blame
8.3 kB
import streamlit as st
from streamlit_js_eval import streamlit_js_eval
from azure.storage.blob import BlobServiceClient
from azure.cosmos import CosmosClient, exceptions
import json
import os
import uuid
import time
import calendar
connection_string = os.getenv("CONNECTION")
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
def upload_blob(pdf_name, json_data, pdf_data_jobdescription,pdf_data_cvs):
try:
container_name = "jobdescriptions"
# json_blob_name = f"{pdf_name}_jsondata.json"
pdf_blob_name_jobdescription = f"{pdf_name}.pdf"
container_client = blob_service_client.get_container_client(container_name)
# json_blob_client = container_client.get_blob_client(json_blob_name)
# json_blob_client.upload_blob(json_data.encode('utf-8'), overwrite=True)
pdf_blob_client = container_client.get_blob_client(pdf_blob_name_jobdescription)
pdf_blob_client.upload_blob(pdf_data_jobdescription, overwrite=True)
upload_job_db_item(pdf_name,len(pdf_data_cvs),json.loads(json_data))
links = []
names = []
for i,cv in enumerate(pdf_data_cvs):
cv_nr_for_id = i+1
cv_session_state_string = "cv-"+str(cv_nr_for_id)
session_state_name = st.session_state[cv_session_state_string]
names.append(session_state_name)
cv_id = pdf_name + "-cv-nr-" + str(cv_nr_for_id)+str(calendar.timegm(time.gmtime()))
upload_db_item(session_state_name, json.loads(json_data), pdf_name, cv_id)
pdf_blob_name_cv = f"{cv_id}.pdf"
pdf_blob_client = container_client.get_blob_client(pdf_blob_name_cv)
pdf_blob_client.upload_blob(pdf_data_cvs[i], overwrite=True)
links.append("https://tensora.ai/workgenius/cv-evaluation2/?job="+cv_id)
st.success('Data and PDF files have been successfully uploaded. The link to the chatbot for the potential candidate is the following: ')
for i,link in enumerate(links):
st.write("Link for the candidate "+names[i]+": ")
st.write(link)
return True
except Exception as e:
print(f"Fehler beim Hochladen der Daten: {str(e)}")
return False
def upload_job_db_item(id, number_of_applicants, data):
endpoint = "https://wg-candidate-data.documents.azure.com:443/"
key = os.getenv("CONNECTION_DB")
client = CosmosClient(endpoint, key)
database = client.get_database_client("ToDoList")
container = database.get_container_client("JobData")
job_item = {
"id": id,
'partitionKey' : 'wg-job-data-v1',
"title": data["title"],
"number_of_applicants": number_of_applicants,
"every_interview_conducted": False,
"evaluation_email": data["email"],
"question_one": data["question_one"],
"question_two": data["question_two"],
"question_three": data["question_three"],
}
try:
# Fügen Sie das Element in den Container ein
container.create_item(body=job_item)
print("Eintrag erfolgreich in die Cosmos DB eingefügt. Container: Job Data")
except exceptions.CosmosHttpResponseError as e:
print(f"Fehler beim Schreiben in die Cosmos DB: {str(e)}")
except Exception as e:
print(f"Allgemeiner Fehler: {str(e)}")
def upload_db_item(name, data, job_description_id, cv_id):
endpoint = "https://wg-candidate-data.documents.azure.com:443/"
key = os.getenv("CONNECTION_DB")
client = CosmosClient(endpoint, key)
database = client.get_database_client("ToDoList")
container = database.get_container_client("Items")
candidate_item = {
"id": cv_id,
'partitionKey' : 'wg-candidate-data-v1',
"name": name,
"title": data["title"],
"interview_conducted": False,
"ai_summary": "",
"evaluation_email": data["email"],
"question_one": data["question_one"],
"question_two": data["question_two"],
"question_three": data["question_three"],
"job_description_id": job_description_id,
}
try:
# Fügen Sie das Element in den Container ein
container.create_item(body=candidate_item)
print("Eintrag erfolgreich in die Cosmos DB eingefügt. Container: Items(candidate Data)")
except exceptions.CosmosHttpResponseError as e:
print(f"Fehler beim Schreiben in die Cosmos DB: {str(e)}")
except Exception as e:
print(f"Allgemeiner Fehler: {str(e)}")
# def clear_states():
# if len(st.session_state.title) > 0 and len(st.session_state.mail) > 0 and st.session_state.job and len(st.session_state.cvs)>0:
# st.session_state.title = ""
# st.session_state.mail = ""
# # st.session_state.job = None
# st.session_state.cvs = []
st.markdown(
"""
<style>
[data-testid=column]{
text-align: center;
display: flex;
align-items: center;
justify-content: center;
}
</style>
""",
unsafe_allow_html=True,
)
col1, col2 = st.columns([2, 1])
col1.title("Job description upload")
col2.image("https://www.workgenius.com/wp-content/uploads/2023/03/WorkGenius_navy-1.svg")
st.write("Please upload the job description and resume(s) as PDF and enter the job title for the position. To receive the evaluation of the potential candidate(s), please provide your email address.")
upload_success = True
with st.container():
uploaded_file_jobdescription = st.file_uploader("Upload the job description:", type=["pdf"], key="job")
job_title = st.text_input("Enter the job title:", key="title")
email = st.text_input("Enter the email:" , key="mail")
uploaded_file_cvs = st.file_uploader("Upload the resume(s):", type=["pdf"],accept_multiple_files=True, key="cvs")
for i,cv in enumerate(st.session_state["cvs"]):
st.text_input(label="Enter the name of the "+str(i+1)+". CV (File: "+cv.name+")", value=cv.name,key="cv-"+str(i+1))
with st.expander("Enter up to three predefined questions if needed. Otherwise leave it blank:"):
question_one = st.text_input("Enter the first question:")
question_two = st.text_input("Enter the second question:")
question_three = st.text_input("Enter the third question:")
col_submit_btn, col_empty, col_clear_btn = st.columns([1,4, 1])
if col_clear_btn.button("Clear " ,use_container_width=True):
streamlit_js_eval(js_expressions="parent.window.location.reload()")
if col_submit_btn.button("Submit", use_container_width=True):
if len(job_title) > 0 and len(email) > 0 and uploaded_file_jobdescription and len(uploaded_file_cvs)>0:
data = {
"title": job_title,
"email": email,
"question_one": "",
"question_two": "",
"question_three": "",
}
if question_one:
data["question_one"] = question_one
if question_two:
data["question_two"] = question_two
if question_three:
data["question_three"] = question_three
json_data = json.dumps(data, ensure_ascii=False)
# Eine zufällige UUID generieren
random_uuid = uuid.uuid4()
# Die UUID als String darstellen
uuid_string = str(random_uuid)
pdf_name = uuid_string
pdf_data_jobdescription = uploaded_file_jobdescription.read()
pdf_data_cvs = []
for i,cv in enumerate(st.session_state["cvs"]):
print(cv.name)
pdf_data_cvs.append(cv.read())
# pdf_data_cv = uploaded_file_cv.read()
upload_success = upload_blob(pdf_name, json_data, pdf_data_jobdescription,pdf_data_cvs)
else:
st.write("Please fill out both fields and upload a PDF file.")
if not upload_success:
st.error('An error has occurred. Please contact the administrator. Sorry for the inconvenience.', icon="🚨")
# else:
# col_submit_btn, col_empty, col_clear_btn = st.columns([1,4, 1])
# if col_clear_btn.button("Clear" ,use_container_width=True):
# streamlit_js_eval(js_expressions="parent.window.location.reload()")