Prasada commited on
Commit
5e4f057
·
verified ·
1 Parent(s): 6a83e83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -7
app.py CHANGED
@@ -1,5 +1,5 @@
1
- import cv2
2
  import os
 
3
  import numpy as np
4
  from PIL import Image, ImageDraw, ImageFont
5
  import json
@@ -114,22 +114,19 @@ def process_image(image):
114
 
115
  # Convert OCR results to JSON
116
  json_results = convert_to_json(ocr_results[0])
117
- json_results_path = os.path.join(UPLOAD_DIR, 'ocr_results.json')
118
  with open(json_results_path, "w") as f:
119
  json.dump(json_results, f, indent=4)
120
 
121
  # Extract field-value pairs from the text
122
  text = " ".join([result[1][0] for result in ocr_results[0]])
123
  field_value_pairs = extract_field_value_pairs(text)
124
- field_value_pairs_path = os.path.join(UPLOAD_DIR, 'extracted_fields.json')
125
  with open(field_value_pairs_path, "w") as f:
126
  json.dump(field_value_pairs, f, indent=4)
127
 
128
  return image_with_boxes, json_results_path, field_value_pairs_path
129
 
130
- # Define Gradio interface
131
- import gradio as gr
132
-
133
  # Define Gradio interface
134
  iface = gr.Interface(
135
  fn=process_image,
@@ -143,4 +140,4 @@ iface = gr.Interface(
143
  )
144
 
145
  if __name__ == "__main__":
146
- iface.launch()
 
 
1
  import os
2
+ import cv2
3
  import numpy as np
4
  from PIL import Image, ImageDraw, ImageFont
5
  import json
 
114
 
115
  # Convert OCR results to JSON
116
  json_results = convert_to_json(ocr_results[0])
117
+ json_results_path = os.path.join("/app", 'ocr_results.json')
118
  with open(json_results_path, "w") as f:
119
  json.dump(json_results, f, indent=4)
120
 
121
  # Extract field-value pairs from the text
122
  text = " ".join([result[1][0] for result in ocr_results[0]])
123
  field_value_pairs = extract_field_value_pairs(text)
124
+ field_value_pairs_path = os.path.join("/app", 'extracted_fields.json')
125
  with open(field_value_pairs_path, "w") as f:
126
  json.dump(field_value_pairs, f, indent=4)
127
 
128
  return image_with_boxes, json_results_path, field_value_pairs_path
129
 
 
 
 
130
  # Define Gradio interface
131
  iface = gr.Interface(
132
  fn=process_image,
 
140
  )
141
 
142
  if __name__ == "__main__":
143
+ iface.launch()