Can even I code with ChatGPT?
created by ChatGPT

Can even I code with ChatGPT?

I know, you've read it countless times about how ChatGPT excels at reading, debugging, and optimizing code. AI has become a buzzword among clients, team members, and partners. But how has it actually impacted your daily workflow?

I quickly integrated ChatGPT into my daily routine, but I couldn’t go beyond basic text-based tasks. Even the paid version, while useful, didn’t revolutionize my workflow as I had hoped.

Started from the bottom

I’ve always been fascinated by technology and enjoyed tinkering with it. I used to code a bit, but due to a lack of time, skill, and—let’s face it—willpower, I often found myself stuck in the valley of despair.

I remember endless hours of Googling, browsing StackOverflow, and reading documentation, all in a desperate attempt to get something working, only to be stopped by the simplest of problems. Eventually, I would run out of time or motivation — usually both —and move on to more productive work.

The real blessing of Gen AI

I’m not worried that software engineers will soon face extinction (shout-out to lamplighters and knocker-ups). But what AI has brought to the table for those of us, simple folk, with limited skills is simply incredible.

ChatGPT, or any similar tool for that matter, can quickly guide you through the valley of despair and help you achieve results, debug issues, and push you toward applicable solutions.

What I did

I had a straightforward problem: I needed a reliable way to translate documents, but I couldn’t find an automated solution that worked for me. DeepL didn’t seem worth the money, and ChatGPT or Microsoft Copilot couldn’t handle the file types I needed. Using cloud services also raised privacy concerns, especially with NDA-protected data. So, I developed my own solution—and you can too.

What do you need to do? Just ask. I wouldn't say you need zero knowledge to pull this off, but if you have a basic idea how one can use terminal and run a script you are good to go. I am also pretty sure ChatGPT will guide you there as well if you're a complete stranger. Just persist (haha, pun intended).

For example, I started with a simple request:

provide a solution to translate excel file from czech to english locally        

What I got was a simple step-by-step instructions, including commands and code I could copy.

Fancy adding a progress bar so you can track if it's running? Just ask!

how to print progress for this code?        

As simple as getting another command and updated code snipped.

Encountered an error? I don’t even bother reading the exception messages anymore. I just copy-paste them, and GPT provides the fix. Here’s one I received:

Traceback (most recent call last):
  File "/Users/mfedorko/Python/translator/translate_excel.py", line 32, in <module>
    df[col] = df[col].astype(str).progress_apply(safe_translate)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mfedorko/Python/translator/venv/lib/python3.12/site-packages/pandas/core/generic.py", line 6299, in __getattr__
    return object.__getattribute__(self, name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Series' object has no attribute 'progress_apply'         

So if you came all the way here just for the final result this is where I got:

import pandas as pd
from deep_translator import GoogleTranslator
from openpyxl import load_workbook
from tqdm import tqdm

# Initialize Google Translator
translator = GoogleTranslator(source='cs', target='en')

def safe_translate(text):
    try:
        return translator.translate(text) if text.strip() else text
    except Exception as e:
        print(f"Error translating '{text}': {e}")
        return text  # Return original text if translation fails

# Load the original Excel workbook with openpyxl
input_file_path = 'requirements.xlsx'  # Replace with your file path
output_file_path = 'requirements_en_styled.xlsx'  # Save translated file

# Load the Excel file using openpyxl to preserve styles
wb = load_workbook(input_file_path)
sheet_names = wb.sheetnames

# Iterate over each sheet in the workbook
for sheet_name in tqdm(sheet_names, desc="Sheets"):
    ws = wb[sheet_name]

    # Iterate through each cell in the sheet, translate, and retain styling
    for row in tqdm(ws.iter_rows(), desc=f"Translating rows in {sheet_name}", leave=False):
        for cell in row:
            if cell.value and isinstance(cell.value, str):
                original_value = cell.value
                translated_value = safe_translate(original_value)
                cell.value = translated_value  # Replace the text, keep formatting

# Save the workbook with the translated content
wb.save(output_file_path)

print(f"Translation completed with styles retained! Translated file saved as '{output_file_path}'.")        

It took only a few minutes to go from idea to working solution—definitely less time than writing this. All you need is an idea and a few minutes of your time. Stop reading crappy LinkedIn posts and go build something!

What's next

So, I’m not sure how clean this Python code is, nor do I think it’s a production-ready solution. But it solves a dreadful task I’ve done a million times and taught me something new along the way, and—honestly—I think it’s beautiful.

I believe everyone should try using tools like this. We are surrounded by technology daily. Interacting with code, and understanding how it works will only become more important.

As for what’s next for me? I’ve got a few ideas about how AI can further enhance my workflow. A locally run note-taker that summarizes meetings and emails them would be a lifesaver during long workshops.

And for fun? I’d love to create a custom F1 statistics library for the weirdest stats out there. Did you know that Narain Karthikeyan is the only F1 driver to finish 24th or lower? Hilarious, I know.

Till next time.

Michal Fedorko Very informative. Thanks for sharing

Like
Reply

To view or add a comment, sign in

Insights from the community

Others also viewed

Explore topics