Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -93,17 +93,6 @@ def extract_pdf_text(file_data):
|
|
| 93 |
logger.error(f"PDF Extraction Error: {e}")
|
| 94 |
return None
|
| 95 |
|
| 96 |
-
# def extract_text_from_image(file_data):
|
| 97 |
-
# """
|
| 98 |
-
# Extracts text from a image file using pytesseract
|
| 99 |
-
# """
|
| 100 |
-
# try:
|
| 101 |
-
# image = Image.open(io.BytesIO(image_data))
|
| 102 |
-
# extracted_text = pytesseract.image_to_string(image)
|
| 103 |
-
# return extracted_text.strip()
|
| 104 |
-
# except Exception as e:
|
| 105 |
-
# logger.error(f"Image Extraction Error: {e}")
|
| 106 |
-
# return None
|
| 107 |
|
| 108 |
# Function to summarize text using OpenAI GPT
|
| 109 |
def extract_invoice_data(file_data, content_type, json_schema):
|
|
@@ -161,7 +150,6 @@ Ensure that:
|
|
| 161 |
return {"error": "Failed to process PDF"}, None
|
| 162 |
|
| 163 |
elif content_type.startswith("image/"):
|
| 164 |
-
# extracted_text = extract_text_from_image(file_data) # OCR extraction
|
| 165 |
# Handle direct image files
|
| 166 |
base64_pdf = base64.b64encode(file_data).decode('utf-8')
|
| 167 |
base64DataResp.append(f"data:{content_type};base64,{base64_pdf}")
|
|
|
|
| 93 |
logger.error(f"PDF Extraction Error: {e}")
|
| 94 |
return None
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
# Function to summarize text using OpenAI GPT
|
| 98 |
def extract_invoice_data(file_data, content_type, json_schema):
|
|
|
|
| 150 |
return {"error": "Failed to process PDF"}, None
|
| 151 |
|
| 152 |
elif content_type.startswith("image/"):
|
|
|
|
| 153 |
# Handle direct image files
|
| 154 |
base64_pdf = base64.b64encode(file_data).decode('utf-8')
|
| 155 |
base64DataResp.append(f"data:{content_type};base64,{base64_pdf}")
|