ankur-bohra commited on
Commit
52cab32
1 Parent(s): 924cad9

Add more logs

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -80,23 +80,27 @@ def submit(input_file, old_text):
80
  if not input_file:
81
  gr.Error("Please upload a file to continue!")
82
  return gr.Textbox.update()
83
-
 
84
  # Send change to preprocessed image or to extracted text
85
  if input_file.name.endswith(".pdf"):
86
  text = process_pdf(Path(input_file.name), extract_only=True)
87
  else:
88
  text = process_image(Path(input_file.name), extract_only=True)
 
89
  return text
90
 
91
 
92
  def categorize_extracted_text(extracted_text):
93
  category = categories.categorize_text(extracted_text)
 
94
  # gr.Info(f"Recognized category: {category}")
95
  return category
96
 
97
 
98
- def extract_from_category(category, extracted_text):
99
  if not category:
 
100
  return (
101
  gr.Chatbot.update(None),
102
  gr.JSON.update(None),
@@ -104,7 +108,7 @@ def extract_from_category(category, extracted_text):
104
  gr.Button.update(interactive=False),
105
  )
106
  category = Category[category]
107
- print("Extracting text from", category)
108
  chain = categories.category_modules[category].chain
109
  formatted_prompt = chain.prompt.format_prompt(
110
  text=extracted_text,
@@ -122,7 +126,9 @@ def extract_from_category(category, extracted_text):
122
  if len(formatted_prompt.messages) > 1:
123
  question += f"**System:**\n{formatted_prompt.messages[1].content}"
124
  question += f"\n\n**Human:**\n{formatted_prompt.messages[0].content}"
 
125
  answer = result.generations[0][0].text
 
126
  try:
127
  information = chain.output_parser.parse_with_prompt(answer, formatted_prompt)
128
  information = information.json() if information else {}
@@ -276,7 +282,7 @@ with gr.Blocks(title="Automatic Reimbursement Tool Demo") as page:
276
  [category],
277
  )
278
  category.change(
279
- extract_from_category,
280
  [category, extracted_text],
281
  [chatbot, information, flag_incorrect_button, flag_irrelevant_button],
282
  )
 
80
  if not input_file:
81
  gr.Error("Please upload a file to continue!")
82
  return gr.Textbox.update()
83
+ print("-"*5)
84
+ print("New input")
85
  # Send change to preprocessed image or to extracted text
86
  if input_file.name.endswith(".pdf"):
87
  text = process_pdf(Path(input_file.name), extract_only=True)
88
  else:
89
  text = process_image(Path(input_file.name), extract_only=True)
90
+ print("Extracted text")
91
  return text
92
 
93
 
94
  def categorize_extracted_text(extracted_text):
95
  category = categories.categorize_text(extracted_text)
96
+ print("Recognized category:", category)
97
  # gr.Info(f"Recognized category: {category}")
98
  return category
99
 
100
 
101
+ def parse_from_category(category, extracted_text):
102
  if not category:
103
+ print("Updated with no category:", category)
104
  return (
105
  gr.Chatbot.update(None),
106
  gr.JSON.update(None),
 
108
  gr.Button.update(interactive=False),
109
  )
110
  category = Category[category]
111
+ print("Parsing text from", category)
112
  chain = categories.category_modules[category].chain
113
  formatted_prompt = chain.prompt.format_prompt(
114
  text=extracted_text,
 
126
  if len(formatted_prompt.messages) > 1:
127
  question += f"**System:**\n{formatted_prompt.messages[1].content}"
128
  question += f"\n\n**Human:**\n{formatted_prompt.messages[0].content}"
129
+ print("\tConstructed prompt")
130
  answer = result.generations[0][0].text
131
+ print("\tProcessed text")
132
  try:
133
  information = chain.output_parser.parse_with_prompt(answer, formatted_prompt)
134
  information = information.json() if information else {}
 
282
  [category],
283
  )
284
  category.change(
285
+ parse_from_category,
286
  [category, extracted_text],
287
  [chatbot, information, flag_incorrect_button, flag_irrelevant_button],
288
  )