Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -84,8 +84,9 @@ def fetch_file_from_s3(file_key):
|
|
| 84 |
def extract_invoice_data(file_data, content_type, json_schema):
|
| 85 |
system_prompt = "You are an expert in document data extraction."
|
| 86 |
|
| 87 |
-
|
| 88 |
base64_encoded = base64.b64encode(file_data).decode('utf-8')
|
|
|
|
| 89 |
|
| 90 |
# Determine the correct MIME type for OpenAI
|
| 91 |
if content_type.startswith("image/"):
|
|
@@ -119,7 +120,7 @@ def extract_invoice_data(file_data, content_type, json_schema):
|
|
| 119 |
temperature=0.5,
|
| 120 |
max_tokens=16384
|
| 121 |
)
|
| 122 |
-
|
| 123 |
# Clean and parse JSON output
|
| 124 |
content = response.choices[0].message.content.strip()
|
| 125 |
cleaned_content = content.strip().strip('```json').strip('```')
|
|
|
|
| 84 |
def extract_invoice_data(file_data, content_type, json_schema):
|
| 85 |
system_prompt = "You are an expert in document data extraction."
|
| 86 |
|
| 87 |
+
# Convert file to Base64
|
| 88 |
base64_encoded = base64.b64encode(file_data).decode('utf-8')
|
| 89 |
+
base64dataresp = f"data:{content_type};base64,{base64_encoded}"
|
| 90 |
|
| 91 |
# Determine the correct MIME type for OpenAI
|
| 92 |
if content_type.startswith("image/"):
|
|
|
|
| 120 |
temperature=0.5,
|
| 121 |
max_tokens=16384
|
| 122 |
)
|
| 123 |
+
|
| 124 |
# Clean and parse JSON output
|
| 125 |
content = response.choices[0].message.content.strip()
|
| 126 |
cleaned_content = content.strip().strip('```json').strip('```')
|