Spaces:
Sleeping
Sleeping
Adding error handling and working clear button
Browse files
app.py
CHANGED
@@ -10,24 +10,29 @@ blob_service_client = BlobServiceClient.from_connection_string(connection_string
|
|
10 |
|
11 |
|
12 |
def upload_blob(pdf_name, json_data, pdf_data):
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
16 |
|
17 |
-
|
18 |
|
19 |
-
|
20 |
-
|
21 |
|
22 |
-
|
23 |
-
|
24 |
|
25 |
-
|
26 |
|
27 |
-
|
28 |
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
31 |
|
32 |
|
33 |
|
@@ -52,34 +57,41 @@ def main():
|
|
52 |
col2.image("https://www.workgenius.com/wp-content/uploads/2023/03/WorkGenius_navy-1.svg")
|
53 |
|
54 |
st.write("Please upload the job description as a PDF and enter the job title for the position. To receive the evaluation of the potential candidates, please enter your email address.")
|
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 |
if __name__ == "__main__":
|
85 |
main()
|
|
|
10 |
|
11 |
|
12 |
def upload_blob(pdf_name, json_data, pdf_data):
|
13 |
+
try:
|
14 |
+
container_name = "jobdescriptions"
|
15 |
+
json_blob_name = f"{pdf_name}_jsondata.json"
|
16 |
+
pdf_blob_name = f"{pdf_name}.pdf"
|
17 |
|
18 |
+
container_client = blob_service_client.get_container_client(container_name)
|
19 |
|
20 |
+
json_blob_client = container_client.get_blob_client(json_blob_name)
|
21 |
+
json_blob_client.upload_blob(json_data.encode('utf-8'), overwrite=True)
|
22 |
|
23 |
+
pdf_blob_client = container_client.get_blob_client(pdf_blob_name)
|
24 |
+
pdf_blob_client.upload_blob(pdf_data, overwrite=True)
|
25 |
|
26 |
+
link = "https://tensora.ai/workgenius/cv-evaluation2/?job="+pdf_name
|
27 |
|
28 |
+
st.write('Data and PDF have been successfully uploaded. The link to the chatbot for the potential candidates is the following: '+link)
|
29 |
|
30 |
+
return True
|
31 |
+
except Exception as e:
|
32 |
+
print(f"Fehler beim Hochladen der Daten: {str(e)}")
|
33 |
+
return False
|
34 |
+
|
35 |
+
|
36 |
|
37 |
|
38 |
|
|
|
57 |
col2.image("https://www.workgenius.com/wp-content/uploads/2023/03/WorkGenius_navy-1.svg")
|
58 |
|
59 |
st.write("Please upload the job description as a PDF and enter the job title for the position. To receive the evaluation of the potential candidates, please enter your email address.")
|
60 |
+
upload_success = True
|
61 |
+
with st.form("job_inputs",clear_on_submit=True):
|
62 |
+
uploaded_file = st.file_uploader("Upload a PDF file:", type=["pdf"])
|
63 |
+
|
64 |
+
job_title = st.text_input("Enter the job title:")
|
65 |
+
email = st.text_input("Enter the email:")
|
66 |
+
submitted = st.form_submit_button("Submit")
|
67 |
+
if submitted:
|
68 |
+
if len(job_title) > 0 and len(email) > 0 and uploaded_file:
|
69 |
+
data = {
|
70 |
+
"title": job_title,
|
71 |
+
"email": email
|
72 |
+
}
|
73 |
+
json_data = json.dumps(data, ensure_ascii=False)
|
74 |
+
|
75 |
+
# Eine zufällige UUID generieren
|
76 |
+
random_uuid = uuid.uuid4()
|
77 |
+
|
78 |
+
# Die UUID als String darstellen
|
79 |
+
uuid_string = str(random_uuid)
|
80 |
+
|
81 |
+
pdf_name = uuid_string
|
82 |
+
|
83 |
+
pdf_data = uploaded_file.read()
|
84 |
+
|
85 |
+
upload_success = upload_blob(pdf_name, json_data, pdf_data)
|
86 |
+
|
87 |
+
|
88 |
+
else:
|
89 |
+
st.write("Please fill out both fields and upload a PDF file.")
|
90 |
+
if not upload_success:
|
91 |
+
st.error('An error has occurred. Please contact the administrator. Sorry for the inconvenience.', icon="🚨")
|
92 |
+
else:
|
93 |
+
col_empty, col_btn = st.columns([5, 1])
|
94 |
+
if col_btn.button("Clear" ,key="clear_btn",use_container_width=True):
|
95 |
+
streamlit_js_eval(js_expressions="parent.window.location.reload()")
|
96 |
if __name__ == "__main__":
|
97 |
main()
|