autoAlt is a demo R package for automatically generating alt-text from QMD and RMD files. It includes the generate_alt_text() function, which uses Ellmer and BrailleR to create alt-text for plots in your documents.
You can install the development version from GitHub:
remotes::install_github("numbats/autoAlt")
It depends on having BrailleR which needs to be installed from GitHub.
To get started, you will need to get an API key for OpenAI from https://platform.openai.com/api-keys.
Provide the file path and name for the qmd or Rmd file you want to process, and an output file path and name. Ensure that all code required to generate graphics is included in the same file. This github repo comes with a test.qmd file in the inst folder to get you started.
autoalt::generate_alt_text("inst/test.qmd", "inst/test-out.txt", api = api)
The generate_alt_text() function scans the document for code chunks containing ggplot, geom, and aes, identifying the source code that generates plots. It extracts the chunk label and uses it to locate the corresponding reference paragraph in the text, and sends requests to ChatGPT via Ellmer, combining: the output from BrailleR (when applicable), and a custom system prompt.
In cases where the example is not self-contained, OpenAI’s code interpreter is used in place of BrailleR to understand the code and generate alt-text. Output will be saved in a separate alt-text.txt file as seen below. The generated alt-text is saved in a separate file called alt-text.txt, as shown below:
