async function initAltImageDetection() {
  try {
    Array.from(document.querySelectorAll('img')).forEach(function (img) {
      if (!img.getAttribute('alt')) {
        img.setAttribute('crossorigin', 'anonymous');
        mobilenet.load().then((model) => {
          model.classify(img).then((predictions) => {
            img.setAttribute('alt', predictions[0].className);
          });
        });
      }
    });
  } catch (error) {
    console.error(error);
  }
}

document.addEventListener('DOMContentLoaded', () => {
  initAltImageDetection();
});
