vkumartr commited on
Commit
ffcb9c3
·
verified ·
1 Parent(s): 22f1d1e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -176,7 +176,9 @@ def extract_text_from_file(
176
  if not schema_doc:
177
  raise ValueError("No schema found for the given document type")
178
 
179
- json_schema = schema_doc.get("json_schema")
 
 
180
 
181
  # Retrieve file from S3 and determine content type
182
  content_type = get_content_type_from_s3(file_key)
@@ -194,8 +196,14 @@ def extract_text_from_file(
194
  "extracted_data": extracted_data
195
  }
196
 
197
- inserted_doc = invoice_collection.insert_one(document)
198
- document_id = str(inserted_doc.inserted_id)
 
 
 
 
 
 
199
 
200
  return {
201
  "message": "Document successfully stored in MongoDB",
 
176
  if not schema_doc:
177
  raise ValueError("No schema found for the given document type")
178
 
179
+ json_schema = schema_doc.get("json_schema")
180
+ if not json_schema:
181
+ raise ValueError("Schema is empty or not properly defined.")
182
 
183
  # Retrieve file from S3 and determine content type
184
  content_type = get_content_type_from_s3(file_key)
 
196
  "extracted_data": extracted_data
197
  }
198
 
199
+ # Insert document into MongoDB
200
+ try:
201
+ inserted_doc = invoice_collection.insert_one(document)
202
+ document_id = str(inserted_doc.inserted_id)
203
+ logger.info(f"Document inserted with ID: {document_id}")
204
+ except Exception as e:
205
+ logger.error(f"Error inserting document: {str(e)}")
206
+ raise HTTPException(status_code=500, detail="Error inserting document into MongoDB")
207
 
208
  return {
209
  "message": "Document successfully stored in MongoDB",