ChatGPT Fails to Read the Text from Image

I wanted to scan a JPEG that contains a table into a CSV file, what is the quickest way? ChatGPT seems to fail the tasks, trying a few times, but can't read the data.

image.png

The code from ChatGPT is:

import pytesseract
from PIL import Image
import pandas as pd

# Load the image from file
image_path = '/mnt/data/image.png'
image = Image.open(image_path)

# Use tesseract to do OCR on the image
text = pytesseract.image_to_string(image)

# Since the user asked for a CSV, we will need to parse the text into a DataFrame and then save it as CSV
# First, we need to split the text into lines
lines = text.split('\n')

# Find the line that contains column headers to determine the structure of the table
column_headers = []
for line in lines:
    if 'Item No.' in line and 'Amount' in line:
        column_headers = line.split()
        break

# Check if column headers have been found
if column_headers:
    # Initialize a dictionary to hold our columns
    columns = {header: [] for header in column_headers}
    
    # Now go through all lines and if a line has the same number of elements as the headers, add it to columns
    for line in lines:
        elements = line.split()
        if len(elements) == len(column_headers):
            for header, element in zip(column_headers, elements):
                columns[header].append(element)
    
    # Convert the dictionary to a DataFrame
    df = pd.DataFrame(columns)
    
    # Save the DataFrame to a CSV file
    csv_path = '/mnt/data/extracted_table.csv'
    df.to_csv(csv_path, index=False)

    csv_path
else:
    'Could not find the column headers in the text.'

Steem Blockchain

Steem to the Moon🚀!

  • You can swap the STEEM/SBD to ETH (Ethereum) via steem2eth!
  • You can swap the STEEM/SBD to Tether USDT (TRC-20) via steem2usdt!
  • You can swap the STEEM/SBD to TRX (TRON) via steem2trx!
  • You can swap the STEEM/SBD to BTS (BitShares) via steem2bts!
  • Register a free STEEM account at SteemYY!

ChatGPT Use Cases

ChatGPT - AGI (Artificial General Intelligence)

ChatGPT Fails to

H2
H3
H4
3 columns
2 columns
1 column
2 Comments