credent007 commited on
Commit
d501a2d
·
verified ·
1 Parent(s): b9a0250

Update json_handling.py

Browse files
Files changed (1) hide show
  1. json_handling.py +32 -18
json_handling.py CHANGED
@@ -34,28 +34,42 @@ import json
34
 
35
  def process_whole_doc(file_path):
36
  images = load_input(file_path)
37
-
38
- complete_json = ""
39
-
40
 
41
- # PART_NAME = "PART-1 - BILL OF ENTRY SUMMARY" # you can change per doc type
42
- for i, image in enumerate(images, start=1):
43
- partial_json = process_document(image)
44
- # print(partial_json)
45
- complete_json = complete_json+partial_json
46
- # # 🔹 Extract only "result"
47
- # result_data = partial_json.get("result", {})
48
- # page_key = f"Page {i}"
49
- # Ensure structure exists
50
- # # if PART_NAME not in complete_json:
51
- # complete_json[] = [{}]
52
 
53
- # if not complete_json[PART_NAME]:
54
- # complete_json[PART_NAME].append({})
55
 
56
- # Merge directly
57
- # complete_json[page_key]=result_data
 
 
 
 
58
 
59
  return complete_json
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
 
 
34
 
35
  def process_whole_doc(file_path):
36
  images = load_input(file_path)
 
 
 
37
 
38
+ complete_json = "["
39
+ first = True
 
 
 
 
 
 
 
 
 
40
 
41
+ for image in images:
42
+ partial_json = process_document(image) # returns string
43
 
44
+ if not first:
45
+ complete_json += ","
46
+ complete_json += partial_json
47
+ first = False
48
+
49
+ complete_json += "]"
50
 
51
  return complete_json
52
+ # complete_json = ""
53
+
54
+
55
+ # # PART_NAME = "PART-1 - BILL OF ENTRY SUMMARY" # you can change per doc type
56
+ # for i, image in enumerate(images, start=1):
57
+ # partial_json = process_document(image)
58
+ # # print(partial_json)
59
+ # complete_json = complete_json+partial_json
60
+ # # # 🔹 Extract only "result"
61
+ # # result_data = partial_json.get("result", {})
62
+ # # page_key = f"Page {i}"
63
+ # # Ensure structure exists
64
+ # # # if PART_NAME not in complete_json:
65
+ # # complete_json[] = [{}]
66
+
67
+ # # if not complete_json[PART_NAME]:
68
+ # # complete_json[PART_NAME].append({})
69
+
70
+ # # ✅ Merge directly
71
+ # # complete_json[page_key]=result_data
72
+
73
+ # return complete_json
74
 
75