Sage commited on
Commit
63b8543
1 Parent(s): 569d9bc

JSON and Kill switch

Browse files
Files changed (1) hide show
  1. app.py +28 -4
app.py CHANGED
@@ -262,6 +262,19 @@ def save_json(text, filename):
262
  json.dump(text, outfile, ensure_ascii=False)
263
  return filename
264
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
  with gr.Blocks(title="Axon OCR", css=".markdown {text-align: center;}") as app:
266
  gr.Markdown("""# Axon OCR
267
  Attach Images or Files below and convert them to Text.""", elem_classes="markdown")
@@ -289,13 +302,24 @@ with gr.Blocks(title="Axon OCR", css=".markdown {text-align: center;}") as app:
289
  gr.Textbox(label="Any additional information? (Optional)", placeholder="This is document is an Official Reciept")]
290
  batch_document_output = gr.File(label="Result")
291
  batch_document_button = gr.Button("Scan")
292
- retry_button = gr.Button("Retry Unprocessed Documents", label="Retry")
293
-
294
-
 
 
 
 
 
 
 
 
 
295
  image_button.click(image, inputs=image_input, outputs=image_output)
296
  document_button.click(document, inputs=document_input, outputs=document_output)
297
- batch_document_button.click(batch_document, inputs=batch_document_input, outputs=batch_document_output)
298
  retry_button.click(retry_unprocessed_documents, outputs=batch_document_output)
 
 
299
 
300
  app.queue()
301
  app.launch(auth=("username", "password"))
 
262
  json.dump(text, outfile, ensure_ascii=False)
263
  return filename
264
 
265
+ def combine_json_files(json_files, progress=gr.Progress()):
266
+ combined_data = []
267
+ progress(0, desc="Starting")
268
+ for file in progress.tqdm(json_files, desc="Combining JSON Files"):
269
+ with open(file.name, 'r') as json_file:
270
+ data = json.load(json_file)
271
+ combined_data.extend(data)
272
+ # Convert the combined_data dict back to a JSON string
273
+ # You might want to save this to a file and return the file,
274
+ # or return the JSON string directly
275
+ logging.info("Combined JSON File: ", combined_data)
276
+ return save_json(combined_data, "Combined Json")
277
+
278
  with gr.Blocks(title="Axon OCR", css=".markdown {text-align: center;}") as app:
279
  gr.Markdown("""# Axon OCR
280
  Attach Images or Files below and convert them to Text.""", elem_classes="markdown")
 
302
  gr.Textbox(label="Any additional information? (Optional)", placeholder="This is document is an Official Reciept")]
303
  batch_document_output = gr.File(label="Result")
304
  batch_document_button = gr.Button("Scan")
305
+ with gr.Row():
306
+ with gr.Column():
307
+ retry_button = gr.Button("Retry Unprocessed Documents", label="Retry")
308
+ with gr.Column():
309
+ stop_button = gr.Button("Stop Processing Document", label="Stop")
310
+ with gr.Tab("Combine JSON"):
311
+ with gr.Row():
312
+ with gr.Column():
313
+ json_files_input = gr.File(file_types=[".json"], file_count="multiple", label='Upload JSON files')
314
+ combined_json_output = gr.File(label="Result")
315
+ combine_button = gr.Button('Combine JSON files')
316
+
317
  image_button.click(image, inputs=image_input, outputs=image_output)
318
  document_button.click(document, inputs=document_input, outputs=document_output)
319
+ batch_document_event = batch_document_button.click(batch_document, inputs=batch_document_input, outputs=batch_document_output)
320
  retry_button.click(retry_unprocessed_documents, outputs=batch_document_output)
321
+ stop_button.click(fn=None, inputs=None, outputs=None, cancels=[batch_document_event])
322
+ combine_button.click(combine_json_files, inputs=json_files_input, outputs=combined_json_output)
323
 
324
  app.queue()
325
  app.launch(auth=("username", "password"))