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