2022-09-11 20:57:15 +00:00
SHELL := /bin/bash
python_version = 3.10.6
venv_prefix = imaginairy
venv_name = $( venv_prefix) -$( python_version)
pyenv_instructions = https://github.com/pyenv/pyenv#installation
pyenv_virt_instructions = https://github.com/pyenv/pyenv-virtualenv#pyenv-virtualenv
init : require_pyenv ## Setup a dev environment for local development.
@pyenv install $( python_version) -s
@echo -e " \033[0;32m ✔️ 🐍 $( python_version) installed \033[0m "
@if ! [ -d " $$ (pyenv root)/versions/ $( venv_name) " ] ; then \
pyenv virtualenv $( python_version) $( venv_name) ; \
fi ;
@pyenv local $( venv_name)
@echo -e " \033[0;32m ✔️ 🐍 $( venv_name) virtualenv activated \033[0m "
pip install --upgrade pip pip-tools
pip-sync requirements-dev.txt
2022-09-13 07:27:53 +00:00
pip install -e . --no-deps
2022-09-11 20:57:15 +00:00
@echo -e "\nEnvironment setup! ✨ 🍰 ✨ 🐍 \n\nCopy this path to tell PyCharm where your virtualenv is. You may have to click the refresh button in the pycharm file explorer.\n"
@echo -e "\033[0;32m"
@pyenv which python
@echo -e "\n\033[0m"
@echo -e "The following commands are available to run in the Makefile\n"
@make -s help
af : autoformat ## Alias for `autoformat`
autoformat : ## Run the autoformatter.
2022-10-06 06:13:48 +00:00
@pycln . --all --quiet --extend-exclude __init__\. py
2022-09-11 20:57:15 +00:00
@isort --atomic --profile black .
@black .
test : ## Run the tests.
@pytest
@echo -e "The tests pass! ✨ 🍰 ✨"
lint : ## Run the code linter.
@pylama
@echo -e "No linting errors - well done! ✨ 🍰 ✨"
deploy : ## Deploy the package to pypi.org
pip install twine wheel
-git tag $$ ( python setup.py -V)
git push --tags
2022-09-12 05:24:02 +00:00
rm -rf dist
2022-09-11 20:57:15 +00:00
python setup.py bdist_wheel
2022-09-12 05:22:43 +00:00
#python setup.py sdist
2022-09-11 20:57:15 +00:00
@echo 'pypi.org Username: '
2022-10-04 12:43:40 +00:00
@read username && twine upload --verbose dist/* -u $$ username;
2022-09-11 20:57:15 +00:00
rm -rf build
rm -rf dist
@echo "Deploy successful! ✨ 🍰 ✨"
2022-09-22 05:03:12 +00:00
build-dev-image :
docker build -f tests/Dockerfile -t imaginairy-dev .
run-dev : build -dev -image
docker run -it -v $$ HOME/.cache/huggingface:/root/.cache/huggingface -v $$ HOME/.cache/torch:/root/.cache/torch -v ` pwd ` /outputs:/outputs imaginairy-dev /bin/bash
2022-09-11 20:57:15 +00:00
requirements : ## Freeze the requirements.txt file
pip-compile setup.py requirements-dev.in --output-file= requirements-dev.txt --upgrade
require_pyenv :
@if ! [ -x " $$ (command -v pyenv) " ] ; then \
echo -e '\n\033[0;31m ❌ pyenv is not installed. Follow instructions here: $(pyenv_instructions)\n\033[0m' ; \
exit 1; \
else \
echo -e "\033[0;32m ✔️ pyenv installed\033[0m" ; \
fi
@if ! [ [ " $$ (pyenv virtualenv --version) " = = *"pyenv-virtualenv" * ] ] ; then \
echo -e '\n\033[0;31m ❌ pyenv virtualenv is not installed. Follow instructions here: $(pyenv_virt_instructions) \n\033[0m' ; \
exit 1; \
else \
echo -e "\033[0;32m ✔️ pyenv-virtualenv installed\033[0m" ; \
fi
2022-09-12 05:22:43 +00:00
vendor_openai_clip :
mkdir -p ./downloads
-cd ./downloads && git clone git@github.com:openai/CLIP.git
cd ./downloads/CLIP && git pull
rm -rf ./imaginairy/vendored/clip
cp -R ./downloads/CLIP/clip imaginairy/vendored/
git --git-dir ./downloads/CLIP/.git rev-parse HEAD | tee ./imaginairy/vendored/clip/clip-commit-hash.txt
echo "vendored from git@github.com:openai/CLIP.git" | tee ./imaginairy/vendored/clip/readme.txt
2022-09-18 00:02:45 +00:00
revendorize : vendorize_kdiffusion
2022-09-14 07:40:25 +00:00
make vendorize REPO = git@github.com:openai/CLIP.git PKG = clip COMMIT = d50d76daa670286dd6cacf3bcd80b5e4823fc8e1
2022-09-18 00:02:45 +00:00
make af
vendorize_clipseg :
2022-09-28 06:15:34 +00:00
make download_repo REPO = git@github.com:timojl/clipseg.git PKG = clipseg COMMIT = ea54753df1e444c4445bac6e023546b6a41951d8
2022-09-18 00:02:45 +00:00
rm -rf ./imaginairy/vendored/clipseg
mkdir -p ./imaginairy/vendored/clipseg
cp -R ./downloads/clipseg/models/* ./imaginairy/vendored/clipseg/
sed -i '' -e 's#import clip#from imaginairy.vendored import clip#g' ./imaginairy/vendored/clipseg/clipseg.py
rm ./imaginairy/vendored/clipseg/vitseg.py
mv ./imaginairy/vendored/clipseg/clipseg.py ./imaginairy/vendored/clipseg/__init__.py
2022-09-28 06:15:34 +00:00
# download weights
rm -rf ./downloads/clipseg-weights
mkdir -p ./downloads/clipseg-weights
wget https://owncloud.gwdg.de/index.php/s/ioHbRzFx6th32hn/download -O ./downloads/clipseg-weights/weights.tar
cd downloads/clipseg-weights && unzip -d weights -j weights.tar
cp ./downloads/clipseg-weights/weights/rd64-uni-refined.pth ./imaginairy/vendored/clipseg/
2022-09-18 00:02:45 +00:00
2022-09-20 04:15:38 +00:00
vendorize_blip :
make download_repo REPO = git@github.com:salesforce/BLIP.git PKG = blip COMMIT = 48211a1594f1321b00f14c9f7a5b4813144b2fb9
rm -rf ./imaginairy/vendored/blip
mkdir -p ./imaginairy/vendored/blip
cp -R ./downloads/blip/models/* ./imaginairy/vendored/blip/
cp -R ./downloads/blip/configs ./imaginairy/vendored/blip/
sed -i '' -e 's#from models\.#from imaginairy.vendored.blip.#g' ./imaginairy/vendored/blip/blip.py
sed -i '' -e 's#print(#\# print(#g' ./imaginairy/vendored/blip/blip.py
2022-09-18 00:02:45 +00:00
vendorize_kdiffusion :
2022-10-15 00:21:38 +00:00
rm -rf ./imaginairy/vendored/k_diffusion
rm -rf ./downloads/k_diffusion
# version 0.0.9
2022-11-11 18:16:59 +00:00
make vendorize REPO = git@github.com:crowsonkb/k-diffusion.git PKG = k_diffusion COMMIT = 60e5042ca0da89c14d1dd59d73883280f8fce991
2022-09-18 00:02:45 +00:00
#sed -i '' -e 's/import\sclip/from\simaginairy.vendored\simport\sclip/g' imaginairy/vendored/k_diffusion/evaluation.py
2022-10-15 00:21:38 +00:00
mv ./downloads/k_diffusion/LICENSE ./imaginairy/vendored/k_diffusion/
2022-09-14 07:40:25 +00:00
rm imaginairy/vendored/k_diffusion/evaluation.py
touch imaginairy/vendored/k_diffusion/evaluation.py
rm imaginairy/vendored/k_diffusion/config.py
touch imaginairy/vendored/k_diffusion/config.py
# without this most of the k-diffusion samplers didn't work
2022-09-14 16:37:45 +00:00
sed -i '' -e 's#return (x - denoised) / utils.append_dims(sigma, x.ndim)#return (x - denoised) / sigma#g' imaginairy/vendored/k_diffusion/sampling.py
sed -i '' -e 's#x = x + torch.randn_like(x) \* sigma_up#x = x + torch.randn_like(x, device="cpu").to(x.device) \* sigma_up#g' imaginairy/vendored/k_diffusion/sampling.py
2022-09-14 07:40:25 +00:00
make af
2022-09-13 16:12:47 +00:00
feature: prompt expansion (#51)
You can use `{}` to randomly pull values from lists. A list of values separated by `|` and enclosed in `{ }` will be randomly drawn from in a non-repeating fashion. Values that are surrounded by `_ _` will pull from a phrase list of the same name. Folders containing .txt phraselist files may be specified via
`--prompt_library_path`. The option may be specified multiple times. Built-in categories:
3d-term, adj-architecture, adj-beauty, adj-detailed, adj-emotion, adj-general, adj-horror, animal, art-movement,
art-site, artist, artist-botanical, artist-surreal, aspect-ratio, bird, body-of-water, body-pose, camera-brand,
camera-model, color, cosmic-galaxy, cosmic-nebula, cosmic-star, cosmic-term, dinosaur, eyecolor, f-stop,
fantasy-creature, fantasy-setting, fish, flower, focal-length, food, fruit, games, gen-modifier, hair, hd,
iso-stop, landscape-type, national-park, nationality, neg-weight, noun-beauty, noun-fantasy, noun-general,
noun-horror, occupation, photo-term, pop-culture, pop-location, punk-style, quantity, rpg-item, scenario-desc,
skin-color, spaceship, style, tree-species, trippy, world-heritage-site
Examples:
`imagine "a {red|black} dog" -r 2 --seed 0` will generate both "a red dog" and "a black dog"
`imagine "a {_color_} dog" -r 4 --seed 0` will generate four, different colored dogs. The colors will eb pulled from an included
phraselist of colors.
`imagine "a {_spaceship_|_fruit_|hot air balloon}. low-poly" -r 4 --seed 0` will generate images of spaceships or fruits or a hot air balloon
Credit to [noodle-soup-prompts](https://github.com/WASasquatch/noodle-soup-prompts/) where most, but not all, of the wordlists originate.
2022-10-09 01:34:35 +00:00
vendorize_noodle_soup :
make download_repo REPO = git@github.com:WASasquatch/noodle-soup-prompts.git PKG = noodle-soup-prompts COMMIT = 5642feb4d0e1340b9d145f5ff64f2b57eab1ae71
mkdir -p ./imaginairy/vendored/noodle_soup_prompts
rm ./imaginairy/vendored/noodle_soup_prompts/*
mv ./downloads/noodle-soup-prompts/LICENSE ./imaginairy/vendored/noodle_soup_prompts/
python scripts/prep_vocab_lists.py
make af
2022-09-13 07:27:53 +00:00
vendorize : ## vendorize a github repo. `make vendorize REPO=git@github.com:openai/CLIP.git PKG=clip`
mkdir -p ./downloads
-cd ./downloads && git clone $( REPO) $( PKG)
2022-09-14 07:40:25 +00:00
cd ./downloads/$( PKG) && git fetch && git checkout $( COMMIT)
2022-09-13 07:27:53 +00:00
rm -rf ./imaginairy/vendored/$( PKG)
cp -R ./downloads/$( PKG) /$( PKG) imaginairy/vendored/
2022-10-15 00:21:38 +00:00
git --git-dir ./downloads/$( PKG) /.git rev-parse HEAD | tee ./imaginairy/vendored/$( PKG) /source-commit-hash.txt
2022-09-13 07:27:53 +00:00
touch ./imaginairy/vendored/$( PKG) /version.py
echo " vendored from $( REPO) " | tee ./imaginairy/vendored/$( PKG) /readme.txt
2022-09-18 00:02:45 +00:00
download_repo :
mkdir -p ./downloads
2022-09-28 06:15:34 +00:00
rm -rf ./downloads/$( PKG)
2022-09-18 00:02:45 +00:00
-cd ./downloads && git clone $( REPO) $( PKG)
cd ./downloads/$( PKG) && git pull
2022-09-13 07:27:53 +00:00
vendorize_whole_repo :
mkdir -p ./downloads
-cd ./downloads && git clone $( REPO) $( PKG)
cd ./downloads/$( PKG) && git pull
rm -rf ./imaginairy/vendored/$( PKG)
cp -R ./downloads/$( PKG) imaginairy/vendored/
git --git-dir ./downloads/$( PKG) /.git rev-parse HEAD | tee ./imaginairy/vendored/$( PKG) /clip-commit-hash.txt
touch ./imaginairy/vendored/$( PKG) /version.py
echo " vendored from $( REPO) " | tee ./imaginairy/vendored/$( PKG) /readme.txt
2022-09-12 05:22:43 +00:00
2022-09-11 20:57:15 +00:00
help : ## Show this help message.
@## https://gist.github.com/prwhite/8168133#gistcomment-1716694
@echo -e " $$ (grep -hE '^\S+:.*##' $( MAKEFILE_LIST) | sed -e 's/:.*##\s*/:/' -e 's/^\(.\+\):\(.*\)/\\x1b[36m\1\\x1b[m:\2/' | column -c2 -t -s :) " | sort