mbosse99 commited on
Commit
989e499
·
1 Parent(s): 13906ad

Update to Spinner

Browse files
Files changed (1) hide show
  1. app.py +53 -34
app.py CHANGED
@@ -231,43 +231,58 @@ with st.container():
231
  system = sys_prompt.format(job=st.session_state["pdf_data_jobdescription_string"], resume=st.session_state["pdf_data_cvs_string"], n=15)
232
  if not st.session_state["ai_questions"]:
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
- {
240
- "role": "system",
241
- "content": system,
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()
 
 
249
  except Exception as e:
250
  print(f"Fehler beim generieren der Fragen: {str(e)}")
251
  st.error("An error has occurred. Please reload the page or contact the admin.", icon="🚨")
252
  else:
253
- for i,question in enumerate(st.session_state["ai_questions"]):
254
- cols = st.columns([5,1])
255
- with cols[1]:
256
- if st.button("Accept",use_container_width=True,key="btn_accept_row_"+str(i)):
257
- print("accept")
258
- pattern = re.compile(r"^[1-9][0-9]?\.")
259
- questions_length = len(st.session_state["final_question_string"])
260
- question_from_text_area = st.session_state["text_area_"+str(i)]
261
- question_to_append = str(questions_length+1)+"."+re.sub(pattern, "", question_from_text_area)
262
- st.session_state["final_question_string"].append(question_to_append)
263
- st.session_state["disable_row_"+str(i)] = True
264
- st.rerun()
265
- if st.button("Delete",use_container_width=True,key="btn_del_row_"+str(i)):
266
- print("delete")
267
- st.session_state["ai_questions"].remove(question)
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]:
@@ -336,4 +351,8 @@ with st.container():
336
 
337
 
338
  if not upload_success:
339
- st.error('An error has occurred. Please contact the administrator. Sorry for the inconvenience.', icon="🚨")
 
 
 
 
 
231
  system = sys_prompt.format(job=st.session_state["pdf_data_jobdescription_string"], resume=st.session_state["pdf_data_cvs_string"], n=15)
232
  if not st.session_state["ai_questions"]:
233
  try:
234
+ # st.write("The questions are generated. This may take a short moment...")
235
+ st.info("The questions are generated. This may take a short moment.", icon="ℹ️")
236
+ with st.spinner("Loading..."):
237
+ res = openai.ChatCompletion.create(
238
+ engine="gpt-4",
239
+ temperature=0.2,
240
+ messages=[
241
+ {
242
+ "role": "system",
243
+ "content": system,
244
+ },
245
+ ],
246
+ )
247
+ st.session_state["ai_questions"] = [item for item in res.choices[0]["message"]["content"].split("\n") if len(item) > 0]
248
+ for i,q in enumerate(res.choices[0]["message"]["content"].split("\n")):
249
+ st.session_state["disable_row_"+str(i)] = False
250
+ st.rerun()
251
  except Exception as e:
252
  print(f"Fehler beim generieren der Fragen: {str(e)}")
253
  st.error("An error has occurred. Please reload the page or contact the admin.", icon="🚨")
254
  else:
255
+ if len(st.session_state["final_question_string"]) <= 0:
256
+ for i,question in enumerate(st.session_state["ai_questions"]):
257
+ cols = st.columns([5,1])
258
+ with cols[1]:
259
+ # if st.button("Accept",use_container_width=True,key="btn_accept_row_"+str(i)):
260
+ # print("accept")
261
+ # pattern = re.compile(r"^[1-9][0-9]?\.")
262
+ # questions_length = len(st.session_state["final_question_string"])
263
+ # question_from_text_area = st.session_state["text_area_"+str(i)]
264
+ # question_to_append = str(questions_length+1)+"."+re.sub(pattern, "", question_from_text_area)
265
+ # st.session_state["final_question_string"].append(question_to_append)
266
+ # st.session_state["disable_row_"+str(i)] = True
267
+ # st.rerun()
268
+ if st.button("Delete",use_container_width=True,key="btn_del_row_"+str(i)):
269
+ print("delete")
270
+ st.session_state["ai_questions"].remove(question)
271
+ st.rerun()
272
+ with cols[0]:
273
+ 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)])
274
+ st.write("If you are satisfied with the questions, then accept them. You can still sort them afterwards.")
275
+ if st.button("Accept all questions",use_container_width=True,key="accept_all_questions"):
276
+ print("accept all")
277
+ for i,question in enumerate(st.session_state["ai_questions"]):
278
+ print("accept")
279
+ pattern = re.compile(r"^[1-9][0-9]?\.")
280
+ questions_length = len(st.session_state["final_question_string"])
281
+ question_from_text_area = st.session_state["text_area_"+str(i)]
282
+ question_to_append = str(questions_length+1)+"."+re.sub(pattern, "", question_from_text_area)
283
+ st.session_state["final_question_string"].append(question_to_append)
284
+ st.session_state["disable_row_"+str(i)] = True
285
+ st.rerun()
286
  for i,final_q in enumerate(st.session_state["final_question_string"]):
287
  cols_final = st.columns([5,1])
288
  with cols_final[1]:
 
351
 
352
 
353
  if not upload_success:
354
+ st.error('An error has occurred. Please contact the administrator. Sorry for the inconvenience.', icon="🚨")
355
+ # else:
356
+ # col_submit_btn, col_empty, col_clear_btn = st.columns([1,4, 1])
357
+ # if col_clear_btn.button("Clear" ,use_container_width=True):
358
+ # streamlit_js_eval(js_expressions="parent.window.location.reload()")