Towhidul commited on
Commit
bcce480
1 Parent(s): 7cbc810

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -66
app.py CHANGED
@@ -8,6 +8,7 @@ import requests
8
  from PIL import Image
9
  import itertools
10
 
 
11
 
12
  HF_SPACES_API_KEY = st.secrets["HF_token"]
13
 
@@ -116,11 +117,17 @@ def proc():
116
  st.write(st.session_state.text_key)
117
 
118
 
119
- claim_text=st.text_area("Enter your claim:", on_change=proc, key='text_key')
120
 
121
 
122
 
123
- evidence_text=st.text_area("Enter your evidence:")
 
 
 
 
 
 
124
 
125
  # form_evidence = st.form(key='my_evidence')
126
  # form_evidence.text_input(label='Enter your evidence')
@@ -382,68 +389,70 @@ def qa_list_gen(claim,srl_list,evidence):
382
  return list_of_qa_pipeline
383
 
384
  #-------------------------------------------------------------------------
385
-
386
-
387
- if claim_text and evidence_text:
388
- st.caption(':green[Kindly hold on for a few minutes while the QA pairs are being generated]')
389
- srl_list = list(itertools.chain(*[list(s) for s in srl(claim_text)]))
390
- qa_list=qa_list_gen(claim_text,srl_list,evidence_text)
391
- list_who = []
392
- list_what = []
393
- list_when = []
394
- list_where = []
395
- list_why = []
396
- list_misc = []
397
-
398
- for item in qa_list:
399
- question = item[0]
400
- if any(x in question.lower() for x in ['who', 'what', 'when', 'where', 'why']):
401
- if 'who' in question.lower():
402
- list_who.append(item)
403
- elif 'what' in question.lower():
404
- list_what.append(item)
405
- elif 'when' in question.lower():
406
- list_when.append(item)
407
- elif 'where' in question.lower():
408
- list_where.append(item)
409
- elif 'why' in question.lower():
410
- list_why.append(item)
411
- else:
412
- list_misc.append(item)
413
- lists = [list_who, list_when, list_why, list_where, list_what]
414
- for j, lst in enumerate(lists):
415
- for i, l in enumerate(lst):
416
- if l: # check if list is not empty
417
- l[0] = f"Q{i+1}: {l[0]}"
418
- l[1] = f"Claim:- {l[1]}"
419
- if l[2]:
420
- l[2] = f"answer retrieved from evidence:- {l[2]}"
421
- else:
422
- l[2] = f"answer retrieved from evidence:- No mention of '{['who', 'when', 'why', 'where', 'what'][j]}' in any related documents."
423
-
424
- for i in range(len(lists)):
425
- if not lists[i]:
426
- lists[i].extend([["No claims", "", f"No mention of '{['who', 'when', 'why', 'where', 'what'][i]}' in any related documents.", "❔ Not verifiable"]])
427
-
428
-
429
- final_df = pd.DataFrame(columns=['Who Claims', 'What Claims', 'When Claims', 'Where Claims', 'Why Claims', 'Misc Claims'])
430
-
431
- all_items_who = [item for item_list in list_who for item in item_list]
432
- all_items_what = [item for item_list in list_what for item in item_list]
433
- all_items_when = [item for item_list in list_when for item in item_list]
434
- all_items_where = [item for item_list in list_where for item in item_list]
435
- all_items_why = [item for item_list in list_why for item in item_list]
436
- all_items_misc = [item for item_list in list_misc for item in item_list]
437
-
438
-
439
- 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))
440
 
441
- final_df['Who Claims'] = all_items_who + [''] * (max_rows - len(all_items_who))
442
- final_df['What Claims'] = all_items_what + [''] * (max_rows - len(all_items_what))
443
- final_df['When Claims'] = all_items_when + [''] * (max_rows - len(all_items_when))
444
- final_df['Where Claims'] = all_items_where + [''] * (max_rows - len(all_items_where))
445
- final_df['Why Claims'] = all_items_why + [''] * (max_rows - len(all_items_why))
446
- final_df['Misc Claims'] = all_items_misc + [''] * (max_rows - len(all_items_misc))
447
- st.write(f"""Claim : {claim_text}""")
448
- st.write(f"""Evidence : {evidence_text}""")
449
- st.table(final_df)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  from PIL import Image
9
  import itertools
10
 
11
+ st.set_page_config(page_title="FACTIFY - 5WQA", layout="wide")
12
 
