Towhidul commited on
Commit
46bdc18
·
1 Parent(s): 835c7af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +87 -17
app.py CHANGED
@@ -364,13 +364,13 @@ def gen_qa_who(df):
364
  "early_stopping":True,
365
  "min_length": 100,"wait_for_model":True})[0]['generated_text'].capitalize()
366
  question_ids = rephrase_question_who(question_ids)
367
- list_of_ques_who.append(f"""Q{j+1}:{question_ids}""")
368
- list_of_ans_who.append(f"""Ans{j+1}:{answer[j]}""")
369
  input_evidence = f"answer_the_next_question_from_context: {question_ids} context: {evidence}"
370
  time.sleep(5)
371
  answer_evidence = query_evidence({"inputs":input_evidence,"truncation":True,"wait_for_model":True})[0]['generated_text']
372
  if answer_evidence.lower() in evidence.lower():
373
- list_of_evidence_answer_who.append(f"""Evidence{j+1}:{answer_evidence}""")
374
  else:
375
  answer_evidence=""
376
  list_of_evidence_answer_who.append(f"""No mention of 'who'in any related documents.""")
@@ -425,12 +425,12 @@ def gen_qa_what(df):
425
  "min_length": 100,"wait_for_model":True})[0]['generated_text'].capitalize()
426
  question_ids = rephrase_question_what(question_ids)
427
  list_of_ques_what.append(f"""Q{j+1}:{question_ids}""")
428
- list_of_ans_what.append(f"""Ans{j+1}:{answer[j]}""")
429
  input_evidence = f"answer_the_next_question_from_context: {question_ids} context: {evidence}"
430
  time.sleep(5)
431
  answer_evidence = query_evidence({"inputs":input_evidence,"truncation":True,"wait_for_model":True})[0]['generated_text']
432
  if answer_evidence.lower() in evidence.lower():
433
- list_of_evidence_answer_what.append(f"""Evidence{j+1}:{answer_evidence}""")
434
 
435
  else:
436
  answer_evidence=""
@@ -487,12 +487,12 @@ def gen_qa_why(df):
487
  "min_length": 100,"wait_for_model":True})[0]['generated_text'].capitalize()
488
  question_ids = rephrase_question_why(question_ids)
489
  list_of_ques_why.append(f"""Q{j+1}:{question_ids}""")
490
- list_of_ans_why.append(f"""Ans{j+1}:{answer[j]}""")
491
  input_evidence = f"answer_the_next_question_from_context: {question_ids} context: {evidence}"
492
  time.sleep(5)
493
  answer_evidence = query_evidence({"inputs":input_evidence,"truncation":True,"wait_for_model":True})[0]['generated_text']
494
  if answer_evidence.lower() in evidence.lower():
495
- list_of_evidence_answer_why.append(f"""Evidence{j+1}:{answer_evidence}""")
496
  else:
497
  answer_evidence=""
498
  list_of_evidence_answer_why.append(f"""No mention of 'why'in any related documents.""")
@@ -548,12 +548,12 @@ def gen_qa_when(df):
548
  "min_length": 100,"wait_for_model":True})[0]['generated_text'].capitalize()
549
  question_ids = rephrase_question_when(question_ids)
550
  list_of_ques_when.append(f"""Q{j+1}:{question_ids}""")
551
- list_of_ans_when.append(f"""Ans{j+1}:{answer[j]}""")
552
  input_evidence = f"answer_the_next_question_from_context: {question_ids} context: {evidence}"
553
  time.sleep(5)
554
  answer_evidence = query_evidence({"inputs":input_evidence,"truncation":True,"wait_for_model":True})[0]['generated_text']
555
  if answer_evidence.lower() in evidence.lower():
556
- list_of_evidence_answer_when.append(f"""Evidence{j+1}:{answer_evidence}""")
557
  else:
558
  answer_evidence=""
559
  list_of_evidence_answer_when.append(f"""No mention of 'when'in any related documents.""")
@@ -609,12 +609,12 @@ def gen_qa_where(df):
609
  "min_length": 100,"wait_for_model":True})[0]['generated_text'].capitalize()
610
  question_ids = rephrase_question_where(question_ids)
611
  list_of_ques_where.append(f"""Q{j+1}:{question_ids}""")
612
- list_of_ans_where.append(f"""Ans{j+1}:{answer[j]}""")
613
  input_evidence = f"answer_the_next_question_from_context: {question_ids} context: {evidence}"
614
  time.sleep(5)
615
  answer_evidence = query_evidence({"inputs":input_evidence,"truncation":True,"wait_for_model":True})[0]['generated_text']
616
  if answer_evidence.lower() in evidence.lower():
617
- list_of_evidence_answer_where.append(f"""Evidence{j+1}:{answer_evidence}""")
618
  else:
619
  answer_evidence=""
620
  list_of_evidence_answer_where.append(f"""No mention of 'where'in any related documents.""")
