Alternat is a tool that automates alt text generation.
Project description
alternat: Automate your image alt-text generation workflow.
Resources
- Homepage and Reference: https://alternat.readthedocs.io/
Description
alternat automates the image alt-text generation workflow by offering ready to use methods for downloading (Collection in alternat lingo) images and then generating alt-text.
alternat features are grouped into tasks - Collection and Generation
Collection
Collection offers convenience methods to download images. It uses puppeteer (headless chrome) to automate the website crawling and image download process
Generation
Generation offers convenience methods to generate alt-texts. It offers drivers to generate the alt-texts.
- Azure API - Uses Azure API for image captioning and OCR. Note Azure is a paid service.
- Google API - Uses google API for image captioning and OCR. Note google is a paid service.
- Open Source - Uses free open source alternative for OCR.
Supported Video and image file formats jpeg, jpg and png are supported.
Installation
Using pypi
- Install node (>=v.12)
- Install Python >= 3.8
- pip install alternat
Note 1: for Windows, please install torch and torchvision first by following the official instruction here https://pytorch.org. On pytorch website, be sure to select the right CUDA version you have. If you intend to run on CPU mode only, select CUDA = None. Or use Docker compose for running instructions here
- Install apify at alternat designated folder
For Windows go to setup_scripts and execute batch script
install_apify_window.bat
For Ubuntu/Linux goto setup_scripts and execute bash script
sudo sh install_apify_ubuntu.sh
For Mac execute following command
mkdir -p ~/.alternat && cd ~/.alternat && npm install apify && cd -
Install from source
- Install git
- Install node (>=v.12)
- Install python >= 3.8
- Open terminal or command prompt
- Clone repo from here https://github.com/keplerlab/alternat.git
- Change the directory to the directory where you have cloned your repo
$cd path_to_the_folder_repo_cloned
- Install apify at alternat designated folder
For Windows goto setup_scripts and execute batch script
install_apify_window.bat
For Ubuntu/Linux goto setup_scripts and execute bash script
sudo sh install_apify_ubuntu.sh
For Mac execute following command
mkdir -p ~/.alternat && cd ~/.alternat && npm install apify && cd -
- Go to setup_scripts folder and run the setup if alternat to be used as standalone application:
sh install_application_mode.sh
Run the setup if alternat to be used as service:
sh install_api_mode.sh
Note: For Windows run following batch files from setup_scripts folder instead of above bash scripts
install_application_mode_windows.bat
Run the setup if alternat to be used as service:
install_api_mode_windows.bat
Installation using Docker
-
Download and Install Docker Desktop for Mac using this link docker-desktop
-
Clone this repo https://github.com/keplerlab/alternat.git
-
Change your directory to your cloned repo.
-
Open terminal and run following commands
cd <path-to-repo> //you need to be in your repo folder
docker-compose build
- Start docker container using this command
docker-compose up
- In a new terminal window open terminal inside docker container for running alternat using command line type following command:
docker-compose exec alternat bash
- You can use this command line to execute collect or generate command line application like this .
Installation using Anaconda python
- Install node (>=v.12)
- Create conda environment and install dependencies using environment.yml file
conda env create -f environment.yml
For windows use environment_windows.yml file for conda env create
conda env create -f environment_windows.yml
- If you want to do image downloads from websites (collect step in alternat) using apify pupeeter you need to also first install nodejs and then goto folder apify. Run npm install:
cd <repo_path>
cd alternat/collection/apify
npm install
- Install apify at alternat designated folder
For Windows goto setup_scripts and execute batch script
install_apify_window.bat
For Ubuntu/Linux goto setup_scripts and execute bash script
sudo sh install_apify_ubuntu.sh
For Mac execute following command
mkdir -p ~/.alternat && cd ~/.alternat && npm install apify && cd -
Running generate task using command line:
If you want to generate alternate text for any image or folder containing multiple images, you can use Command line option which we call generation stage.
To run generation stage alone you can use following command:
# To run a single file, results will be collected under "results/generate"
# The image extensions supported are: .jpg, .jpeg, .png.
python app.py generate --output-dir-path="./results" --input-image-file-path="./sample/images_with_text/sample1.png"
or
# To run for entire directory, results will be collected under "results/generate"
# The image extensions supported are: .jpg, .jpeg, .png.
python app.py generate --input-dir-path="./sample/images_with_text" --output-dir-path="./results"
or
# To generate alt-text using specific driver (like azure, google or open source)
# Do not forget to add the credentials to their respective config files when using azure and google
# azure needs SUBSCRIPTION_KEY and ENDPOINT URL
# google needs ABSOLUTE_PATH_TO_CREDENTIALS_FILE (a credential json file)
python app.py generate --output-dir-path="./results" --input-image-file-path="./sample/images_with_text/sample1.png" --driver-config-file-path="./sample/generator_driver_conf/azure.json"
Sample images are located at sample/images and sample/images_with_text
Running collect task using command line:
First stage is called collection stage, it can be used to crawl and download images from any website or website url, to run the collection stage use following commands:
Use case: Download image from single page
# To run the collection
python app.py collect --collect-using-apify <WEBSITE_URL> ./DATADUMP
Use case: Download images recursively for a given site
# To run the collection
python app.py collect --collect-using-apify --download-recursive <WEBSITE_URL> ./DATADUMP
Knows Issue / Troubleshooting
- If you get error like Error: spawn wmic.exe ENOENT while running collect command (using apify) in alternat on Microsoft Windows This indicates that the wmic utility's directory is not found on your PATH. Open the advanced System Properties window (you can open the System page with Windows+Pause/Break) and on the Advanced tab, click Environment Variables. In the section for system variables, find PATH (or any capitalization thereof). Add this entry to it:
%SystemRoot%\System32\Wbem
Note that entries are delimited by semicolons.
Attributions
- For open source ocr we are using EasyOCR project https://github.com/JaidedAI/EasyOCR by Rakpong Kittinaradorn.
- For web crawling we are using apify wrapper over puppeteer library https://apify.com/.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file alternat-0.1.1.tar.gz
.
File metadata
- Download URL: alternat-0.1.1.tar.gz
- Upload date:
- Size: 27.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62db3683ae838abe86cc2b0b529171594a66771eb6e7670624bdb0fd830c6c75 |
|
MD5 | b3a215c1e1638211a360fc717279bc48 |
|
BLAKE2b-256 | 9260bcfd93bd40da1217762c2041cf45e0ca5df60e5dc4ec30c27387d982bb2a |
File details
Details for the file alternat-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: alternat-0.1.1-py3-none-any.whl
- Upload date:
- Size: 37.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4282bab92e2728db0a596012f638b5284e45edea9a189191497cfa7c088abac0 |
|
MD5 | d342891836186250252b45320bfce16d |
|
BLAKE2b-256 | 24fd203e32bb4a6e7b0dec31f7b2b1dc930f7b820490d5c70a4be53c5b3452ca |