Generate image description and tags with the help of computer vision (inspired by altify).
- Python 2.7+ / Python 3.5+
- Wagtail 1.7+
- Access to any of the supported providers
Install the library with pip:
$ pip install wagtailaltgenerator
Depending on your selected provider, you might also need extra requirements (example pip install wagtailaltgenerator[rekognition]
. Please check the install instructions for the various providers below.
-
Install
pip install wagtailaltgenerator
-
Register an account on Microsoft Cognitive Service
-
Retrieve API key for the product
Computer Vision - Preview
-
Add the key to your django settings:
COMPUTER_VISION_API_KEY = 'yourkey'
-
Make sure
wagtailaltgenerator
is added to yourINSTALLED_APPS
.INSTALLED_APPS = ( # ... 'wagtailaltgenerator', )
- Upload an image through Wagtail
- Watch the title and/or tags get generated...
- ...And done!
ALT_GENERATOR_USE_TAGS
: Enable/disable image tags (True
by default)ALT_GENERATOR_MAX_TAGS
: The maximum amount of tags to use from service (default-1
, unlimited)ALT_GENERATOR_PROVIDER
: The provider you would like to use (wagtailaltgenerator.providers.cognitive.Cognitive
is default)ALT_GENERATOR_MIN_CONFIDENCE
: The minimum accepted percentage of confidence the provider has in describing the image (default0
, accept any).ALT_GENERATOR_PREFER_UPLOAD
: If you want your provider to read asset by url, or through binary upload (defaultTrue
, always try to post image). Only Cognitive Services supports both choices this.
Microsoft's computer vision API. Docs
- (+) Supports both tags and descriptions
- (-) Service still in preview
- (-) Requires monthly API key rotation
ALT_GENERATOR_PROVIDER
:'wagtailaltgenerator.providers.cognitive.Cognitive'
COMPUTER_VISION_API_KEY
: Microsoft Cognitive Services API key
Amazon's image analysis API. Docs
- (+) Stable
- (-) Supports only tags
Add ...[rekognition]
when you install wagtailaltgenerator (this will install the extra packages required).
pip install wagtailaltgenerator[rekognition]
The Rekognition provider is based on boto and uses its configuration.
These are three of the most common settings:
AWS_ACCESS_KEY_ID
: The access key for your AWS accountAWS_SECRET_ACCESS_KEY
: The secret key for your AWS accountAWS_DEFAULT_REGION
: The default region to use, e.g. us-west-2, eu-west-1, etc
You also need to define the provider:
ALT_GENERATOR_PROVIDER
:'wagtailaltgenerator.providers.rekognition.Rekognition'
Google's Cloud Vision API docs.
- (+) Stable
- (-) Support only tags
pip install wagtailaltgenerator[google_vision]
The Google Vision provider is based on google-api-python-client
and are typically done using Application Default Credentials for authentication.
You can authenticate locally with the Google Cloud SDK, on production with either the built in credentials (if you already run on Google Cloud) or with a Service Account key file.
You also need to define the provider:
ALT_GENERATOR_PROVIDER
:'wagtailaltgenerator.providers.google_vision.GoogleVision'
This library include tests for the different providers.
- Make sure to install dev requirements:
pip install -r requirements/tests.txt
- Copy test_vars.sh and fill in the blanks
cp test_vars.example.sh test_vars.sh
- Run tests:
source test_vars.sh && python runtests.py
You can also run separate test cases: runtests.py tests.test_cognitive_service.CognitiveServiceTest
These hooks will automatically bump the application version when using git flow release ...
chmod +x $PWD/git-hooks/release-start.sh
ln -nfs $PWD/git-hooks/release-start.sh .git/hooks/post-flow-release-start
ln -nfs $PWD/git-hooks/release-start.sh .git/hooks/post-flow-hotfix-start
python setup.py egg_info
twine register dist/mypkg.wh
python setup.py sdist
twine upload dist/*
Want to contribute? Awesome. Just send a pull request.
Wagtail-alt-generator is released under the MIT License.