Prasada commited on
Commit
ac5b07c
1 Parent(s): ff0c58a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -113,20 +113,33 @@ def process_image(image):
113
 
114
  # Convert OCR results to JSON
115
  json_results = convert_to_json(ocr_results[0])
 
 
 
116
 
117
  # Extract field-value pairs from the text
118
  text = " ".join([result[1][0] for result in ocr_results[0]])
119
  field_value_pairs = extract_field_value_pairs(text)
 
 
 
120
 
121
- return image_with_boxes, json_results, field_value_pairs
 
 
 
122
 
123
  # Define Gradio interface
124
  iface = gr.Interface(
125
  fn=process_image,
126
  inputs=gr.Image(type="pil"),
127
- outputs=[gr.Image(type="pil"), gr.JSON(), gr.JSON()],
 
 
 
 
128
  live=True
129
  )
130
 
131
  if __name__ == "__main__":
132
- iface.launch()
 
113
 
114
  # Convert OCR results to JSON
115
  json_results = convert_to_json(ocr_results[0])
116
+ json_results_path = os.path.join(UPLOAD_DIR, 'ocr_results.json')
117
+ with open(json_results_path, "w") as f:
118
+ json.dump(json_results, f, indent=4)
119
 
120
  # Extract field-value pairs from the text
121
  text = " ".join([result[1][0] for result in ocr_results[0]])
122
  field_value_pairs = extract_field_value_pairs(text)
123
+ field_value_pairs_path = os.path.join(UPLOAD_DIR, 'extracted_fields.json')
124
+ with open(field_value_pairs_path, "w") as f:
125
+ json.dump(field_value_pairs, f, indent=4)
126
 
127
+ return image_with_boxes, json_results_path, field_value_pairs_path
128
+
129
+ # Define Gradio interface
130
+ import gradio as gr
131
 
132
  # Define Gradio interface
133
  iface = gr.Interface(
134
  fn=process_image,
135
  inputs=gr.Image(type="pil"),
136
+ outputs=[
137
+ gr.Image(type="pil"),
138
+ gr.File(label="Download OCR Results"),
139
+ gr.File(label="Download Extracted Fields")
140
+ ],
141
  live=True
142
  )
143
 
144
  if __name__ == "__main__":
145
+ iface.launch()