Llama Use Case : OCR with Receipts

Shows the usage Ollama hosted llama models
from utils import llama32, stream_response, disp_image, img2base64, llama32pi, rs4llama, merge_images
from fastcore.all import *
import pathlib
import PIL
# Get all receipt images using pathlib
receipt_images = list(pathlib.Path("images").glob("receipt*")); receipt_images
receipt_images[0].absolute().as_posix()
'/notebook/internal/portfolio/curations/courses/GENAI_LLAMA32/images/receipt-2.jpg'
for img in receipt_images: disp_image(img)

Prompting Strategy

# question="""You are an intelligent assistant designed to read and extract information from receipts. When presented with an image or text of a receipt, your task is to:
# Identify the section where the total amount charged is mentioned.
# Ensure you accurately interpret the itemized payment, subtotal, total, including any taxes, tips, or surcharges.
# Clearly provide the total charge or amount paid with a brief explanation of how it was derived.
# Here’s an example:

# Input (Text):
# Pizza Planet Slice Shop
# 1234 Galaxy Way
# Sunnyvale, CA 94087
# ...
# Subtotal: $12.50
# Tax: $1.10
# Tip: $1.90
# Total: $15.50

# Output:
# Total charge: $15.50
# Explanation: The total was calculated as the sum of the subtotal ($12.50), tax ($1.10), and tip ($1.90).

# Input (Text):
# Rocket Fuel Café
# 4321 Orbit Street
# San Francisco, CA 94103
# ...
# Subtotal: $5.00
# Food Tax (8.25%): $0.41
# Employee Wellness Surcharge (3.0%): $0.15
# Tip: $0.70
# Total: $6.26

# Output:
# Total charge: $6.26
# Explanation: The total includes the subtotal ($5.00), tax ($0.41), surcharge ($0.15), and tip ($0.70), adding up to $6.26.

# Now your turn:

# Input (Image/Text):
# [Provide the new receipt here]

# Output:
# [The total charge and explanation of how it was derived.]"
# """

question = "What is the total charge and/or transaction amount paid including surcharge, tax andtip in the receipt?"
results =[llama32pi(question, img.absolute().as_posix()) for img in receipt_images]; results

<<Streaming response>>

<<Streaming response>>

The total amount of money spent on this purchase is $4.39 (excluding tax). This can be calculated by adding together the cost of one Drip Coffee ($4) and the tip ($0.39).

<<Streaming response>>

The total charge for this transaction was $13.96 before the tip. This is calculated by adding the subtotal of $11.25 (El Blanco Slice - $5.75 + Shrooms Slice - $5.50) to the tax of $1.69 and subtracting the EMV Chip Read, which was $0.00 in this case.

$13.96 = ($11.25 + $1.69) - ($0.00)

['The total cost of the order was $15.38, comprising a base price of $14.09 plus a $1.29 tax. There were no additional charges or tips included in the final bill.\n\n**Breakdown of Costs:**\n\n* Base Price: $10.59\n* Tax: $3.50\n\n**Total Amount Paid:** $15.38',
 'The total amount of money spent on this purchase is $4.39 (excluding tax). This can be calculated by adding together the cost of one Drip Coffee ($4) and the tip ($0.39).',
 'The total charge for this transaction was $13.96 before the tip. This is calculated by adding the subtotal of $11.25 (El Blanco Slice - $5.75 + Shrooms Slice - $5.50) to the tax of $1.69 and subtracting the EMV Chip Read, which was $0.00 in this case.\n\n$13.96 = ($11.25 + $1.69) - ($0.00)']
# results_combined = "\n".join(results); results_combined
results; enumerate(results)
results_combined = "\n\n".join([f"Receipt#{i+1}\n{v}" for i,v in enumerate(results)]); print(results_combined)
# ["Receipt-{i}\n{v}" for i,v in enumerate(results)]
Receipt#1
The total cost of the order was $15.38, comprising a base price of $14.09 plus a $1.29 tax. There were no additional charges or tips included in the final bill.

**Breakdown of Costs:**

* Base Price: $10.59
* Tax: $3.50

**Total Amount Paid:** $15.38

Receipt#2
The total amount of money spent on this purchase is $4.39 (excluding tax). This can be calculated by adding together the cost of one Drip Coffee ($4) and the tip ($0.39).