@@ -658,18 +658,88 @@ def gen_qa_where(df):
658
  # # st.write(gen_qa_who(df))
659
  # # st.table(final_df)
660
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
661
  if claim_text and evidence_text:
662
  st.write("You entered: ", claim_text)
663
  st.write("You entered: ", evidence_text)
664
  st.caption(':green[Kindly hold on for a few minutes while the QA pairs are being generated]')
665
  df=claim(claim_text)
666
  df["evidence"]=evidence_text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
667
  final_df = pd.DataFrame(columns=['Who Claims', 'What Claims', 'When Claims', 'Where Claims', 'Why Claims'])
668
- final_df["Who Claims"]=gen_qa_who(df)
669
- final_df["What Claims"]=gen_qa_what(df)
670
- final_df["When Claims"]=gen_qa_when(df)
671
- final_df["Where Claims"]=gen_qa_where(df)
672
- final_df["Why Claims"]=gen_qa_why(df)
 
673
  st.table(final_df)
674
  st.write(df["claim"])
675
- st.write(df["evidence"])
 
 
364
  "early_stopping":True,
365
  "min_length": 100,"wait_for_model":True})[0]['generated_text'].capitalize()
366
  question_ids = rephrase_question_who(question_ids)
367
+ list_of_ques_who.append(f"""Q{j+1} :\n {question_ids}""")
368
+ list_of_ans_who.append(f"""Claim :\n {answer[j]}""")
369
  input_evidence = f"answer_the_next_question_from_context: {question_ids} context: {evidence}"
370
  time.sleep(5)
371
  answer_evidence = query_evidence({"inputs":input_evidence,"truncation":True,"wait_for_model":True})[0]['generated_text']
372
  if answer_evidence.lower() in evidence.lower():
373
+ list_of_evidence_answer_who.append(f"""Answer retrieved from evidence :\n {answer_evidence}""")
374
  else:
375
  answer_evidence=""
376
  list_of_evidence_answer_who.append(f"""No mention of 'who'in any related documents.""")
 
425
  "min_length": 100,"wait_for_model":True})[0]['generated_text'].capitalize()
426
  question_ids = rephrase_question_what(question_ids)
427
  list_of_ques_what.append(f"""Q{j+1}:{question_ids}""")
428
+ list_of_ans_what.append(f"""Claim :\n {answer[j]}""")
429
  input_evidence = f"answer_the_next_question_from_context: {question_ids} context: {evidence}"
430
  time.sleep(5)
431
  answer_evidence = query_evidence({"inputs":input_evidence,"truncation":True,"wait_for_model":True})[0]['generated_text']
432
  if answer_evidence.lower() in evidence.lower():
433
+ list_of_evidence_answer_what.append(f"""Answer retrieved from evidence :\n {answer_evidence}""")
434
 
435
  else:
436
  answer_evidence=""
 
487
  "min_length": 100,"wait_for_model":True})[0]['generated_text'].capitalize()
488
  question_ids = rephrase_question_why(question_ids)
489
  list_of_ques_why.append(f"""Q{j+1}:{question_ids}""")
490
+ list_of_ans_why.append(f"""Claim :\n {answer[j]}""")
491
  input_evidence = f"answer_the_next_question_from_context: {question_ids} context: {evidence}"
492
  time.sleep(5)
493
  answer_evidence = query_evidence({"inputs":input_evidence,"truncation":True,"wait_for_model":True})[0]['generated_text']
494
  if answer_evidence.lower() in evidence.lower():
495
+ list_of_evidence_answer_why.append(f"""Answer retrieved from evidence :\n {answer_evidence}""")
496
  else:
497
  answer_evidence=""
498
  list_of_evidence_answer_why.append(f"""No mention of 'why'in any related documents.""")
 
548
  "min_length": 100,"wait_for_model":True})[0]['generated_text'].capitalize()
549
  question_ids = rephrase_question_when(question_ids)
550
  list_of_ques_when.append(f"""Q{j+1}:{question_ids}""")
551
+ list_of_ans_when.append(f"""Claim :\n {answer[j]}""")
552
  input_evidence = f"answer_the_next_question_from_context: {question_ids} context: {evidence}"
553
  time.sleep(5)
554
  answer_evidence = query_evidence({"inputs":input_evidence,"truncation":True,"wait_for_model":True})[0]['generated_text']
555
  if answer_evidence.lower() in evidence.lower():
556
+ list_of_evidence_answer_when.append(f"""Answer retrieved from evidence :\n {answer_evidence}""")
557
  else:
558
  answer_evidence=""
559
  list_of_evidence_answer_when.append(f"""No mention of 'when'in any related documents.""")
 
609
  "min_length": 100,"wait_for_model":True})[0]['generated_text'].capitalize()
610
  question_ids = rephrase_question_where(question_ids)
611
  list_of_ques_where.append(f"""Q{j+1}:{question_ids}""")
