Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import uvicorn
|
| 2 |
from fastapi.staticfiles import StaticFiles
|
| 3 |
import hashlib
|
| 4 |
-
from enum import Enum
|
| 5 |
from fastapi import FastAPI, Header, Query, Depends, HTTPException
|
| 6 |
from PIL import Image
|
| 7 |
import io
|
|
@@ -92,7 +91,7 @@ def extract_invoice_data(file_data, content_type):
|
|
| 92 |
if content_type.startswith("image/"):
|
| 93 |
mime_type = content_type # e.g., image/png, image/jpeg
|
| 94 |
elif content_type == "application/pdf":
|
| 95 |
-
mime_type =
|
| 96 |
else:
|
| 97 |
raise ValueError(f"Unsupported content type: {content_type}")
|
| 98 |
|
|
@@ -230,15 +229,6 @@ def extract_invoice_data(file_data, content_type):
|
|
| 230 |
logger.error(f"Error in data extraction: {e}")
|
| 231 |
return {"error": str(e)}
|
| 232 |
|
| 233 |
-
# def extract_text_from_s3(file_key, content_type):
|
| 234 |
-
# return "Extracted text from file", 1 # Placeholder for real extraction logic
|
| 235 |
-
|
| 236 |
-
# def convert_to_base64(file_key):
|
| 237 |
-
# return "Base64 encoded data" # Placeholder
|
| 238 |
-
|
| 239 |
-
# def generate_summary(extracted_text):
|
| 240 |
-
# return "Summarized text" # Placeholder
|
| 241 |
-
|
| 242 |
def get_content_type_from_s3(file_key):
|
| 243 |
"""Fetch the content type (MIME type) of a file stored in S3."""
|
| 244 |
try:
|
|
@@ -297,6 +287,7 @@ def extract_text_from_file(
|
|
| 297 |
return {
|
| 298 |
"message": "Document successfully stored in MongoDB",
|
| 299 |
"document_id": document_id,
|
|
|
|
| 300 |
"extracted_data": extracted_data
|
| 301 |
}
|
| 302 |
|
|
|
|
| 1 |
import uvicorn
|
| 2 |
from fastapi.staticfiles import StaticFiles
|
| 3 |
import hashlib
|
|
|
|
| 4 |
from fastapi import FastAPI, Header, Query, Depends, HTTPException
|
| 5 |
from PIL import Image
|
| 6 |
import io
|
|
|
|
| 91 |
if content_type.startswith("image/"):
|
| 92 |
mime_type = content_type # e.g., image/png, image/jpeg
|
| 93 |
elif content_type == "application/pdf":
|
| 94 |
+
mime_type = content_type
|
| 95 |
else:
|
| 96 |
raise ValueError(f"Unsupported content type: {content_type}")
|
| 97 |
|
|
|
|
| 229 |
logger.error(f"Error in data extraction: {e}")
|
| 230 |
return {"error": str(e)}
|
| 231 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
def get_content_type_from_s3(file_key):
|
| 233 |
"""Fetch the content type (MIME type) of a file stored in S3."""
|
| 234 |
try:
|
|
|
|
| 287 |
return {
|
| 288 |
"message": "Document successfully stored in MongoDB",
|
| 289 |
"document_id": document_id,
|
| 290 |
+
"entityrefkey":entity_ref_key,
|
| 291 |
"extracted_data": extracted_data
|
| 292 |
}
|
| 293 |
|