Here is the link to the blog post on Image SEO using AI
This script uses Python with the Microsoft Computer Vision API (provided as part of the Microsoft Cognitive Services) to generate meta description for images stored on a WordPress website. You will need an API key from Microsoft and the export of your WordPress Media Library that can be done using the WordPress Export Tool. The result is a CSV file containing the URL of the image, the title of the image, the proposed description for the image and a confidence score. The script will skip the analysis if the description is already present in your media library.
Here is an example generated with the same code (you will also find a Jupyter Notebook to run quick tests in this repo): the description, in this case, is written on the image.
Not perfect, but still quite impressive.
To run the script simply download it and follow these steps:
- Login to your WordPress dashboard, and navigate to Tools Export.
- Choose to export Media content.
- Click Download Export File and the XML content will be downloaded in .xml format with a date on its file name.
2. Add your Microsoft Computer Vision API Key
- Update line 15
- Update line 30
If not use pip install
to install the libraries below:
- time
- requests
- operator
- numpy
- pandas
- xmltodict
- write
python generate-descriptions.py
The script will generate a file called out.csv that contains a list of the processed images containing their original title, the url of the image, the metadescription generated by the Computer Vision API and a confidence score (this will come handy when you will have to choose if it's worth keeping what the CV has suggested).
I highly recommend to validate the results before importing the data back into your CMS. Google Sheet is a perfect way to help you revise and update the captions generated for your images.
In Google Sheet, you can use the function image(URL)
to display the image in a cell.
The code is free and licensed with the Apache 2.0 License.