vkumartr commited on
Commit
be66b8a
·
verified ·
1 Parent(s): 9734810

Stores in MongoDB

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -219,13 +219,26 @@ def ocr_from_s3(
219
  # Summarize the extracted text
220
  summary = summarize_text(full_text)
221
 
222
- return {
 
223
  "file_key": file_key,
224
  "file_type": content_type,
225
  "document_type": document_type,
226
  "entity_ref_key": entity_ref_key,
227
  "base64DataResp": base64DataResp,
228
  "extracted_text": full_text,
 
 
 
 
 
 
 
 
 
 
 
 
229
  "summary": summary
230
  }
231
 
 
219
  # Summarize the extracted text
220
  summary = summarize_text(full_text)
221
 
222
+ # Document structure for MongoDB
223
+ document = {
224
  "file_key": file_key,
225
  "file_type": content_type,
226
  "document_type": document_type,
227
  "entity_ref_key": entity_ref_key,
228
  "base64DataResp": base64DataResp,
229
  "extracted_text": full_text,
230
+ "summary": summary,
231
+ "created_at": datetime.utcnow()
232
+ }
233
+
234
+ # Insert into MongoDB
235
+ inserted_doc = invoice_collection.insert_one(document)
236
+ document_id = str(inserted_doc.inserted_id) # Convert ObjectId to string
237
+
238
+ return {
239
+ "message": "Document successfully stored in MongoDB",
240
+ "document_id": document_id,
241
+ "file_key": file_key,
242
  "summary": summary
243
  }
244