mbosse99 commited on
Commit
9e9de90
·
1 Parent(s): c22222c

Adding error handling and working clear button

Browse files
Files changed (1) hide show
  1. app.py +53 -41
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
- container_name = "jobdescriptions"
14
- json_blob_name = f"{pdf_name}_jsondata.json"
15
- pdf_blob_name = f"{pdf_name}.pdf"
 
16
 
17
- container_client = blob_service_client.get_container_client(container_name)
18
 
19
- json_blob_client = container_client.get_blob_client(json_blob_name)
20
- json_blob_client.upload_blob(json_data.encode('utf-8'), overwrite=True)
21
 
22
- pdf_blob_client = container_client.get_blob_client(pdf_blob_name)
23
- pdf_blob_client.upload_blob(pdf_data, overwrite=True)
24
 
25
- link = "https://tensora.ai/workgenius/cv-evaluation2/?job="+pdf_name
26
 
27
- st.write('Data and PDF have been successfully uploaded. The link to the chatbot for the potential candidates is the following: '+link)
28
 
29
- if st.button("Clear Inputs"):
30
- streamlit_js_eval(js_expressions="parent.window.location.reload()")
 
 
 
 
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
- uploaded_file = st.file_uploader("Upload a PDF file:", type=["pdf"])
57
-
58
- job_title = st.text_input("Enter the job title:")
59
- email = st.text_input("Enter the email:")
60
- if st.button("Submit"):
61
- if len(job_title) > 0 and len(email) > 0 and uploaded_file:
62
- data = {
63
- "title": job_title,
64
- "email": email
65
- }
66
- json_data = json.dumps(data, ensure_ascii=False)
67
-
68
- # Eine zufällige UUID generieren
69
- random_uuid = uuid.uuid4()
70
-
71
- # Die UUID als String darstellen
72
- uuid_string = str(random_uuid)
73
-
74
- pdf_name = uuid_string
75
-
76
- pdf_data = uploaded_file.read()
77
-
78
- upload_blob(pdf_name, json_data, pdf_data)
79
-
80
- else:
81
- st.write("Please fill out both fields and upload a PDF file.")
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()