barcode-flask/data.py

27 lines
537 B
Python
Raw Permalink Normal View History

from PIL import Image
import pytesseract as OCR
2024-02-24 23:59:15 +01:00
import api_key
from openai import OpenAI as AI
receipts = ['image.jpg']
amounts = []
merchants = []
OCR.pytesseract.tesseract_cmd = r"/usr/local/bin/tesseract"
2024-02-24 23:59:15 +01:00
client = AI(api_key = api_key.key)
2024-02-24 23:59:15 +01:00
for receipt in receipts:
text = OCR.image_to_string(receipt)
print(text)
2024-02-24 23:59:15 +01:00
req = client.chat.completions.create(
model="gpt-3.5.turbo",
messages = [{
2024-02-24 19:28:59 +01:00
"role": "user",
2024-02-24 23:59:15 +01:00
"content": f"parse the following receipt as JSON data: {text}",
}]
)
2024-02-24 19:28:59 +01:00
2024-02-24 23:59:15 +01:00
print(req.choices[0].message.content)