File size: 1,410 Bytes
69a6cef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from functools import partial
from typing import Optional

import click
from ditk import logging
from gchar.utils import GLOBAL_CONTEXT_SETTINGS
from gchar.utils import print_version as _origin_print_version

from .tags import save_recommended_tags

print_version = partial(_origin_print_version, 'cyberharem.dataset')


@click.group(context_settings={**GLOBAL_CONTEXT_SETTINGS}, help='Publish trained models')
@click.option('-v', '--version', is_flag=True, callback=print_version, expose_value=False, is_eager=True)
def cli():
    pass  # pragma: no cover


@cli.command('retag', context_settings={**GLOBAL_CONTEXT_SETTINGS}, help='Regenerate tags for given work directory.')
@click.option('-w', '--workdir', 'workdir', type=click.Path(file_okay=False, exists=True), required=True,
              help='Work directory for experiment.', show_default=True)
@click.option('-n', '--name', 'name', type=str, default=None,
              help='Name of the character.', show_default=True)
def retag(workdir, name: Optional[str] = None):
    logging.try_init_root(logging.INFO)

    from ..publish.steps import find_steps_in_workdir
    pt_name, _ = find_steps_in_workdir(workdir)
    name = name or '_'.join(pt_name.split('_')[:-1])

    logging.info(f'Regenerate tags for {name!r}, on {workdir!r}.')
    save_recommended_tags(name, workdir=workdir)
    logging.info('Success!')


if __name__ == '__main__':
    cli()