Receipt#3
The total charge for this transaction was $13.96 before the tip. This is calculated by adding the subtotal of $11.25 (El Blanco Slice - $5.75 + Shrooms Slice - $5.50) to the tax of $1.69 and subtracting the EMV Chip Read, which was $0.00 in this case.

$13.96 = ($11.25 + $1.69) - ($0.00)
messages = [{
    "role": "user",
    "content":f"Recheck and calculate what's the sum total of charge of all the receipts below?{results_combined}"
}]; messages

# stream_response(llama32(messages))
stream_response(llama32(messages, stream=True))

<<Streaming response>>

Let’s calculate the total sum of charge for all three receipts:

Receipt#1: Base Price: $10.59 Tax: $3.50 Total Amount Paid: $15.38 (already calculated)

Receipt#2: Drip Coffee: $4 Tip: $0.39 Total Amount Spent: $4.39

Receipt#3: Subtotal: $11.25 ($5.75 + $5.50) Tax: $1.69 EMV Chip Read: $0.00 (no charge) Total Charge Before Tip: $13.96

Now, let’s add up the total charges for all three receipts:

$15.38 (Receipt#1) + $4.39 (Receipt#2) + $13.96 (Receipt#3) = $33.73

So, the sum total of charge for all three receipts is $33.73.

"Let's calculate the total sum of charge for all three receipts:\n\n**Receipt#1:**\nBase Price: $10.59\nTax: $3.50\nTotal Amount Paid: $15.38 (already calculated)\n\n**Receipt#2:**\nDrip Coffee: $4\nTip: $0.39\nTotal Amount Spent: $4.39\n\n**Receipt#3:**\nSubtotal: $11.25 ($5.75 + $5.50)\nTax: $1.69\nEMV Chip Read: $0.00 (no charge)\nTotal Charge Before Tip: $13.96\n\nNow, let's add up the total charges for all three receipts:\n\n$15.38 (Receipt#1) + $4.39 (Receipt#2) + $13.96 (Receipt#3) = **$33.73**\n\nSo, the sum total of charge for all three receipts is $33.73."
def llama32opi(prompt, system_prompt, image_url, stream=True):
    messages = [{
                "role": "system",
                 "content": system_prompt,
                },
                {"role": "user",
                    "content": [
                        {"type": "text",
                            "text": prompt,
                        },
                        {"type": "image_url",
                            "image_url": {"url": image_url}
                        }
                    ]
                }]
    if stream: result = stream_response(llama32(messages, stream=stream))
    else: result = llama32(messages)
    return result

With System Prompt

system_prompt = """
You are an intelligent OCR assistant designed to read and extract information from receipts. 
When presented with a receipt, your task is to:
1. Identify the section where the total amount charged is mentioned.
2. Accurately interpret the total, including taxes, tips, or surcharges.
3. Clearly provide the total charge with a brief explanation of how it was derived.
"""

question = "What is the total charge and/or transaction amount paid including surcharge, tax andtip in the receipt?"
results =[llama32opi(question, system_prompt, img.absolute().as_posix()) for img in receipt_images]; results

<<Streaming response>>

<<Streaming response>>

The total charge for this transaction is $4.39. This includes:

  • A base fee of $4.00
  • An additional 6 cents surcharge
  • A 7.75% sales tax of $0.31
  • The tip amount is not explicitly shown on the receipt, but it can be inferred that the total charge does include a tip.

To arrive at the total charge:

  1. Start with the base fee: $4.00
  2. Add the surcharge: $0.06
  3. Calculate the sales tax (7.75% of $4.00): $0.31
  4. Sum up these amounts to get the subtotal: $4.00 + $0.06 + $0.31 = $4.37

The final amount paid, including all charges and tips, is $4.39.

Answer: The total charge for this transaction was $4.39, which includes a base fee of $4.00, a 6 cents surcharge, a sales tax of $0.31, and an assumed tip amount.

<<Streaming response>>

The total charge and/or transaction amount paid including surcharge, tax and tip in the receipt is $13.96.

This figure can be broken down as follows: - Subtotal: $11.25 - Tax: $1.69 - Tip: $1.02 Total Amount: 11.25 + 1.69 + 1.02 = $13.96

["The total charge and/or transaction amount paid, including all applicable charges, is $15.38.\n\nThis figure encompasses the following components:\n\n* **Subtotal**: The subtotal of $14.09 represents the initial cost of items purchased.\n* **Tax**: A tax of $1.29 was added to the subtotal.\n* **Tip**: No tip was included in this transaction.\n* **Total**: After adding the tax, the total amount due is $15.38.\n\nThis breakdown provides a clear understanding of how the final amount was calculated based on the receipt's details.",
 'The total charge for this transaction is **$4.39**. This includes:\n\n* A base fee of **$4.00**\n* An additional **6 cents** surcharge\n* A 7.75% sales tax of $0.31\n* The tip amount is not explicitly shown on the receipt, but it can be inferred that the total charge does include a tip.\n\nTo arrive at the total charge:\n\n1. Start with the base fee: $4.00\n2. Add the surcharge: $0.06\n3. Calculate the sales tax (7.75% of $4.00): $0.31\n4. Sum up these amounts to get the subtotal: $4.00 + $0.06 + $0.31 = $4.37\n\nThe final amount paid, including all charges and tips, is $4.39.\n\n**Answer:** The total charge for this transaction was **$4.39**, which includes a base fee of $4.00, a 6 cents surcharge, a sales tax of $0.31, and an assumed tip amount.',
 'The total charge and/or transaction amount paid including surcharge, tax and tip in the receipt is $13.96.\n\nThis figure can be broken down as follows:\n- Subtotal: $11.25\n- Tax: $1.69\n- Tip: $1.02\nTotal Amount: 11.25 + 1.69 + 1.02 = $13.96']
results; enumerate(results)
results_combined = "\n\n".join([f"Receipt#{i+1}\n{v}" for i,v in enumerate(results)]); results_combined
messages = [{
    "role": "user",
    "content":f"Revalidate and calculate what's the sum total of charge of all the receipts below?{results_combined}"
}]; messages

# stream_response(llama32(messages))
stream_response(llama32(messages, stream=True))

<<Streaming response>>

Let’s break down each receipt to calculate the total charge:

Receipt#1

  • Subtotal: $14.09
  • Tax: $1.29
  • Total: $15.38

The subtotal and tax are already given, so we can calculate the tip as: $15.38 (Total) - ($14.09 + $1.29) = $0.00 However, it’s stated that no tip was included in this transaction.

Receipt#2

  • Base fee: $4.00
  • Surcharge: $0.06
  • Sales tax: $0.31 (7.75% of $4.00)
  • Total charge: $4.39

The total charge already includes the base fee, surcharge, sales tax, and an assumed tip amount.

Receipt#3

  • Subtotal: $11.25
  • Tax: $1.69
  • Tip: $1.02
  • Total Amount: $13.96 (already given)

We can verify that the total charge is indeed correct by adding up the subtotal, tax, and tip: $11.25 + $1.69 + $1.02 = $14.96 (not $13.96, there seems to be an error in this receipt).

Now, let’s calculate the sum of all three receipts:

Receipt#1: $15.38 Receipt#2: $4.39 Receipt#3: $13.96 (assuming it should be $14.96, but we’ll use the given value)

The total sum is: $15.38 + $4.39 + $13.96 = $33.73

"Let's break down each receipt to calculate the total charge:\n\n**Receipt#1**\n\n* Subtotal: $14.09\n* Tax: $1.29\n* Total: $15.38\n\nThe subtotal and tax are already given, so we can calculate the tip as:\n$15.38 (Total) - ($14.09 + $1.29) = $0.00\nHowever, it's stated that no tip was included in this transaction.\n\n**Receipt#2**\n\n* Base fee: $4.00\n* Surcharge: $0.06\n* Sales tax: $0.31 (7.75% of $4.00)\n* Total charge: $4.39\n\nThe total charge already includes the base fee, surcharge, sales tax, and an assumed tip amount.\n\n**Receipt#3**\n\n* Subtotal: $11.25\n* Tax: $1.69\n* Tip: $1.02\n* Total Amount: $13.96 (already given)\n\nWe can verify that the total charge is indeed correct by adding up the subtotal, tax, and tip:\n$11.25 + $1.69 + $1.02 = $14.96 (not $13.96, there seems to be an error in this receipt).\n\nNow, let's calculate the sum of all three receipts:\n\n**Receipt#1**: $15.38\n**Receipt#2**: $4.39\n**Receipt#3**: $13.96 (assuming it should be $14.96, but we'll use the given value)\n\nThe total sum is:\n$15.38 + $4.39 + $13.96 = $33.73"
## Billing Dates
question = "What are the dates on receipt"
results =[llama32pi(question, img.absolute().as_posix()) for img in receipt_images]; results

<<Streaming response>>

<<Streaming response>>

The receipt is dated September 22, 2024, which can be inferred from the date “22-Sep-2024” appearing in multiple places on the receipt. This date format suggests that the transaction took place on September 22nd of last year.

Answer: 22-Sep-2024

<<Streaming response>>

The dates that appear on this receipt are:

  • Date ordered: 9/23/24
  • Date printed: 9/23/24
['The dates mentioned on the receipt are:\n\n* Valid until: 30 days after the purchase date (no specific end date is provided)\n* Purchase Date: September 22, 2024',
 'The receipt is dated **September 22, 2024**, which can be inferred from the date "22-Sep-2024" appearing in multiple places on the receipt. This date format suggests that the transaction took place on September 22nd of last year.\n\nAnswer: 22-Sep-2024',
 'The dates that appear on this receipt are:\n\n* Date ordered: 9/23/24\n* Date printed: 9/23/24']
results_combined = "\n\n".join([f"Receipt#{i+1}\n{v}" for i,v in enumerate(results)]); print(results_combined)
messages = [{
    "role": "user",
    "content":f"Give all the billing dates in dd-mm-yyyy in tabular format for each receipt?{results_combined}"
}]; messages

# stream_response(llama32(messages))
stream_response(llama32(messages, stream=True))
Receipt#1
The dates mentioned on the receipt are:

* Valid until: 30 days after the purchase date (no specific end date is provided)
* Purchase Date: September 22, 2024

Receipt#2
The receipt is dated **September 22, 2024**, which can be inferred from the date "22-Sep-2024" appearing in multiple places on the receipt. This date format suggests that the transaction took place on September 22nd of last year.

Answer: 22-Sep-2024

Receipt#3
The dates that appear on this receipt are:

* Date ordered: 9/23/24
* Date printed: 9/23/24

<<Streaming response>>

Here are the billing dates in dd-mm-yyyy format for each receipt:

Receipt # Billing Date
1 No specific end date, but valid until 30 days after Sept 22, 2024 = Oct 22, 2024
2 22-09-2023
3 No billing dates mentioned, only order and print dates (9/23/24)

Note that Receipt #1 has a billing date of October 22, 2024, which is 30 days after the purchase date. Receipt #2 has a billing date of September 22, 2023, based on the inferred transaction date.

'Here are the billing dates in dd-mm-yyyy format for each receipt:\n\n| Receipt # | Billing Date |\n| --- | --- |\n| 1 | No specific end date, but valid until 30 days after Sept 22, 2024 = Oct 22, 2024 |\n| 2 | 22-09-2023 |\n| 3 | No billing dates mentioned, only order and print dates (9/23/24) |\n\nNote that Receipt #1 has a billing date of October 22, 2024, which is 30 days after the purchase date. Receipt #2 has a billing date of September 22, 2023, based on the inferred transaction date.'

With System Prompt and Reprompting

system_prompt = """
You are an intelligent OCR assistant designed to read and extract information from receipts. 
When presented with a receipt, your task is to:
1. Identify the section where the total amount charged is mentioned.
2. Accurately interpret the total, including taxes, tips, or surcharges.
3. Clearly provide the total charge with a brief explanation of how it was derived.
4. Please note sometimes tip can be listed afterwards and is not included in total charge. Identify such cases and calculate total charge as listed total or charge plus tip
"""

question = "What is the total charge and/or transaction amount paid including surcharge, tax and tip in the receipt?"
img = receipt_images[1]
resp_i = llama32opi(question,system_prompt=system_prompt, image_url=img.absolute().as_posix()); resp_i

<<Streaming response>>

'The total charge on this receipt was $4.39.\n\nThis total was calculated by adding 7.75% sales tax to the cost of one item at a price of $4.00. The calculation is as follows: \n\n1. Sales Tax Calculation:\n   * Amount before tax = $4.00\n   * Sales tax rate = 7.75%\n   * Tax amount = $4.00 x 0.0775 = $0.31\n\n2. Subtotal Calculation:\n   * Total cost including tax = Amount before tax + Tax amount\n   * Total cost including tax = $4.00 + $0.31 = $4.31\n\n3. Tip is not included in this calculation as it was listed separately on the receipt.\n\nNote: The tip is separate from the total charge and is not included in the calculation above.\n\nAnswer: The total charge paid for this transaction, including tax but not including the tip listed at the bottom of the receipt was $4.31.'
image_url = img.absolute().as_posix()
reprompt = "Verify if your output is correct. If there are discrepancies or missing details, adjust your output and explanation accordingly.Ensure the total includes all charges (e.g., tax, tip, surcharge) and provide a clear, accurate explanation for how it was derived. Don't modify if things are correct"
messages = [{
            "role": "system",
                "content": system_prompt,
            },
            {"role": "user",
                "content": [
                    {"type": "text",
                        "text": question,
                    },
                    {"type": "image_url",
                        "image_url": {"url": image_url}
                    }
                ]
            },
            {
                "role": "assistant",
                "content":resp_i
            },
            {"role": "user",
                "content": [
                    {"type": "text",
                        "text": reprompt,
                    },
                    {"type": "image_url",
                        "image_url": {"url": image_url}
                    }
                ]
            },
            ]


resp_ri = stream_response(llama32(messages, stream=True)); resp_ri

<<Streaming response>>

'The total charge on this receipt was $4.39.\n\nThis total was calculated by adding 7.75% sales tax to the cost of one item at a price of $4.00. The calculation is as follows: \n\n1. Sales Tax Calculation:\n   * Amount before tax = $4.00\n   * Sales tax rate = 7.75%\n   * Tax amount = $4.00 x 0.0775 = $0.31\n\n2. Subtotal Calculation:\n   * Total cost including tax = Amount before tax + Tax amount\n   * Total cost including tax = $4.00 + $0.31 = $4.31\n\n3. Tip is not included in this calculation as it was listed separately on the receipt.\n\nNote: The tip is separate from the total charge and is not included in the calculation above.\n\nAnswer: The total charge paid for this transaction, including tax but not including the tip listed at the bottom of the receipt was $4.31.'
print(resp_ri)
The total charge on this receipt was $4.39.

This total was calculated by adding 7.75% sales tax to the cost of one item at a price of $4.00. The calculation is as follows: 

1. Sales Tax Calculation:
   * Amount before tax = $4.00
   * Sales tax rate = 7.75%
   * Tax amount = $4.00 x 0.0775 = $0.31

2. Subtotal Calculation:
   * Total cost including tax = Amount before tax + Tax amount
   * Total cost including tax = $4.00 + $0.31 = $4.31

3. Tip is not included in this calculation as it was listed separately on the receipt.

Note: The tip is separate from the total charge and is not included in the calculation above.

Answer: The total charge paid for this transaction, including tax but not including the tip listed at the bottom of the receipt was $4.31.
def ocr_reprompt(prompt, reprompt, system_prompt, image_url, stream=True):
    resp_i = llama32opi(prompt,system_prompt=system_prompt, image_url=image_url, stream=True); resp_i
    messages = [{
            "role": "system",
                "content": system_prompt,
            },
            {"role": "user",
                "content": [
                    {"type": "text",
                        "text": prompt,
                    },
                    {"type": "image_url",
                        "image_url": {"url": image_url}
                    }
                ]
            },
            {
                "role": "assistant",
                "content":resp_i
            },
            {"role": "user",
                "content": [
                    {"type": "text",
                        "text":f"You said {resp_i} on given images.{reprompt}",
                    },
                    {"type": "image_url",
                        "image_url": {"url": image_url}
                    }
                ]
            },
            ]
    resp_ri = stream_response(llama32(messages, stream=True)); resp_ri
    return resp_ri
resp_ri = ocr_reprompt(question, reprompt, system_prompt=system_prompt, image_url=img.absolute().as_posix()); resp_ri

<<Streaming response>>

<<Streaming response>>

Receipt Analysis

The provided receipt is from Dark Horse Coffee - San Diego, California. The receipt includes a subtotal of $4.00 for one Drip Coffee 16oz.

Taxes and Surcharges

There are no additional taxes or surcharges listed on this receipt.

Tip Information

A tip amount is not specified in the provided information; however, it may be mentioned below the total charge. Therefore, we will assume that the tip has been included in the total charge.

Total Charge Calculation

Given the subtotal of $4.00 and the absence of any additional charges or surcharges, the total transaction amount can be considered as the same as the subtotal plus tip. However, since no tip is specified, we cannot accurately calculate a separate tip amount without further information.

Conclusion

Based on the provided receipt details, the total charge for this transaction is $4.39 ($4.00 + $0.39). This assumes that the tip has been included in the total charge and does not require any additional calculation beyond the subtotal.

The correct answer is: $4.39

'**Receipt Analysis**\n\nThe provided receipt is from Dark Horse Coffee - San Diego, California. The receipt includes a subtotal of $4.00 for one Drip Coffee 16oz.\n\n**Taxes and Surcharges**\n\nThere are no additional taxes or surcharges listed on this receipt.\n\n**Tip Information**\n\nA tip amount is not specified in the provided information; however, it may be mentioned below the total charge. Therefore, we will assume that the tip has been included in the total charge.\n\n**Total Charge Calculation**\n\nGiven the subtotal of $4.00 and the absence of any additional charges or surcharges, the total transaction amount can be considered as the same as the subtotal plus tip. However, since no tip is specified, we cannot accurately calculate a separate tip amount without further information.\n\n**Conclusion**\n\nBased on the provided receipt details, the total charge for this transaction is $4.39 ($4.00 + $0.39). This assumes that the tip has been included in the total charge and does not require any additional calculation beyond the subtotal.\n\nThe correct answer is: **$4.39**'
results =[ocr_reprompt(question, reprompt, system_prompt=system_prompt, image_url=img.absolute().as_posix()) for img in receipt_images]; results
results_combined = "\n\n".join([f"Receipt#{i+1}\n{v}" for i,v in enumerate(results)]); results_combined
messages = [{
    "role": "user",
    "content":f"Revalidate and calculate what's the sum total of charge or transaction of all the receipts below?{results_combined}"
}]; messages

# stream_response(llama32(messages))
stream_response(llama32(messages, stream=True))

<<Streaming response>>

<<Streaming response>>

I apologize for my previous mistake. Upon re-examining the receipt, I realized that the total charge is actually $15.38, not $11.88.

Here’s the corrected breakdown:

  • Subtotal: $10.59
  • Tax: $1.29 (not explicitly mentioned but calculated based on the total)
  • Tip: Not included in the subtotal; however, there’s a note stating “NO Whipped Cream” and “LIGHT Chocolate Drizzle,” which might indicate that some items were ordered without additional charges.
  • Total Charge: Calculated as $10.59 + $1.29 + $3.50 = $15.38

Conclusion

The total charge for the transaction is indeed $15.38, including tax and excluding tip since it wasn’t a part of the original order.

Answer: The total amount paid was $15.38 based on the subtotal and tax calculation.

<<Streaming response>>

The total charge for this transaction is $4.39.

This total includes a food tax of 7.75%, which amounts to $0.31, and a surcharge that has not been disclosed. It does not include a service charge or gratuity, as there is no indication of one being added to the bill.

<<Streaming response>>

The total charge for this transaction is $4.39.

This total includes a food tax of 7.75%, which amounts to $0.31, and a surcharge that has not been disclosed. It does not include a service charge or gratuity, as there is no indication of one being added to the bill.

The amount before any taxes or tips was $4.00, with an additional food tax of 7.75%, which amounts to $0.31 and brings the total to $4.31. However, it appears that a tip has been included as well, in this case, $0.08. Therefore, the final total is $4.39 ($4.31 + $0.08).

<<Streaming response>>

The total charge and/or transaction amount paid, including a 1% surcharge, tax of $1.69, and an additional tip of $2.00, is $13.96.

This amount can be broken down as follows:

  • El Blanco Slice: $5.75
  • Shrooms Slice: $5.50
  • Total before tax/surcharge/tip: $11.25
  • 1% Surcharge: $0.12 (calculated as 1% of the subtotal)
  • Tax: $1.69
  • Tip: $2.00

Total charge including all these elements is $13.96.

<<Streaming response>>

After re-examining the receipt, I noticed that the provided calculation incorrectly included an additional $2.00 tip, which is not mentioned on the receipt.

Here’s the corrected breakdown:

  • El Blanco Slice: $5.75
  • Shrooms Slice: $5.50
  • Total before tax/surcharge/tip: $11.25

The total charge including all these elements is $13.96.

To derive this amount, we can simply add the subtotal of $11.25 and the 1% surcharge of $0.12 to get a subtotal of $11.37 before tax.

Then, adding the tax of $1.69 gives us a total of $13.06.

Finally, subtracting $0.10 from this amount yields the final total charge of $13.96, which is likely due to an additional tip that was not included in the calculation.

Therefore, based on the information provided in the receipt and ensuring accurate inclusion of all charges, I confirm that the correct total charge is indeed $13.96.

<<Streaming response>>

Here are the calculations for each receipt:

Receipt#1: Subtotal: $10.59 Tax: $1.29 (calculated based on the total) Total Charge: $10.59 + $1.29 = $11.88

However, according to the corrected breakdown provided in Receipt#1, the actual total charge is $15.38.

Receipt#2: Subtotal: $4.00 Food tax: 7.75% of $4.00 = $0.31 Total before taxes or tips: $4.00 + $0.31 = $4.31 Tip: $0.08 Final Total: $4.31 + $0.08 = $4.39

Receipt#3: Subtotal: $11.25 Surcharge: 1% of $11.25 = $0.12 Total before tax: $11.25 + $0.12 = $11.37 Tax: $1.69 Total before tip: $11.37 + $1.69 = $13.06 Tip: -$0.10 (assuming this is a discount, not an additional charge) Final Total: $13.06 - $0.10 = $13.96

'Here are the calculations for each receipt:\n\nReceipt#1:\nSubtotal: $10.59\nTax: $1.29 (calculated based on the total)\nTotal Charge: $10.59 + $1.29 = $11.88\n\nHowever, according to the corrected breakdown provided in Receipt#1, the actual total charge is $15.38.\n\nReceipt#2:\nSubtotal: $4.00\nFood tax: 7.75% of $4.00 = $0.31\nTotal before taxes or tips: $4.00 + $0.31 = $4.31\nTip: $0.08\nFinal Total: $4.31 + $0.08 = $4.39\n\nReceipt#3:\nSubtotal: $11.25\nSurcharge: 1% of $11.25 = $0.12\nTotal before tax: $11.25 + $0.12 = $11.37\nTax: $1.69\nTotal before tip: $11.37 + $1.69 = $13.06\nTip: -$0.10 (assuming this is a discount, not an additional charge)\nFinal Total: $13.06 - $0.10 = $13.96'
results =[ocr_reprompt(question, reprompt, system_prompt=system_prompt, image_url=rs4llama(img.absolute().as_posix())) for img in receipt_images]; results
results_combined = "\n\n".join([f"Receipt#{i+1}\n{v}" for i,v in enumerate(results)]); results_combined
messages = [{
    "role": "user",
    "content":f"Revalidate and calculate what's the sum total of charge or transaction of all the receipts below?{results_combined}"
}]; messages

# stream_response(llama32(messages))
stream_response(llama32(messages, stream=True))

<<Streaming response>>

Receipt Analysis

The provided receipt is from McDonald’s Restaurant #3094, located at 3128 El Camino Real, Palo Alto, CA. The order was placed on September 22nd, 2024.

Total Charge Calculation

  • Subtotal: $14.09
  • Tax (1.29): Added to the subtotal for a total of $15.38
  • Tip: Not included in the total charge; instead, listed separately as $3.50

Transaction Amount

The transaction amount is the sum of the subtotal, tax, and tip:

$14.09 + $1.29 = $15.38 (subtotal and tax) $15.38 + $3.50 = $18.88 (including tip)

However, if we consider only the subtotal and tax for the transaction amount:

$14.09 + $1.29 = $15.38

Therefore, the total charge is $18.88, while the transaction amount is $15.38.

<<Streaming response>>

I apologize for the mistake in my previous response. Based on the provided receipt, I re-analyzed the information to ensure accuracy.

Receipt Analysis

The provided receipt is from McDonald’s Restaurant #3094, located at 3128 El Camino Real, Palo Alto, CA. The order was placed on September 22nd, 2024.

Total Charge Calculation

  • Subtotal: $10.59
  • Tax (1.29): Added to the subtotal for a total of $11.88

Transaction Amount

The transaction amount includes all charges:

$10.59 + $1.29 = $11.88

Therefore, the total charge is $11.88.

I have corrected my previous response to reflect the accurate information from the receipt.

<<Streaming response>>

The total charge in this receipt is $4.39. This includes a 7.75% food tax ($0.31) added to the price of the coffee ($4.00). There are no surcharges or tips mentioned on this receipt.

$4.00 + $0.31 = $4.31 Therefore, the total charge is $4.39 and not $4.39 including tip because there was no tip included in the original amount.

<<Streaming response>>

The total charge in this receipt is $4.39. This includes a 7.75% food tax ($0.31) added to the price of the coffee ($4.00). There are no surcharges or tips mentioned on this receipt.

$4.00 + $0.31 = $4.31 Therefore, the total charge is $4.39 and not $4.39 including tip because there was no tip included in the original amount.

<<Streaming response>>

The total charge and/or transaction amount paid for this purchase is $13.96.

This includes a subtotal of $11.25, taxes of $1.69, and a tip of $0.02.

<<Streaming response>>

The total charge and/or transaction amount paid for this purchase is $13.96.

This includes a subtotal of $11.25, taxes of $1.69, and a tip of $0.02. However, the receipt does not mention any surcharge. The total listed on the receipt is $13.96, which is comprised of the subtotal ($11.25), tax ($1.69), and tip ($0.02).

<<Streaming response>>

Here are the calculations for each receipt:

Receipt#1 $10.59 (subtotal) + $1.29 (tax) = $11.88

Receipt#2 $4.00 (coffee price) + $0.31 (food tax) = $4.31 Total charge: $4.39 Note: The total charge is $4.39, not including tip.

Receipt#3 Subtotal: $11.25 Tax: $1.69 Tip: $0.02 Total charge: $13.96

'Here are the calculations for each receipt:\n\n**Receipt#1**\n$10.59 (subtotal) + $1.29 (tax) = $11.88\n\n**Receipt#2**\n$4.00 (coffee price) + $0.31 (food tax) = $4.31\nTotal charge: $4.39\nNote: The total charge is $4.39, not including tip.\n\n**Receipt#3**\nSubtotal: $11.25\nTax: $1.69\nTip: $0.02\nTotal charge: $13.96'
img_combined = merge_images([PIL.Image.open(img.absolute().as_posix()) for img in receipt_images]); img_combined.size
(5760, 2560)

Merge Images

results =ocr_reprompt(question, reprompt, system_prompt=system_prompt, image_url=rs4llama(img_combined)) 
messages = [{
    "role": "user",
    "content":f"What's the sum total of charge or transaction of all the receipts below?{results_combined}"
}]; messages

# stream_response(llama32(messages))
stream_response(llama32(messages, stream=True))

<<Streaming response>>

Receipt Analysis

The provided receipt is from McDonald’s Restaurant with a survey code 20508-00153-B. The total charge on this receipt is $14.79.

Breakdown of Charges:

  • Subtotal: $10.59
  • Tax: $4.20 (30% tax rate)
  • Total Charge: $14.79

Tip and Surcharge Information: There are no tips or surcharges listed on the receipt.

Conclusion: The total charge paid for this transaction, including tax, is $14.79.

<<Streaming response>>

The provided receipt is from State of Mind Slice House with no survey code listed. The total charge on this receipt is $11.25.

Breakdown of Charges:

  • Subtotal: $5.75
  • Tip: Not included in the subtotal but added separately as $1.89
  • Total Charge: $11.25

Tip and Surcharge Information: The tip is listed separately after the subtotal, indicating it’s not included in the total charge.

Conclusion: The total charge paid for this transaction, including tax (0% tax rate), is $11.25.

<<Streaming response>>

The sum total of charge or transaction of all the receipts below is:

$11.88 (Receipt#1) + $4.39 (Receipt#2) + $13.96 (Receipt#3)

= $30.23

'The sum total of charge or transaction of all the receipts below is:\n\n$11.88 (Receipt#1) + $4.39 (Receipt#2) + $13.96 (Receipt#3)\n\n= $30.23'