mbosse99 commited on
Commit
13906ad
·
1 Parent(s): 4aa28d5

Update with Sorting Final Questions

Browse files
Files changed (1) hide show
  1. app.py +57 -8
app.py CHANGED
@@ -12,6 +12,11 @@ import time
12
  import calendar
13
  import re
14
 
 
 
 
 
 
15
  connection_string = os.getenv("CONNECTION")
16
  blob_service_client = BlobServiceClient.from_connection_string(connection_string)
17
 
@@ -31,7 +36,11 @@ def upload_blob(pdf_name, json_data, pdf_data_jobdescription,pdf_data_cvs, pre_g
31
  pdf_blob_client.upload_blob(pdf_data_jobdescription, overwrite=True)
32
 
33
  upload_job_db_item(pdf_name,len(pdf_data_cvs),json.loads(json_data),pre_generated_bool, custom_questions)
34
-
 
 
 
 
35
  links = []
36
  names = []
37
  for i,cv in enumerate(pdf_data_cvs):
@@ -115,6 +124,28 @@ def upload_db_item(name, data, job_description_id, cv_id):
115
  except Exception as e:
116
  print(f"Allgemeiner Fehler: {str(e)}")
117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  st.markdown(
119
  """
120
  <style>
@@ -143,6 +174,9 @@ if "pdf_data_jobdescription_string" not in st.session_state:
143
  if "final_question_string" not in st.session_state:
144
  st.session_state["final_question_string"] = []
145
 
 
 
 
146
  with open("sys_prompt_frontend.txt") as f:
147
  sys_prompt = f.read()
148
 
@@ -199,7 +233,7 @@ with st.container():
199
  try:
200
  st.write("The questions are generated. This may take a short moment...")
201
  res = openai.ChatCompletion.create(
202
- model="gpt-4",
203
  temperature=0.2,
204
  messages=[
205
  {
@@ -208,7 +242,7 @@ with st.container():
208
  },
209
  ],
210
  )
211
- st.session_state["ai_questions"] = res.choices[0]["message"]["content"].split("\n")
212
  for i,q in enumerate(res.choices[0]["message"]["content"].split("\n")):
213
  st.session_state["disable_row_"+str(i)] = False
214
  st.rerun()
@@ -234,6 +268,25 @@ with st.container():
234
  st.rerun()
235
  with cols[0]:
236
  st.text_area(label="Question "+str(i+1)+":",value=question,label_visibility="collapsed",key="text_area_"+str(i),disabled=st.session_state["disable_row_"+str(i)])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
  else:
238
  with st.expander("Enter up to three predefined questions if needed. Otherwise leave it blank:"):
239
  question_one = st.text_input("Enter the first question:")
@@ -283,8 +336,4 @@ with st.container():
283
 
284
 
285
  if not upload_success:
286
- st.error('An error has occurred. Please contact the administrator. Sorry for the inconvenience.', icon="🚨")
287
- # else:
288
- # col_submit_btn, col_empty, col_clear_btn = st.columns([1,4, 1])
289
- # if col_clear_btn.button("Clear" ,use_container_width=True):
290
- # streamlit_js_eval(js_expressions="parent.window.location.reload()")
 
12
  import calendar
13
  import re
14
 
15
+ openai.api_key = os.getenv("OPENAI_API_KEY")
16
+ openai.api_base = "https://tensora-oai.openai.azure.com/"
17
+ openai.api_type = "azure"
18
+ openai.api_version = "2023-05-15"
19
+
20
  connection_string = os.getenv("CONNECTION")
21
  blob_service_client = BlobServiceClient.from_connection_string(connection_string)
22
 
 
36
  pdf_blob_client.upload_blob(pdf_data_jobdescription, overwrite=True)
37
 
38
  upload_job_db_item(pdf_name,len(pdf_data_cvs),json.loads(json_data),pre_generated_bool, custom_questions)
39
+ if pre_generated_bool:
40
+ for i,question in enumerate(custom_questions):
41
+ question_nr_for_id = i+1
42
+ question_id = pdf_name + "-question-nr-" + str(question_nr_for_id)+str(calendar.timegm(time.gmtime()))
43
+ upload_question_db_item(question_id, pdf_name, question,st.session_state["pdf_data_jobdescription_string"])
44
  links = []
45
  names = []
46
  for i,cv in enumerate(pdf_data_cvs):
 
124
  except Exception as e:
125
  print(f"Allgemeiner Fehler: {str(e)}")
126
 
127
+ def upload_question_db_item(id, job_id, question, job_content):
128
+ endpoint = "https://wg-candidate-data.documents.azure.com:443/"
129
+ key = os.getenv("CONNECTION_DB")
130
+ client = CosmosClient(endpoint, key)
131
+ database = client.get_database_client("ToDoList")
132
+ container = database.get_container_client("Questions")
133
+ question_item = {
134
+ "id": id,
135
+ "partitionKey" : "wg-question-data-v1",
136
+ "job_id": job_id,
137
+ "question_content": question,
138
+ "job_description": job_content,
139
+ }
140
+ try:
141
+ # Fügen Sie das Element in den Container ein
142
+ container.create_item(body=question_item)
143
+ print("Eintrag erfolgreich in die Cosmos DB eingefügt. Container: Questions(Question Data)")
144
+ except exceptions.CosmosHttpResponseError as e:
145
+ print(f"Fehler beim Schreiben in die Cosmos DB: {str(e)}")
146
+ except Exception as e:
147
+ print(f"Allgemeiner Fehler: {str(e)}")
148
+
149
  st.markdown(
150
  """
151
  <style>
 
174
  if "final_question_string" not in st.session_state:
175
  st.session_state["final_question_string"] = []
176
 
177
+ def adjust_numbering(lst):
178
+ return [f"{i + 1}. {item.split('. ', 1)[1]}" for i, item in enumerate(lst)]
179
+
180
  with open("sys_prompt_frontend.txt") as f:
181
  sys_prompt = f.read()
182
 
 
233
  try:
234
  st.write("The questions are generated. This may take a short moment...")
235
  res = openai.ChatCompletion.create(
236
+ engine="gpt-4",
237
  temperature=0.2,
238
  messages=[
239
  {
 
242
  },
243
  ],
244
  )
245
+ st.session_state["ai_questions"] = [item for item in res.choices[0]["message"]["content"].split("\n") if len(item) > 0]
246
  for i,q in enumerate(res.choices[0]["message"]["content"].split("\n")):
247
  st.session_state["disable_row_"+str(i)] = False
248
  st.rerun()
 
268
  st.rerun()
269
  with cols[0]:
270
  st.text_area(label="Question "+str(i+1)+":",value=question,label_visibility="collapsed",key="text_area_"+str(i),disabled=st.session_state["disable_row_"+str(i)])
271
+ for i,final_q in enumerate(st.session_state["final_question_string"]):
272
+ cols_final = st.columns([5,1])
273
+ with cols_final[1]:
274
+ if st.button("Up",use_container_width=True,key="btn_up_row_"+str(i),disabled=True if i == 0 else False):
275
+ if i > 0:
276
+ # Tausche das aktuelle Element mit dem vorherigen Element
277
+ st.session_state.final_question_string[i], st.session_state.final_question_string[i - 1] = \
278
+ st.session_state.final_question_string[i - 1], st.session_state.final_question_string[i]
279
+ st.session_state.final_question_string = adjust_numbering(st.session_state.final_question_string)
280
+ st.rerun()
281
+ if st.button("Down",use_container_width=True,key="btn_down_row_"+str(i), disabled=True if i == len(st.session_state["final_question_string"])-1 else False):
282
+ if i < len(st.session_state.final_question_string) - 1:
283
+ # Tausche das aktuelle Element mit dem nächsten Element
284
+ st.session_state.final_question_string[i], st.session_state.final_question_string[i + 1] = \
285
+ st.session_state.final_question_string[i + 1], st.session_state.final_question_string[i]
286
+ st.session_state.final_question_string = adjust_numbering(st.session_state.final_question_string)
287
+ st.rerun()
288
+ with cols_final[0]:
289
+ st.write(final_q)
290
  else:
291
  with st.expander("Enter up to three predefined questions if needed. Otherwise leave it blank:"):
292
  question_one = st.text_input("Enter the first question:")
 
336
 
337
 
338
  if not upload_success:
339
+ st.error('An error has occurred. Please contact the administrator. Sorry for the inconvenience.', icon="🚨")