Spaces:
Running
Running
Update feature
Browse files
app.py
CHANGED
|
@@ -1,20 +1,22 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from streamlit_js_eval import streamlit_js_eval
|
| 3 |
from azure.storage.blob import BlobServiceClient
|
|
|
|
| 4 |
import json
|
| 5 |
import os
|
| 6 |
import uuid
|
|
|
|
|
|
|
| 7 |
|
| 8 |
connection_string = os.getenv("CONNECTION")
|
| 9 |
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
|
| 10 |
|
| 11 |
|
| 12 |
-
def upload_blob(pdf_name, json_data, pdf_data_jobdescription,
|
| 13 |
try:
|
| 14 |
container_name = "jobdescriptions"
|
| 15 |
json_blob_name = f"{pdf_name}_jsondata.json"
|
| 16 |
pdf_blob_name_jobdescription = f"{pdf_name}.pdf"
|
| 17 |
-
pdf_blob_name_cv = f"{pdf_name}_resume.pdf"
|
| 18 |
|
| 19 |
container_client = blob_service_client.get_container_client(container_name)
|
| 20 |
|
|
@@ -24,101 +26,142 @@ def upload_blob(pdf_name, json_data, pdf_data_jobdescription,pdf_data_cv):
|
|
| 24 |
pdf_blob_client = container_client.get_blob_client(pdf_blob_name_jobdescription)
|
| 25 |
pdf_blob_client.upload_blob(pdf_data_jobdescription, overwrite=True)
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
st.success('Data and PDF files have been successfully uploaded. The link to the chatbot for the potential candidate is the following: ')
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
|
| 35 |
return True
|
| 36 |
except Exception as e:
|
| 37 |
print(f"Fehler beim Hochladen der Daten: {str(e)}")
|
| 38 |
return False
|
| 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 |
question_one = st.text_input("Enter the first question:")
|
| 78 |
question_two = st.text_input("Enter the second question:")
|
| 79 |
question_three = st.text_input("Enter the third question:")
|
| 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 |
-
if __name__ == "__main__":
|
| 124 |
-
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from streamlit_js_eval import streamlit_js_eval
|
| 3 |
from azure.storage.blob import BlobServiceClient
|
| 4 |
+
from azure.cosmos import CosmosClient, exceptions
|
| 5 |
import json
|
| 6 |
import os
|
| 7 |
import uuid
|
| 8 |
+
import time
|
| 9 |
+
import calendar
|
| 10 |
|
| 11 |
connection_string = os.getenv("CONNECTION")
|
| 12 |
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
|
| 13 |
|
| 14 |
|
| 15 |
+
def upload_blob(pdf_name, json_data, pdf_data_jobdescription,pdf_data_cvs):
|
| 16 |
try:
|
| 17 |
container_name = "jobdescriptions"
|
| 18 |
json_blob_name = f"{pdf_name}_jsondata.json"
|
| 19 |
pdf_blob_name_jobdescription = f"{pdf_name}.pdf"
|
|
|
|
| 20 |
|
| 21 |
container_client = blob_service_client.get_container_client(container_name)
|
| 22 |
|
|
|
|
| 26 |
pdf_blob_client = container_client.get_blob_client(pdf_blob_name_jobdescription)
|
| 27 |
pdf_blob_client.upload_blob(pdf_data_jobdescription, overwrite=True)
|
| 28 |
|
| 29 |
+
links = []
|
| 30 |
+
names = []
|
| 31 |
+
for i,cv in enumerate(pdf_data_cvs):
|
| 32 |
+
cv_nr_for_id = i+1
|
| 33 |
+
cv_session_state_string = "cv-"+str(cv_nr_for_id)
|
| 34 |
+
session_state_name = st.session_state[cv_session_state_string]
|
| 35 |
+
names.append(session_state_name)
|
| 36 |
+
cv_id = pdf_name + "-cv-nr-" + str(cv_nr_for_id)+str(calendar.timegm(time.gmtime()))
|
| 37 |
+
upload_db_item(session_state_name, json.loads(json_data), pdf_name, cv_id)
|
| 38 |
+
pdf_blob_name_cv = f"{cv_id}.pdf"
|
| 39 |
+
pdf_blob_client = container_client.get_blob_client(pdf_blob_name_cv)
|
| 40 |
+
pdf_blob_client.upload_blob(pdf_data_cvs[i], overwrite=True)
|
| 41 |
+
links.append("https://tensora.ai/workgenius/cv-evaluation2/?job="+cv_id)
|
| 42 |
|
| 43 |
st.success('Data and PDF files have been successfully uploaded. The link to the chatbot for the potential candidate is the following: ')
|
| 44 |
+
for i,link in enumerate(links):
|
| 45 |
+
st.write("Link for the candidate "+names[i]+": ")
|
| 46 |
+
st.write(link)
|
| 47 |
|
| 48 |
return True
|
| 49 |
except Exception as e:
|
| 50 |
print(f"Fehler beim Hochladen der Daten: {str(e)}")
|
| 51 |
return False
|
| 52 |
|
| 53 |
+
def upload_db_item(name, data, job_description_id, cv_id):
|
| 54 |
+
|
| 55 |
+
endpoint = "https://wg-candidate-data.documents.azure.com:443/"
|
| 56 |
+
key = os.getenv("CONNECTION_DB")
|
| 57 |
+
client = CosmosClient(endpoint, key)
|
| 58 |
+
database = client.get_database_client("ToDoList")
|
| 59 |
+
container = database.get_container_client("Items")
|
| 60 |
+
candidate_item = {
|
| 61 |
+
"id": cv_id,
|
| 62 |
+
'partitionKey' : 'wg-candidate-data-v1',
|
| 63 |
+
"name": name,
|
| 64 |
+
"title": data["title"],
|
| 65 |
+
"interview_conducted": False,
|
| 66 |
+
"ai_summary": "",
|
| 67 |
+
"evaluation_email": data["email"],
|
| 68 |
+
"question_one": data["question_one"],
|
| 69 |
+
"question_two": data["question_two"],
|
| 70 |
+
"question_three": data["question_three"],
|
| 71 |
+
"job_description_id": job_description_id,
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
try:
|
| 75 |
+
# Fügen Sie das Element in den Container ein
|
| 76 |
+
container.create_item(body=candidate_item)
|
| 77 |
+
print("Eintrag erfolgreich in die Cosmos DB eingefügt.")
|
| 78 |
+
except exceptions.CosmosHttpResponseError as e:
|
| 79 |
+
print(f"Fehler beim Schreiben in die Cosmos DB: {str(e)}")
|
| 80 |
+
except Exception as e:
|
| 81 |
+
print(f"Allgemeiner Fehler: {str(e)}")
|
| 82 |
+
|
| 83 |
+
# def clear_states():
|
| 84 |
+
# 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:
|
| 85 |
+
# st.session_state.title = ""
|
| 86 |
+
# st.session_state.mail = ""
|
| 87 |
+
# # st.session_state.job = None
|
| 88 |
+
# st.session_state.cvs = []
|
| 89 |
+
|
| 90 |
+
st.markdown(
|
| 91 |
+
"""
|
| 92 |
+
<style>
|
| 93 |
+
[data-testid=column]{
|
| 94 |
+
text-align: center;
|
| 95 |
+
display: flex;
|
| 96 |
+
align-items: center;
|
| 97 |
+
justify-content: center;
|
| 98 |
+
}
|
| 99 |
+
</style>
|
| 100 |
+
""",
|
| 101 |
+
unsafe_allow_html=True,
|
| 102 |
+
)
|
| 103 |
+
col1, col2 = st.columns([2, 1])
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
col1.title("Job description upload")
|
| 107 |
+
col2.image("https://www.workgenius.com/wp-content/uploads/2023/03/WorkGenius_navy-1.svg")
|
| 108 |
+
|
| 109 |
+
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.")
|
| 110 |
+
upload_success = True
|
| 111 |
+
with st.container():
|
| 112 |
+
uploaded_file_jobdescription = st.file_uploader("Upload the job description:", type=["pdf"], key="job")
|
| 113 |
+
job_title = st.text_input("Enter the job title:", key="title")
|
| 114 |
+
email = st.text_input("Enter the email:" , key="mail")
|
| 115 |
+
uploaded_file_cvs = st.file_uploader("Upload the resume(s):", type=["pdf"],accept_multiple_files=True, key="cvs")
|
| 116 |
+
for i,cv in enumerate(st.session_state["cvs"]):
|
| 117 |
+
st.text_input(label="Enter the name of the "+str(i+1)+". CV", value=cv.name,key="cv-"+str(i+1))
|
| 118 |
+
with st.expander("Enter up to three predefined questions if needed. Otherwise leave it blank:"):
|
| 119 |
question_one = st.text_input("Enter the first question:")
|
| 120 |
question_two = st.text_input("Enter the second question:")
|
| 121 |
question_three = st.text_input("Enter the third question:")
|
| 122 |
+
col_submit_btn, col_empty, col_clear_btn = st.columns([1,4, 1])
|
| 123 |
+
if col_clear_btn.button("Clear " ,use_container_width=True):
|
| 124 |
+
streamlit_js_eval(js_expressions="parent.window.location.reload()")
|
| 125 |
+
if col_submit_btn.button("Submit", use_container_width=True):
|
| 126 |
+
if len(job_title) > 0 and len(email) > 0 and uploaded_file_jobdescription and len(uploaded_file_cvs)>0:
|
| 127 |
+
data = {
|
| 128 |
+
"title": job_title,
|
| 129 |
+
"email": email,
|
| 130 |
+
"question_one": "",
|
| 131 |
+
"question_two": "",
|
| 132 |
+
"question_three": "",
|
| 133 |
+
}
|
| 134 |
+
if question_one:
|
| 135 |
+
data["question_one"] = question_one
|
| 136 |
+
if question_two:
|
| 137 |
+
data["question_two"] = question_two
|
| 138 |
+
if question_three:
|
| 139 |
+
data["question_three"] = question_three
|
| 140 |
|
| 141 |
+
json_data = json.dumps(data, ensure_ascii=False)
|
| 142 |
|
| 143 |
+
# Eine zufällige UUID generieren
|
| 144 |
+
random_uuid = uuid.uuid4()
|
| 145 |
|
| 146 |
+
# Die UUID als String darstellen
|
| 147 |
+
uuid_string = str(random_uuid)
|
| 148 |
|
| 149 |
+
pdf_name = uuid_string
|
| 150 |
|
| 151 |
+
pdf_data_jobdescription = uploaded_file_jobdescription.read()
|
| 152 |
+
pdf_data_cvs = []
|
| 153 |
+
for i,cv in enumerate(st.session_state["cvs"]):
|
| 154 |
+
pdf_data_cvs.append(cv.read())
|
| 155 |
+
# pdf_data_cv = uploaded_file_cv.read()
|
| 156 |
|
| 157 |
+
upload_success = upload_blob(pdf_name, json_data, pdf_data_jobdescription,pdf_data_cvs)
|
| 158 |
+
else:
|
| 159 |
+
st.write("Please fill out both fields and upload a PDF file.")
|
| 160 |
|
| 161 |
|
| 162 |
+
if not upload_success:
|
| 163 |
+
st.error('An error has occurred. Please contact the administrator. Sorry for the inconvenience.', icon="🚨")
|
| 164 |
+
# else:
|
| 165 |
+
# col_submit_btn, col_empty, col_clear_btn = st.columns([1,4, 1])
|
| 166 |
+
# if col_clear_btn.button("Clear" ,use_container_width=True):
|
| 167 |
+
# streamlit_js_eval(js_expressions="parent.window.location.reload()")
|
|
|
|
|
|
|
|
|