CarlosMalaga commited on
Commit
bbfcd2c
1 Parent(s): f7ebab3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -23
app.py CHANGED
@@ -243,10 +243,13 @@ def set_intro(css):
243
  # )
244
 
245
  def write_candidates_to_file(text, candidates, selected_candidates):
 
 
 
246
  # Write the selected candidates to a file
247
  with open("logs/selected_candidates.tsv", "a") as file:
248
- file.write(text + "\t" + str(candidates) + str(selected_candidates) + "\n")
249
-
250
 
251
  def run_client():
252
  with open(Path(__file__).parent / "style.css") as f:
@@ -352,15 +355,36 @@ def run_client():
352
  st.markdown(text, unsafe_allow_html=True)
353
  else:
354
  if selection_list == "Top-k DB in Taxonomy Intervention" or selection_list == "Top-k DB in Taxonomy Outcome":
355
- response = relik_model.retrieve(text, k=50, batch_size=400, progress_bar=False)
356
  candidates_text = [pred.document.text for pred in response[0] if pred.document.text in db_set]
357
  else:
358
  response = relik_model.retrieve(text, k=10, batch_size=400, progress_bar=False)
359
  candidates_text = [pred.document.text for pred in response[0]]
360
 
361
  if candidates_text:
362
- st.session_state.candidates = candidates_text[:10]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
363
 
 
 
 
 
364
  else:
365
  st.session_state.candidates = []
366
  st.session_state.selected_candidates = []
@@ -369,24 +393,6 @@ def run_client():
369
  else:
370
  st.error("Please enter some text.")
371
 
372
- if st.session_state.candidates:
373
- dict_of_ents_candidates, options_candidates = get_retriever_annotations_candidates(text, st.session_state.candidates)
374
-
375
- st.markdown("<h2 style='color: black;'>Possible Candidates:</h2>", unsafe_allow_html=True)
376
-
377
- # Display the candidates with checkboxes
378
- for candidate in dict_of_ents_candidates["ents"]:
379
- if st.checkbox(candidate, key=candidate):
380
- if candidate not in st.session_state.selected_candidates:
381
- st.session_state.selected_candidates.append(candidate)
382
- else:
383
- if candidate in st.session_state.selected_candidates:
384
- st.session_state.selected_candidates.remove(candidate)
385
-
386
- # Button to save the selected candidates to a file
387
- if st.button("Save Selected Candidates"):
388
- write_candidates_to_file(text, dict_of_ents_candidates["ents"], st.session_state.selected_candidates)
389
- st.success("Selected candidates have been saved to file.")
390
-
391
  if __name__ == "__main__":
392
  run_client()
 
243
  # )
244
 
245
  def write_candidates_to_file(text, candidates, selected_candidates):
246
+ # Write the selected candidates to a file
247
+ # Ensure the directory exists
248
+ os.makedirs("logs", exist_ok=True)
249
  # Write the selected candidates to a file
250
  with open("logs/selected_candidates.tsv", "a") as file:
251
+ file.write(f"{text}\t{str(candidates)}\t{str(selected_candidates)}\n")
252
+
253
 
254
  def run_client():
255
  with open(Path(__file__).parent / "style.css") as f:
 
355
  st.markdown(text, unsafe_allow_html=True)
356
  else:
357
  if selection_list == "Top-k DB in Taxonomy Intervention" or selection_list == "Top-k DB in Taxonomy Outcome":
358
+ response = relik_model.retrieve(text, k=30, batch_size=400, progress_bar=False)
359
  candidates_text = [pred.document.text for pred in response[0] if pred.document.text in db_set]
360
  else:
361
  response = relik_model.retrieve(text, k=10, batch_size=400, progress_bar=False)
362
  candidates_text = [pred.document.text for pred in response[0]]
363
 
364
  if candidates_text:
365
+ st.session_state.candidates = candidates_text[:5]
366
+
367
+ dict_of_ents_candidates, options_candidates = get_retriever_annotations_candidates(text, st.session_state.candidates)
368
+
369
+ st.markdown("<h2 style='color: black;'>Possible Candidates:</h2>", unsafe_allow_html=True)
370
+
371
+ # Display the candidates with checkboxes
372
+ for candidate in dict_of_ents_candidates["ents"]:
373
+ if candidate in st.session_state.selected_candidates:
374
+ checked = True
375
+ else:
376
+ checked = False
377
+ if st.checkbox(candidate, key=candidate, value=checked):
378
+ if candidate not in st.session_state.selected_candidates:
379
+ st.session_state.selected_candidates.append(candidate)
380
+ else:
381
+ if candidate in st.session_state.selected_candidates:
382
+ st.session_state.selected_candidates.remove(candidate)
383
 
384
+ # Button to save the selected candidates to a file
385
+ if st.button("Save Selected Candidates"):
386
+ write_candidates_to_file(text, dict_of_ents_candidates["ents"], st.session_state.selected_candidates)
387
+ st.success("Selected candidates have been saved to file.")
388
  else:
389
  st.session_state.candidates = []
390
  st.session_state.selected_candidates = []
 
393
  else:
394
  st.error("Please enter some text.")
395
 
396
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
397
  if __name__ == "__main__":
398
  run_client()