Spaces:
Running
Running
File size: 8,298 Bytes
a3280e8 0126cb1 a3280e8 c219480 a3280e8 1259f25 c219480 a3280e8 c219480 9e9de90 000000e 18b432b a3280e8 9e9de90 a3280e8 000000e a3280e8 18b432b 000000e c219480 dc774e7 18b432b c219480 a3280e8 9e9de90 000000e c219480 000000e c219480 56b5571 c219480 56b5571 c219480 9e9de90 c219480 9e9de90 c219480 9e9de90 c219480 9e9de90 c219480 9e9de90 c219480 56b5571 c219480 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
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()") |