Towhidul commited on
Commit
6a0831e
β€’
1 Parent(s): d39b7f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -27
app.py CHANGED
@@ -4,9 +4,9 @@ import re
4
  import time
5
  import requests
6
 
7
- if "visibility" not in st.session_state:
8
- st.session_state.visibility = "visible"
9
- st.session_state.disabled = False
10
 
11
 
12
  HF_SPACES_API_KEY = st.secrets["HF_token"]
@@ -75,16 +75,16 @@ def proc():
75
 
76
  # st.text_area('enter text', on_change=proc, key='text_key')
77
 
78
- claim_text = st.text_input(
79
- "Enter your claim πŸ‘‡",
80
- label_visibility="visible",
81
- # placeholder=st.session_state.placeholder,
82
- )
83
 
84
- if claim_text:
85
- st.write("You entered: ", claim_text)
86
 
87
- # claim_text=st.text_area("Enter your claim:", on_change=proc, key='text_key')
88
 
89
  # form_claim = st.form(key='my_claim')
90
  # form_claim.text_input(label='Enter your claim')
@@ -92,21 +92,21 @@ if claim_text:
92
 
93
 
94
 
95
- evidence_text = st.text_input(
96
- "Enter your evidence πŸ‘‡",
97
- label_visibility="visible",
98
- # disabled=st.session_state.disabled,
99
- # placeholder=st.session_state.placeholder,
100
- )
101
 
102
- if evidence_text:
103
- st.write("You entered: ", evidence_text)
104
 
105
  # evidence_text=st.text_area("Enter your evidence:")
106
 
107
- # form_evidence = st.form(key='my_evidence')
108
- # form_evidence.text_input(label='Enter your evidence')
109
- # evidence_text = form_evidence.form_submit_button(label='Submit')
110
 
111
  if evidence_text:
112
  st.caption(':green[Kindly hold on for a few minutes while the QA pairs are being generated]')
@@ -122,6 +122,7 @@ predictor = Predictor.from_path("structured-prediction-srl-bert.tar.gz")
122
 
123
  #---------------------------------------------------------------
124
  #---------------------------------------------------------------
 
125
  def claim(text):
126
  import re
127
  def remove_special_chars(text):
@@ -328,6 +329,7 @@ def claim(text):
328
  data=df[["claim","who","what","why","when","where"]].copy()
329
  return data
330
  #-------------------------------------------------------------------------
 
331
  def split_ws(input_list, delimiter="<sep>"):
332
  output_list = []
333
  for item in input_list:
@@ -339,13 +341,14 @@ def split_ws(input_list, delimiter="<sep>"):
339
  return output_list
340
 
341
  #--------------------------------------------------------------------------
 
342
  def calc_rouge_l_score(list_of_evidence, list_of_ans):
343
  scorer = rouge_scorer.RougeScorer(['rougeL'], use_stemmer=True)
344
  scores = scorer.score(' '.join(list_of_evidence), ' '.join(list_of_ans))
345
  return scores['rougeL'].fmeasure
346
  #-------------------------------------------------------------------------
347
 
348
-
349
  def rephrase_question_who(question):
350
  if not question.lower().startswith("who"):
351
  words = question.split()
@@ -354,6 +357,7 @@ def rephrase_question_who(question):
354
  else:
355
  return question
356
  #------------------------------------------------------------------------
 
357
  def gen_qa_who(df):
358
  list_of_ques_who=[]
359
  list_of_ans_who=[]
@@ -405,7 +409,7 @@ def gen_qa_who(df):
405
  rouge_l_scores="Not verifiable"
406
  return list_of_ques_who,list_of_ans_who,rouge_l_scores,list_of_evidence_answer_who
407
  #------------------------------------------------------------
408
-
409
  def rephrase_question_what(question):
410
  if not question.lower().startswith("what"):
411
  words = question.split()
@@ -414,6 +418,7 @@ def rephrase_question_what(question):
414
  else:
415
  return question
416
  #----------------------------------------------------------
 
417
  def gen_qa_what(df):
418
  list_of_ques_what=[]
419
  list_of_ans_what=[]
@@ -465,7 +470,7 @@ def gen_qa_what(df):
465
  rouge_l_scores="Not verifiable"
466
  return list_of_ques_what,list_of_ans_what,rouge_l_scores,list_of_evidence_answer_what
467
  #----------------------------------------------------------
468
-
469
  def rephrase_question_why(question):
470
  if not question.lower().startswith("why"):
471
  words = question.split()
@@ -475,6 +480,7 @@ def rephrase_question_why(question):
475
  return question
476
 
477
  #---------------------------------------------------------
 
478
  def gen_qa_why(df):
479
  list_of_ques_why=[]
480
  list_of_ans_why=[]
@@ -526,7 +532,7 @@ def gen_qa_why(df):
526
  return list_of_ques_why,list_of_ans_why,rouge_l_scores,list_of_evidence_answer_why
527
 
528
  #---------------------------------------------------------
529
-
530
  def rephrase_question_when(question):
531
  if not question.lower().startswith("when"):
532
  words = question.split()
@@ -535,6 +541,7 @@ def rephrase_question_when(question):
535
  else:
536
  return question
537
  #---------------------------------------------------------
 
538
  def gen_qa_when(df):
539
  list_of_ques_when=[]
540
  list_of_ans_when=[]
@@ -586,7 +593,7 @@ def gen_qa_when(df):
586
  return list_of_ques_when,list_of_ans_when,rouge_l_scores,list_of_evidence_answer_when
587
 
