Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -157,8 +157,13 @@ def process_receipt_endpoint():
|
|
| 157 |
|
| 158 |
# Process the image with Gemini
|
| 159 |
image = Image.open(io.BytesIO(image_bytes))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
model = configure_gemini()
|
| 161 |
-
result_text = process_receipt(model,
|
| 162 |
|
| 163 |
try:
|
| 164 |
json_str = result_text[result_text.find('{'):result_text.rfind('}')+1]
|
|
|
|
| 157 |
|
| 158 |
# Process the image with Gemini
|
| 159 |
image = Image.open(io.BytesIO(image_bytes))
|
| 160 |
+
# --- Image Compression ---
|
| 161 |
+
compressed_buffer = io.BytesIO()
|
| 162 |
+
image.save(compressed_buffer, format="JPEG", optimize=True, quality=90) # Adjust quality as needed
|
| 163 |
+
compressed_image_bytes = compressed_buffer.getvalue()
|
| 164 |
+
compressed_image = Image.open(io.BytesIO(compressed_image_bytes)
|
| 165 |
model = configure_gemini()
|
| 166 |
+
result_text = process_receipt(model, compressed_image)
|
| 167 |
|
| 168 |
try:
|
| 169 |
json_str = result_text[result_text.find('{'):result_text.rfind('}')+1]
|