qq1023 commited on
Commit
00ca9a0
·
1 Parent(s): 768fc67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -19
app.py CHANGED
@@ -169,6 +169,27 @@ def flag_if_shared(flag_method):
169
  return flag_method(request, *args, **kwargs)
170
  return proxy
171
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
 
173
  with gr.Blocks(title="Automatic Reimbursement Tool Demo") as page:
174
  gr.Markdown("<center><h1>Automatic Reimbursement Tool Demo</h1></center>")
@@ -197,7 +218,7 @@ with gr.Blocks(title="Automatic Reimbursement Tool Demo") as page:
197
  label="Input receipt",
198
  show_label=True,
199
  type="file",
200
- file_count="single",
201
  file_types=["image", ".pdf"],
202
  )
203
  input_file.change(
@@ -295,26 +316,9 @@ with gr.Blocks(title="Automatic Reimbursement Tool Demo") as page:
295
  [input_file],
296
  [extracted_text, category, chatbot, information],
297
  ).then(
298
- extract_text,
299
  [input_file],
300
- [extracted_text],
301
- ).then(
302
- categorize_text,
303
- [extracted_text],
304
- [category],
305
- ).then(
306
- query,
307
- [category, extracted_text],
308
- [chatbot],
309
- queue=True,
310
- ).then(
311
- parse,
312
- [category, chatbot],
313
  [information],
314
- ).then(
315
- activate_flags,
316
- None,
317
- [flag_incorrect_button, flag_irrelevant_button],
318
  ).then(
319
  flag_if_shared(flag_method),
320
  [
 
169
  return flag_method(request, *args, **kwargs)
170
  return proxy
171
 
172
+ def process_and_output_files(input_files):
173
+ output_data = []
174
+
175
+ for file in input_files:
176
+ # Extract and categorize text for each file
177
+ text = extract_text(file)
178
+ category = categorize_text(text)
179
+ chatbot_response = query(category, text)
180
+ parsed_info = parse(category, chatbot_response)
181
+
182
+ # Append the relevant data for this file to the output_data list
183
+ output_data.append({
184
+ "File Name": file.name,
185
+ "Extracted Text": text,
186
+ "Category": category,
187
+ "Chatbot Response": chatbot_response[0][1],
188
+ "Parsed Information": parsed_info,
189
+ })
190
+
191
+ return output_data
192
+
193
 
194
  with gr.Blocks(title="Automatic Reimbursement Tool Demo") as page:
195
  gr.Markdown("<center><h1>Automatic Reimbursement Tool Demo</h1></center>")
 
218
  label="Input receipt",
219
  show_label=True,
220
  type="file",
221
+ file_count="multiple",
222
  file_types=["image", ".pdf"],
223
  )
224
  input_file.change(
 
316
  [input_file],
317
  [extracted_text, category, chatbot, information],
318
  ).then(
319
+ process_and_output_files,
320
  [input_file],
 
 
 
 
 
 
 
 
 
 
 
 
 
321
  [information],
 
 
 
 
322
  ).then(
323
  flag_if_shared(flag_method),
324
  [