ChatGPT Fails to Read the Text from Image

in #blog5 months ago (edited)

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

Sort:  

!ask how to Read the Text from Image?



There are several ways to read text from an image. Depending on the type of image, optical character recognition (OCR) software can be used to convert the text into a digital format. Additionally, online tools such as iLovePDF and Free OCR offer free OCR services to extract text from images. If you're working with a PDF file, Adobe Acrobat Pro or Google Drive can also be used to select and copy the text from the image.


command: !ask is powered by witness @justyy and his contributions are: https://steemyy.com
More commands are coming!.
!ask is currently based on ChatGPT-3.5

Coin Marketplace

STEEM 0.29
TRX 0.12
JST 0.034
BTC 63094.38
ETH 3148.11
USDT 1.00
SBD 3.88