Skip to content

Commit 5b56f05

Browse files
committed
feature: print version
- fix: default config wasn't being selected for custom models
1 parent 9b1d130 commit 5b56f05

9 files changed

+53
-8
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ tests/vastai_cli.py
2525
*.kgrind
2626
*.pyprof
2727
**/.polyscope.ini
28-
**/imgui.ini
28+
**/imgui.ini
29+
**/.eggs

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ docker run -it --gpus all -v $HOME/.cache/huggingface:/root/.cache/huggingface -
253253
## ChangeLog
254254

255255
**7.6.0**
256+
- fix: default model config was broken
257+
- feature: print version with `--version`
256258
- feature: ability to load safetensors
257-
258-
**7.5.0**
259259
- feature: 🎉 outpainting. Examples: `--outpaint up10,down300,left50,right50` or `--outpaint all100` or `--outpaint u100,d200,l300,r400`
260260

261261
**7.4.3**

imaginairy/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
LazyLoadingImage,
1313
WeightedPrompt,
1414
)
15+
from .version import __version__ # noqa
1516

1617
# https://stackoverflow.com/questions/71738218/module-pil-has-not-attribute-resampling
1718
if not hasattr(PIL.Image, "Resampling"): # Pillow<9.0

imaginairy/cmds.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
import click
66
from click_shell import shell
77

8-
from imaginairy import LazyLoadingImage, config, generate_caption
8+
from imaginairy import LazyLoadingImage, __version__, config, generate_caption
99
from imaginairy.api import imagine_image_files
10-
from imaginairy.config import MODEL_SHORT_NAMES
1110
from imaginairy.enhancers.prompt_expansion import expand_prompts
1211
from imaginairy.log_utils import configure_logging
1312
from imaginairy.samplers import SAMPLER_TYPE_OPTIONS
@@ -198,7 +197,7 @@
198197
@click.option(
199198
"--model-weights-path",
200199
"--model",
201-
help=f"Model to use. Should be one of {', '.join(MODEL_SHORT_NAMES)}, or a path to custom weights.",
200+
help=f"Model to use. Should be one of {', '.join(config.MODEL_SHORT_NAMES)}, or a path to custom weights.",
202201
show_default=True,
203202
default=config.DEFAULT_MODEL,
204203
)
@@ -215,6 +214,12 @@
215214
default=None,
216215
multiple=True,
217216
)
217+
@click.option(
218+
"--version",
219+
default=False,
220+
is_flag=True,
221+
help="Print the version and exit.",
222+
)
218223
@click.pass_context
219224
def imagine_cmd(
220225
ctx,
@@ -249,11 +254,16 @@ def imagine_cmd(
249254
model_weights_path,
250255
model_config_path,
251256
prompt_library_path,
257+
version, # noqa
252258
):
253259
"""Have the AI generate images. alias:imagine."""
254260
if ctx.invoked_subcommand is not None:
255261
return
256262

263+
if version:
264+
print(__version__)
265+
return
266+
257267
if quiet:
258268
log_level = "ERROR"
259269
configure_logging(log_level)
@@ -329,6 +339,12 @@ def aimg():
329339
pass
330340

331341

342+
@aimg.command()
343+
def version():
344+
"""Print the version."""
345+
print(__version__)
346+
347+
332348
@click.argument("image_filepaths", nargs=-1)
333349
@aimg.command()
334350
def describe(image_filepaths):
@@ -381,7 +397,7 @@ def describe(image_filepaths):
381397
"--model-weights-path",
382398
"--model",
383399
"model",
384-
help=f"Model to use. Should be one of {', '.join(MODEL_SHORT_NAMES)}, or a path to custom weights.",
400+
help=f"Model to use. Should be one of {', '.join(config.MODEL_SHORT_NAMES)}, or a path to custom weights.",
385401
show_default=True,
386402
default=config.DEFAULT_MODEL,
387403
)

imaginairy/model_manager.py

+3
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ def resolve_model_paths(
241241

242242
if model_metadata_c:
243243
config_path = model_metadata_c.config_path
244+
245+
if config_path is None:
246+
config_path = iconfig.MODEL_CONFIG_SHORTCUTS[iconfig.DEFAULT_MODEL].config_path
244247
model_metadata = model_metadata_w or model_metadata_c
245248
logger.debug(f"Loading model weights from: {weights_path}")
246249
logger.debug(f"Loading model config from: {config_path}")

imaginairy/version.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from importlib.metadata import PackageNotFoundError, version
2+
3+
try:
4+
__version__ = version("imaginairy")
5+
except PackageNotFoundError:
6+
__version__ = None

tests/test_model_manager.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from imaginairy import config
2+
from imaginairy.model_manager import resolve_model_paths
3+
4+
5+
def test_resolved_paths():
6+
"""Test that the resolved model path is correct."""
7+
model_metadata, weights_path, config_path = resolve_model_paths()
8+
assert model_metadata.short_name == config.DEFAULT_MODEL
9+
assert model_metadata.config_path == config_path
10+
default_config_path = config_path
11+
12+
model_metadata, weights_path, config_path = resolve_model_paths(
13+
weights_path="foo.ckpt"
14+
)
15+
assert weights_path == "foo.ckpt"
16+
assert config_path == default_config_path

tests/test_outpaint.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
from imaginairy import ImaginePrompt, LazyLoadingImage, imagine
44
from imaginairy.outpaint import outpaint_arg_str_parse
5+
from imaginairy.utils import get_device
56
from tests import TESTS_FOLDER
67
from tests.utils import assert_image_similar_to_expectation
78

89

10+
@pytest.mark.skipif(get_device() == "cpu", reason="Too slow to run on CPU")
911
def test_outpainting_outpaint(filename_base_for_outputs):
1012
img = LazyLoadingImage(
1113
filepath=f"{TESTS_FOLDER}/data/girl_with_a_pearl_earring.jpg"

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ filterwarnings =
88

99
[pylama]
1010
format = pylint
11-
skip = */.tox/*,*/.env/*,build/*,*/downloads/*,other/*,prolly_delete/*,downloads/*,imaginairy/vendored/*,testing_support/vastai_cli_official.py
11+
skip = */.tox/*,*/.env/*,build/*,*/downloads/*,other/*,prolly_delete/*,downloads/*,imaginairy/vendored/*,testing_support/vastai_cli_official.py,.eggs/*
1212
linters = pylint,pycodestyle,pyflakes,mypy
1313
ignore =
1414
Z999,C0103,C0301,C0302,C0114,C0115,C0116,

0 commit comments

Comments
 (0)