13
  HF_SPACES_API_KEY = st.secrets["HF_token"]
14
 
 
117
  st.write(st.session_state.text_key)
118
 
119
 
120
+ # claim_text=st.text_area("Enter your claim:", on_change=proc, key='text_key')
121
 
122
 
123
 
124
+ # evidence_text=st.text_area("Enter your evidence:")
125
+ with st.form(key="claim_evidence_form",clear_on_submit=True):
126
+ claim_text = st.text_input()
127
+ evidence_text = st.text_input()
128
+ submitted = st.form_submit_button("Submit")
129
+
130
+
131
 
132
  # form_evidence = st.form(key='my_evidence')
133
  # form_evidence.text_input(label='Enter your evidence')
 
389
  return list_of_qa_pipeline
390
 
391
  #-------------------------------------------------------------------------
392
+ # Handle form submission
393
+ if submitted and claim_text and evidence_text:
394
+ if not claim_text or not claim_text:
395
+ st.warning("You need to input both the claim and evidence and then press Submit")
396
+ else:
397
+ st.caption(':green[Kindly hold on for a few minutes while the QA pairs are being generated]')
398
+ srl_list = list(itertools.chain(*[list(s) for s in srl(claim_text)]))
399
+ qa_list=qa_list_gen(claim_text,srl_list,evidence_text)
400
+ list_who = []
401
+ list_what = []
402
+ list_when = []
403
+ list_where = []
404
+ list_why = []
405
+ list_misc = []
406
+
407
+ for item in qa_list:
408
+ question = item[0]
409
+ if any(x in question.lower() for x in ['who', 'what', 'when', 'where', 'why']):
410
+ if 'who' in question.lower():
411
+ list_who.append(item)
412
+ elif 'what' in question.lower():
413
+ list_what.append(item)
414
+ elif 'when' in question.lower():
415
+ list_when.append(item)
416
+ elif 'where' in question.lower():
417
+ list_where.append(item)
418
+ elif 'why' in question.lower():
419
+ list_why.append(item)
420
+ else:
421
+ list_misc.append(item)
422
+ lists = [list_who, list_when, list_why, list_where, list_what]
423
+ for j, lst in enumerate(lists):
424
+ for i, l in enumerate(lst):
425
+ if l: # check if list is not empty
426
+ l[0] = f"Q{i+1}: {l[0]}"
427
+ l[1] = f"Claim:- {l[1]}"
428
+ if l[2]:
429
+ l[2] = f"answer retrieved from evidence:- {l[2]}"
430
+ else:
431
+ l[2] = f"answer retrieved from evidence:- No mention of '{['who', 'when', 'why', 'where', 'what'][j]}' in any related documents."
432
+
433
+ for i in range(len(lists)):
434
+ if not lists[i]:
435
+ lists[i].extend([["No claims", "", f"No mention of '{['who', 'when', 'why', 'where', 'what'][i]}' in any related documents.", "❔ Not verifiable"]])
 
 
 
 
 
 
 
 
 
 
 
436
 
437
+
438
+ final_df = pd.DataFrame(columns=['Who Claims', 'What Claims', 'When Claims', 'Where Claims', 'Why Claims', 'Misc Claims'])
439
+
440
+ all_items_who = [item for item_list in list_who for item in item_list]
441
+ all_items_what = [item for item_list in list_what for item in item_list]
442
+ all_items_when = [item for item_list in list_when for item in item_list]
443
+ all_items_where = [item for item_list in list_where for item in item_list]
444
+ all_items_why = [item for item_list in list_why for item in item_list]
445
+ all_items_misc = [item for item_list in list_misc for item in item_list]
446
+
447
+
448
+ 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))
449
+
450
+ final_df['Who Claims'] = all_items_who + [''] * (max_rows - len(all_items_who))
451
+ final_df['What Claims'] = all_items_what + [''] * (max_rows - len(all_items_what))
452
+ final_df['When Claims'] = all_items_when + [''] * (max_rows - len(all_items_when))
453
+ final_df['Where Claims'] = all_items_where + [''] * (max_rows - len(all_items_where))
454
+ final_df['Why Claims'] = all_items_why + [''] * (max_rows - len(all_items_why))
455
+ final_df['Misc Claims'] = all_items_misc + [''] * (max_rows - len(all_items_misc))
456
+ st.write(f"""Claim : {claim_text}""")
457
+ st.write(f"""Evidence : {evidence_text}""")
458
+ st.table(final_df)