CarlosMalaga commited on
Commit
7f7fc6a
1 Parent(s): 4a0b379

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -11
app.py CHANGED
@@ -166,6 +166,20 @@ with open("/home/user/app/models/retriever/document_index/documents.jsonl", "r")
166
  element = json.loads(line)
167
  io_map[element["text"]] = element["metadata"]["type"]
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  @st.cache_resource()
170
  def load_model():
171
 
@@ -249,7 +263,7 @@ def run_client():
249
  index=0 # Default to 'question'
250
  )
251
 
252
- selection_options = ["DB Intervention (GPT)", "DB Outcome (GPT)", "Taxonomy Intervention (GPT)", "Taxonomy Outcome (GPT)"]
253
 
254
  if analysis_type == "Retriever":
255
  # Selection list using selectbox
@@ -328,20 +342,38 @@ def run_client():
328
 
329
  st.markdown(text, unsafe_allow_html=True)
330
  else:
331
- response = relik_model.retrieve(text, k=10, batch_size=100, progress_bar=False)
 
 
 
 
 
 
332
 
333
- candidates_text = []
334
- for pred in response[0]:
335
- candidates_text.append(pred.document.text)
336
 
337
- dict_of_ents_candidates, options_candidates = get_retriever_annotations_candidates(text, candidates_text)
 
338
 
339
- text = """
340
- <h2 style='color: black;'>Possible Candidates:</h2>
341
- <ul style='color: black;'>
342
- """ + "".join(f"<li style='color: black;'>{candidate}</li>" for candidate in dict_of_ents_candidates["ents"][0:10]) + "</ul>"
 
 
343
 
344
- st.markdown(text, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
345
  else:
346
  st.error("Please enter some text.")
347
 
 
166
  element = json.loads(line)
167
  io_map[element["text"]] = element["metadata"]["type"]
168
 
169
+
170
+ import json
171
+ db_set = set()
172
+ with open("models/retriever/intervention/gpt/db/document_index/documents.jsonl", "r") as r:
173
+ for line in r:
174
+ element = json.loads(line)
175
+ db_set.add(element["text"])
176
+
177
+ with open("models/retriever/outcome/gpt/db/document_index/documents.jsonl", "r") as r:
178
+ for line in r:
179
+ element = json.loads(line)
180
+ db_set.add(element["text"])
181
+
182
+
183
  @st.cache_resource()
184
  def load_model():
185
 
 
263
  index=0 # Default to 'question'
264
  )
265
 
266
+ selection_options = ["DB Intervention", "DB Outcome", "Top-k DB Intervention", "Top-k Soft DB Outcome", "Taxonomy Intervention", "Taxonomy Outcome"]
267
 
268
  if analysis_type == "Retriever":
269
  # Selection list using selectbox
 
342
 
343
  st.markdown(text, unsafe_allow_html=True)
344
  else:
345
+ if "Top-k" in selection_options:
346
+ response = relik_model.retrieve(text, k=100, batch_size=400, progress_bar=False)
347
+
348
+ candidates_text = []
349
+ for pred in response[0]:
350
+ if pred.document.text in db_set:
351
+ candidates_text.append(pred.document.text)
352
 
 
 
 
353
 
354
+ else:
355
+ response = relik_model.retrieve(text, k=10, batch_size=400, progress_bar=False)
356
 
357
+ candidates_text = []
358
+ for pred in response[0]:
359
+ candidates_text.append(pred.document.text)
360
+
361
+ if candidates_text:
362
+ candidates_text = candidates_text[:5]
363
 
364
+ dict_of_ents_candidates, options_candidates = get_retriever_annotations_candidates(text, candidates_text)
365
+
366
+
367
+ text = """
368
+ <h2 style='color: black;'>Possible Candidates:</h2>
369
+ <ul style='color: black;'>
370
+ """ + "".join(f"<li style='color: black;'>{candidate}</li>" for candidate in dict_of_ents_candidates["ents"]) + "</ul>"
371
+
372
+ st.markdown(text, unsafe_allow_html=True)
373
+ else:
374
+
375
+ text = "<h2 style='color: black;'>No Candidates Found</h2>"
376
+
377
  else:
378
  st.error("Please enter some text.")
379