samarthagarwal23 commited on
Commit
c010f14
1 Parent(s): 8af8a15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -70,8 +70,10 @@ def cstr_break(s, color='black'):
70
 
71
  def print_colored(text, start_idx, end_idx, confidence):
72
  conf_str = 'Confidence: ' + confidence
73
- a = cstr_break(' '.join([cstr(' '.join([text[:start_idx], cstr_bold(text[start_idx:end_idx], color='red'), text[end_idx:]]), color='black'), conf_str]))
74
- #a = colored(text[:start_idx]) + colored(text[start_idx:end_idx], 'red', 'on_yellow') + colored(text[end_idx:])
 
 
75
  return a
76
 
77
  def final_qa_pipeline(file, query):
@@ -95,7 +97,7 @@ def final_qa_pipeline(file, query):
95
  # print_colored(fnl_['doc'], fnl_['start'], fnl_['end'])
96
  # print(colored("Confidence score of ") + colored(str(fnl_['score'])[:4], attrs=['bold']))
97
  else:
98
- return ("No match", "0")
99
 
100
  examples = [
101
  [os.path.abspath("dbs-annual-report-2020.pdf"), "how much dividend was paid to shareholders ?"],
@@ -109,7 +111,7 @@ examples = [
109
  iface = gr.Interface(
110
  fn = final_qa_pipeline,
111
  inputs = [gr.inputs.File(label="input pdf file"), gr.inputs.Textbox(label="Question:")],
112
- outputs = [gr.outputs.HTML(label="Predicted answer"), gr.outputs.Textbox(label="Confidence") ],
113
  examples=examples,
114
  title = "Question Answering on company annual reports",
115
  description = "Navigate long annual reports by using Machine learning to answer your questions. \nSimply upload any annual report pdf you are interested in and ask model a question OR load an example from below."
 
70
 
71
  def print_colored(text, start_idx, end_idx, confidence):
72
  conf_str = 'Confidence: ' + confidence
73
+ a = cstr(' '.join([text[:start_idx], \
74
+ cstr_bold(text[start_idx:end_idx], color='red'), \
75
+ text[end_idx:], \
76
+ cstr_break(conf_str, color='yellow')]), color='black')
77
  return a
78
 
79
  def final_qa_pipeline(file, query):
 
97
  # print_colored(fnl_['doc'], fnl_['start'], fnl_['end'])
98
  # print(colored("Confidence score of ") + colored(str(fnl_['score'])[:4], attrs=['bold']))
99
  else:
100
+ return ("No match")
101
 
102
  examples = [
103
  [os.path.abspath("dbs-annual-report-2020.pdf"), "how much dividend was paid to shareholders ?"],
 
111
  iface = gr.Interface(
112
  fn = final_qa_pipeline,
113
  inputs = [gr.inputs.File(label="input pdf file"), gr.inputs.Textbox(label="Question:")],
114
+ outputs = [gr.outputs.HTML(label="Predicted answer")],
115
  examples=examples,
116
  title = "Question Answering on company annual reports",
117
  description = "Navigate long annual reports by using Machine learning to answer your questions. \nSimply upload any annual report pdf you are interested in and ask model a question OR load an example from below."