Update app.py
Browse files
app.py
CHANGED
@@ -391,68 +391,67 @@ def qa_list_gen(claim,srl_list,evidence):
|
|
391 |
#-------------------------------------------------------------------------
|
392 |
# Handle form submission
|
393 |
if submitted and claim_text and evidence_text:
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
list_misc = []
|
404 |
-
|
405 |
-
for item in qa_list:
|
406 |
-
question = item[0]
|
407 |
-
if any(x in question.lower() for x in ['who', 'what', 'when', 'where', 'why']):
|
408 |
-
if 'who' in question.lower():
|
409 |
-
list_who.append(item)
|
410 |
-
elif 'what' in question.lower():
|
411 |
-
list_what.append(item)
|
412 |
-
elif 'when' in question.lower():
|
413 |
-
list_when.append(item)
|
414 |
-
elif 'where' in question.lower():
|
415 |
-
list_where.append(item)
|
416 |
-
elif 'why' in question.lower():
|
417 |
-
list_why.append(item)
|
418 |
-
else:
|
419 |
-
list_misc.append(item)
|
420 |
-
lists = [list_who, list_when, list_why, list_where, list_what]
|
421 |
-
for j, lst in enumerate(lists):
|
422 |
-
for i, l in enumerate(lst):
|
423 |
-
if l: # check if list is not empty
|
424 |
-
l[0] = f"Q{i+1}: {l[0]}"
|
425 |
-
l[1] = f"Claim:- {l[1]}"
|
426 |
-
if l[2]:
|
427 |
-
l[2] = f"answer retrieved from evidence:- {l[2]}"
|
428 |
-
else:
|
429 |
-
l[2] = f"answer retrieved from evidence:- No mention of '{['who', 'when', 'why', 'where', 'what'][j]}' in any related documents."
|
430 |
-
|
431 |
-
for i in range(len(lists)):
|
432 |
-
if not lists[i]:
|
433 |
-
lists[i].extend([["No claims", "", f"No mention of '{['who', 'when', 'why', 'where', 'what'][i]}' in any related documents.", "❔ Not verifiable"]])
|
434 |
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
391 |
#-------------------------------------------------------------------------
|
392 |
# Handle form submission
|
393 |
if submitted and claim_text and evidence_text:
|
394 |
+
st.caption(':green[Kindly hold on for a few minutes while the QA pairs are being generated]')
|
395 |
+
srl_list = list(itertools.chain(*[list(s) for s in srl(claim_text)]))
|
396 |
+
qa_list=qa_list_gen(claim_text,srl_list,evidence_text)
|
397 |
+
list_who = []
|
398 |
+
list_what = []
|
399 |
+
list_when = []
|
400 |
+
list_where = []
|
401 |
+
list_why = []
|
402 |
+
list_misc = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
403 |
|
404 |
+
for item in qa_list:
|
405 |
+
question = item[0]
|
406 |
+
if any(x in question.lower() for x in ['who', 'what', 'when', 'where', 'why']):
|
407 |
+
if 'who' in question.lower():
|
408 |
+
list_who.append(item)
|
409 |
+
elif 'what' in question.lower():
|
410 |
+
list_what.append(item)
|
411 |
+
elif 'when' in question.lower():
|
412 |
+
list_when.append(item)
|
413 |
+
elif 'where' in question.lower():
|
414 |
+
list_where.append(item)
|
415 |
+
elif 'why' in question.lower():
|
416 |
+
list_why.append(item)
|
417 |
+
else:
|
418 |
+
list_misc.append(item)
|
419 |
+
lists = [list_who, list_when, list_why, list_where, list_what]
|
420 |
+
for j, lst in enumerate(lists):
|
421 |
+
for i, l in enumerate(lst):
|
422 |
+
if l: # check if list is not empty
|
423 |
+
l[0] = f"Q{i+1}: {l[0]}"
|
424 |
+
l[1] = f"Claim:- {l[1]}"
|
425 |
+
if l[2]:
|
426 |
+
l[2] = f"answer retrieved from evidence:- {l[2]}"
|
427 |
+
else:
|
428 |
+
l[2] = f"answer retrieved from evidence:- No mention of '{['who', 'when', 'why', 'where', 'what'][j]}' in any related documents."
|
429 |
+
|
430 |
+
for i in range(len(lists)):
|
431 |
+
if not lists[i]:
|
432 |
+
lists[i].extend([["No claims", "", f"No mention of '{['who', 'when', 'why', 'where', 'what'][i]}' in any related documents.", "❔ Not verifiable"]])
|
433 |
+
|
434 |
+
|
435 |
+
final_df = pd.DataFrame(columns=['Who Claims', 'What Claims', 'When Claims', 'Where Claims', 'Why Claims', 'Misc Claims'])
|
436 |
+
|
437 |
+
all_items_who = [item for item_list in list_who for item in item_list]
|
438 |
+
all_items_what = [item for item_list in list_what for item in item_list]
|
439 |
+
all_items_when = [item for item_list in list_when for item in item_list]
|
440 |
+
all_items_where = [item for item_list in list_where for item in item_list]
|
441 |
+
all_items_why = [item for item_list in list_why for item in item_list]
|
442 |
+
all_items_misc = [item for item_list in list_misc for item in item_list]
|
443 |
+
|
444 |
+
|
445 |
+
max_rows = max(len(all_items_who), len(all_items_what), len(all_items_when), len(all_items_where), len(all_items_why), len(all_items_misc))
|
446 |
+
|
447 |
+
final_df['Who Claims'] = all_items_who + [''] * (max_rows - len(all_items_who))
|
448 |
+
final_df['What Claims'] = all_items_what + [''] * (max_rows - len(all_items_what))
|
449 |
+
final_df['When Claims'] = all_items_when + [''] * (max_rows - len(all_items_when))
|
450 |
+
final_df['Where Claims'] = all_items_where + [''] * (max_rows - len(all_items_where))
|
451 |
+
final_df['Why Claims'] = all_items_why + [''] * (max_rows - len(all_items_why))
|
452 |
+
final_df['Misc Claims'] = all_items_misc + [''] * (max_rows - len(all_items_misc))
|
453 |
+
st.write(f"""Claim : {claim_text}""")
|
454 |
+
st.write(f"""Evidence : {evidence_text}""")
|
455 |
+
st.table(final_df)
|
456 |
+
else:
|
457 |
+
st.warning("You need to input both the claim and evidence and then press Submit")
|