How to OCR code without Gemini messing with it?

Hello – I'm trying Gemini for OCR (it's simpler to use than the API) but it makes clear changes the text.

This is a fragment of an image that I gave to Flash 2.5:

source image (partial)

The prompt was "OCR this, without making any changes to the text"

It took some liberties with the output, removing a pair of # marks near the end.

    multi_entry_queries = {}
    for idx, entry_str in enumerate(stream, start=1):
        try:
            entry = json.loads(entry_str)
        except Exception as e:
            print(f"Cannot parse #{idx}: {entry_str.strip()}", file=sys.stderr)
            continue
        if 'c' in entry and entry['c'] == "COMMAND":
            continue
        if '$' in entry.get('ns', ''):
            continue

Another example:

https://preview.redd.it/wl7cheue485g1.png?width=441&format=png&auto=webp&s=69f94848ceb07f0d0ee6397b2db001ee4223a874

# "create" goes to position 0, etc
crud_counts[ts_min_s][crud_index(cmd_type[0])] += 1

These look like attempts at correction (it recognized and highlighted the Python code). How do I get it to be faithful? I've tried including clauses like "don't make any changes"; "don't interpret the code"; "recover the original text". It won't "listen".

Any ideas?

Leave a Reply