588
  #------------------------------------------------------
589
-
590
  def rephrase_question_where(question):
591
  if not question.lower().startswith("where"):
592
  words = question.split()
@@ -595,6 +602,7 @@ def rephrase_question_where(question):
595
  else:
596
  return question
597
  #------------------------------------------------------
 
598
  def gen_qa_where(df):
599
  list_of_ques_where=[]
600
  list_of_ans_where=[]
 
4
  import time
5
  import requests
6
 
7
+ # if "visibility" not in st.session_state:
8
+ # st.session_state.visibility = "visible"
9
+ # st.session_state.disabled = False
10
 
11
 
12
  HF_SPACES_API_KEY = st.secrets["HF_token"]
 
75
 
76
  # st.text_area('enter text', on_change=proc, key='text_key')
77
 
78
+ # claim_text = st.text_input(
79
+ # "Enter your claim πŸ‘‡",
80
+ # label_visibility="visible",
81
+ # # placeholder=st.session_state.placeholder,
82
+ # )
83
 
84
+ # if claim_text:
85
+ # st.write("You entered: ", claim_text)
86
 
87
+ claim_text=st.text_area("Enter your claim:", on_change=proc, key='text_key')
88
 
89
  # form_claim = st.form(key='my_claim')
90
  # form_claim.text_input(label='Enter your claim')
 
92
 
93
 
94
 
95
+ # evidence_text = st.text_input(
96
+ # "Enter your evidence πŸ‘‡",
97
+ # label_visibility="visible",
98
+ # # disabled=st.session_state.disabled,
99
+ # # placeholder=st.session_state.placeholder,
100
+ # )
101
 
102
+ # if evidence_text:
103
+ # st.write("You entered: ", evidence_text)
104
 
105
  # evidence_text=st.text_area("Enter your evidence:")
106
 
107
+ form_evidence = st.form(key='my_evidence')
108
+ form_evidence.text_input(label='Enter your evidence')
109
+ evidence_text = form_evidence.form_submit_button(label='Submit')
110
 
111
  if evidence_text:
112
  st.caption(':green[Kindly hold on for a few minutes while the QA pairs are being generated]')
 
122
 
123
  #---------------------------------------------------------------
124
  #---------------------------------------------------------------
125
+ @st.cache
126
  def claim(text):
127
  import re
128
  def remove_special_chars(text):
 
329
  data=df[["claim","who","what","why","when","where"]].copy()
330
  return data
331
  #-------------------------------------------------------------------------
332
+ @st.cache
333
  def split_ws(input_list, delimiter="<sep>"):
334
  output_list = []
335
  for item in input_list:
 
341
  return output_list
342
 
343
  #--------------------------------------------------------------------------
344
+ @st.cache
345
  def calc_rouge_l_score(list_of_evidence, list_of_ans):
346
  scorer = rouge_scorer.RougeScorer(['rougeL'], use_stemmer=True)
347
  scores = scorer.score(' '.join(list_of_evidence), ' '.join(list_of_ans))
348
  return scores['rougeL'].fmeasure
349
  #-------------------------------------------------------------------------
350
 
351
+ @st.cache
352
  def rephrase_question_who(question):
353
  if not question.lower().startswith("who"):
354
  words = question.split()
 
357
  else:
358
  return question
359
  #------------------------------------------------------------------------
360
+ @st.cache
361
  def gen_qa_who(df):
362
  list_of_ques_who=[]
363
  list_of_ans_who=[]
 
409
  rouge_l_scores="Not verifiable"
410
  return list_of_ques_who,list_of_ans_who,rouge_l_scores,list_of_evidence_answer_who
411
  #------------------------------------------------------------
412
+ @st.cache
413
  def rephrase_question_what(question):
414
  if not question.lower().startswith("what"):
415
  words = question.split()
 
418
  else:
419
  return question
420
  #----------------------------------------------------------
421
+ @st.cache
422
  def gen_qa_what(df):
423
  list_of_ques_what=[]
424
  list_of_ans_what=[]
 
470
  rouge_l_scores="Not verifiable"
471
  return list_of_ques_what,list_of_ans_what,rouge_l_scores,list_of_evidence_answer_what
472
  #----------------------------------------------------------
473
+ @st.cache
474
  def rephrase_question_why(question):
475
  if not question.lower().startswith("why"):
476
  words = question.split()
 
480
  return question
481
 
482
  #---------------------------------------------------------
483
+ @st.cache
484
  def gen_qa_why(df):
485
  list_of_ques_why=[]
486
  list_of_ans_why=[]
 
532
  return list_of_ques_why,list_of_ans_why,rouge_l_scores,list_of_evidence_answer_why
533
 
534
  #---------------------------------------------------------
535
+ @st.cache
536
  def rephrase_question_when(question):
537
  if not question.lower().startswith("when"):
538
  words = question.split()
 
541
  else:
542
  return question
543
  #---------------------------------------------------------
544
+ @st.cache
545
  def gen_qa_when(df):
546
  list_of_ques_when=[]
547
  list_of_ans_when=[]
 
593
  return list_of_ques_when,list_of_ans_when,rouge_l_scores,list_of_evidence_answer_when
594
 
595
  #------------------------------------------------------
596
+ @st.cache
597
  def rephrase_question_where(question):
598
  if not question.lower().startswith("where"):
599
  words = question.split()
 
602
  else:
603
  return question
604
  #------------------------------------------------------
605
+ @st.cache
606
  def gen_qa_where(df):
607
  list_of_ques_where=[]
608
  list_of_ans_where=[]