612
+ list_of_ans_where.append(f"""Claim :\n {answer[j]}""")
613
  input_evidence = f"answer_the_next_question_from_context: {question_ids} context: {evidence}"
614
  time.sleep(5)
615
  answer_evidence = query_evidence({"inputs":input_evidence,"truncation":True,"wait_for_model":True})[0]['generated_text']
616
  if answer_evidence.lower() in evidence.lower():
617
+ list_of_evidence_answer_where.append(f"""Answer retrieved from evidence :\n {answer_evidence}""")
618
  else:
619
  answer_evidence=""
620
  list_of_evidence_answer_where.append(f"""No mention of 'where'in any related documents.""")
 
658
  # # st.write(gen_qa_who(df))
659
  # # st.table(final_df)
660
 
661
+ # if claim_text and evidence_text:
662
+ # st.write("You entered: ", claim_text)
663
+ # st.write("You entered: ", evidence_text)
664
+ # st.caption(':green[Kindly hold on for a few minutes while the QA pairs are being generated]')
665
+ # df=claim(claim_text)
666
+ # df["evidence"]=evidence_text
667
+ # final_df = pd.DataFrame(columns=['Who Claims', 'What Claims', 'When Claims', 'Where Claims', 'Why Claims'])
668
+ # final_df["Who Claims"]=gen_qa_who(df)
669
+ # final_df["What Claims"]=gen_qa_what(df)
670
+ # final_df["When Claims"]=gen_qa_when(df)
671
+ # final_df["Where Claims"]=gen_qa_where(df)
672
+ # final_df["Why Claims"]=gen_qa_why(df)
673
+ # st.table(final_df)
674
+ # st.write(df["claim"])
675
+ # st.write(df["evidence"])
676
+
677
  if claim_text and evidence_text:
678
  st.write("You entered: ", claim_text)
679
  st.write("You entered: ", evidence_text)
680
  st.caption(':green[Kindly hold on for a few minutes while the QA pairs are being generated]')
681
  df=claim(claim_text)
682
  df["evidence"]=evidence_text
683
+ lst1=gen_qa_who(df6)
684
+ lst2=gen_qa_what(df6)
685
+ lst3=gen_qa_when(df6)
686
+ lst4=gen_qa_where(df6)
687
+ lst5=gen_qa_why(df6)
688
+
689
+ output1=[]
690
+ if 'No claims' in lst1[0]:
691
+ output1=[item for item in lst1]
692
+ else:
693
+ for i in range(len(lst1[0])):
694
+ output1.append(lst1[0][i])
695
+ output1.append(lst1[1][i])
696
+ output1.append(lst1[2][i])
697
+ output1.append(lst1[3][i])
698
+ output2=[]
699
+ if 'No claims' in lst2[0]:
700
+ output2=[item for item in lst2]
701
+ else:
702
+ for i in range(len(lst2[0])):
703
+ output2.append(lst2[0][i])
704
+ output2.append(lst2[1][i])
705
+ output2.append(lst2[2][i])
706
+ output2.append(lst2[3][i])
707
+ output3=[]
708
+ if 'No claims' in lst3[0]:
709
+ output3=[item for item in lst3]
710
+ else:
711
+ for i in range(len(lst3[0])):
712
+ output3.append(lst3[0][i])
713
+ output3.append(lst3[1][i])
714
+ output3.append(lst3[2][i])
715
+ output3.append(lst3[3][i])
716
+ output4=[]
717
+ if 'No claims' in lst4[0]:
718
+ output4=[item for item in lst4]
719
+ else:
720
+ for i in range(len(lst4[0])):
721
+ output4.append(lst4[0][i])
722
+ output4.append(lst4[1][i])
723
+ output4.append(lst4[2][i])
724
+ output4.append(lst4[3][i])
725
+ output5=[]
726
+ if 'No claims' in lst5[0]:
727
+ output5=[item for item in lst5]
728
+ else:
729
+ for i in range(len(lst5[0])):
730
+ output5.append(lst5[0][i])
731
+ output5.append(lst5[1][i])
732
+ output5.append(lst5[2][i])
733
+ output5.append(lst5[3][i])
734
+ max_rows = max(len(output1), len(output2), len(output3), len(output4), len(output5))
735
  final_df = pd.DataFrame(columns=['Who Claims', 'What Claims', 'When Claims', 'Where Claims', 'Why Claims'])
736
+ # add the data to the dataframe
737
+ final_df['Who Claims'] = output1 + [''] * (max_rows - len(output1))
738
+ final_df['What Claims'] = output2 + [''] * (max_rows - len(output2))
739
+ final_df['When Claims'] = output3 + [''] * (max_rows - len(output3))
740
+ final_df['Where Claims'] = output4 + [''] * (max_rows - len(output4))
741
+ final_df['Why Claims'] = output5 + [''] * (max_rows - len(output5))
742
  st.table(final_df)
743
  st.write(df["claim"])
744
+ st.write(df["evidence"])
745
+