Spaces:
Sleeping
Sleeping
Update OCR.py
Browse files
OCR.py
CHANGED
@@ -14,7 +14,7 @@ processor = AutoProcessor.from_pretrained(model_id)
|
|
14 |
|
15 |
def extract_text_from_image(image_content):
|
16 |
image = Image.open(io.BytesIO(image_content))
|
17 |
-
prompt = "Extract the following details from this invoice: Invoice Number, Amount, Invoice Date
|
18 |
inputs = processor(text=prompt, images=image, return_tensors="pt").to(device)
|
19 |
input_len = inputs["input_ids"].shape[-1]
|
20 |
with torch.inference_mode():
|
@@ -29,5 +29,4 @@ def extract_invoice_details(text):
|
|
29 |
details['Invoice Number'] = re.search(r'Invoice Number: (\S+)', text).group(1) if re.search(r'Invoice Number: (\S+)', text) else 'N/A'
|
30 |
details['Amount'] = re.search(r'Total Amount Due: (\S+)', text).group(1) if re.search(r'Total Amount Due: (\S+)', text) else 'N/A'
|
31 |
details['Invoice Date'] = re.search(r'Invoice Date: (\S+)', text).group(1) if re.search(r'Invoice Date: (\S+)', text) else 'N/A'
|
32 |
-
details['Due Date'] = re.search(r'Due Date: (\S+)', text).group(1) if re.search(r'Due Date: (\S+)', text) else 'N/A'
|
33 |
return details
|
|
|
14 |
|
15 |
def extract_text_from_image(image_content):
|
16 |
image = Image.open(io.BytesIO(image_content))
|
17 |
+
prompt = "Extract the following details from this invoice: Invoice Number, Total Amount, Invoice Date."
|
18 |
inputs = processor(text=prompt, images=image, return_tensors="pt").to(device)
|
19 |
input_len = inputs["input_ids"].shape[-1]
|
20 |
with torch.inference_mode():
|
|
|
29 |
details['Invoice Number'] = re.search(r'Invoice Number: (\S+)', text).group(1) if re.search(r'Invoice Number: (\S+)', text) else 'N/A'
|
30 |
details['Amount'] = re.search(r'Total Amount Due: (\S+)', text).group(1) if re.search(r'Total Amount Due: (\S+)', text) else 'N/A'
|
31 |
details['Invoice Date'] = re.search(r'Invoice Date: (\S+)', text).group(1) if re.search(r'Invoice Date: (\S+)', text) else 'N/A'
|
|
|
32 |
return details
|