CarlosMalaga
commited on
Commit
•
e3700f2
1
Parent(s):
8d04bb9
Update app.py
Browse files
app.py
CHANGED
@@ -301,6 +301,11 @@ def run_client():
|
|
301 |
st.session_state["relik_model"] = load_model()
|
302 |
relik_model = st.session_state["relik_model"][0]
|
303 |
|
|
|
|
|
|
|
|
|
|
|
304 |
# ReLik API call
|
305 |
if submit:
|
306 |
|
@@ -344,47 +349,40 @@ def run_client():
|
|
344 |
<ul style='color: black;'>
|
345 |
""" + candidate_text + "</ul>"
|
346 |
|
347 |
-
st.markdown(text, unsafe_allow_html=True)
|
348 |
else:
|
349 |
-
if selection_list == "Top-k DB in Taxonomy Intervention" or selection_list == "Top-k DB in
|
350 |
-
response = relik_model.retrieve(text, k=
|
351 |
-
|
352 |
-
candidates_text = []
|
353 |
-
for pred in response[0]:
|
354 |
-
if pred.document.text in db_set:
|
355 |
-
candidates_text.append(pred.document.text)
|
356 |
-
|
357 |
-
|
358 |
else:
|
359 |
response = relik_model.retrieve(text, k=10, batch_size=400, progress_bar=False)
|
360 |
-
|
361 |
-
|
362 |
-
for pred in response[0]:
|
363 |
-
candidates_text.append(pred.document.text)
|
364 |
-
|
365 |
if candidates_text:
|
366 |
-
|
367 |
|
368 |
-
dict_of_ents_candidates, options_candidates = get_retriever_annotations_candidates(text,
|
369 |
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
)
|
383 |
-
# Button to save the selected candidates to a file
|
384 |
if st.button("Save Selected Candidates"):
|
385 |
-
write_candidates_to_file(text, dict_of_ents_candidates["ents"], selected_candidates)
|
386 |
st.success("Selected candidates have been saved to file.")
|
387 |
-
|
|
|
|
|
|
|
|
|
388 |
else:
|
389 |
|
390 |
text = "<h2 style='color: black;'>No Candidates Found</h2>"
|
|
|
301 |
st.session_state["relik_model"] = load_model()
|
302 |
relik_model = st.session_state["relik_model"][0]
|
303 |
|
304 |
+
if 'candidates' not in st.session_state:
|
305 |
+
st.session_state['candidates'] = []
|
306 |
+
if 'selected_candidates' not in st.session_state:
|
307 |
+
st.session_state['selected_candidates'] = []
|
308 |
+
|
309 |
# ReLik API call
|
310 |
if submit:
|
311 |
|
|
|
349 |
<ul style='color: black;'>
|
350 |
""" + candidate_text + "</ul>"
|
351 |
|
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 |
+
dict_of_ents_candidates, options_candidates = get_retriever_annotations_candidates(text, st.session_state.candidates)
|
365 |
|
366 |
+
st.markdown("<h2 style='color: black;'>Possible Candidates:</h2>", unsafe_allow_html=True)
|
367 |
+
|
368 |
+
# Display the candidates with checkboxes
|
369 |
+
for candidate in dict_of_ents_candidates["ents"]:
|
370 |
+
if st.checkbox(candidate, key=candidate):
|
371 |
+
if candidate not in st.session_state.selected_candidates:
|
372 |
+
st.session_state.selected_candidates.append(candidate)
|
373 |
+
else:
|
374 |
+
if candidate in st.session_state.selected_candidates:
|
375 |
+
st.session_state.selected_candidates.remove(candidate)
|
376 |
+
|
377 |
+
# Button to save the selected candidates to a file
|
|
|
|
|
378 |
if st.button("Save Selected Candidates"):
|
379 |
+
write_candidates_to_file(text, dict_of_ents_candidates["ents"], st.session_state.selected_candidates)
|
380 |
st.success("Selected candidates have been saved to file.")
|
381 |
+
else:
|
382 |
+
st.session_state.candidates = []
|
383 |
+
st.session_state.selected_candidates = []
|
384 |
+
st.markdown("<h2 style='color: black;'>No Candidates Found</h2>", unsafe_allow_html=True)
|
385 |
+
|
386 |
else:
|
387 |
|
388 |
text = "<h2 style='color: black;'>No Candidates Found</h2>"
|