class FaceSwapInterface: def __init__(self): self._parser = FullHelpArgumentParser() self._subparser = self._parser.add_subparsers() def extract(self, input_dir, output_dir, filter_path): extract = Extract(self._subparser, "extract", "Extract the faces from a pictures.") args_str = "extract --input-dir {} --output-dir {} --processes 1 --detector cnn --filter {}" args_str = args_str.format(input_dir, output_dir, filter_path) self._run_script(args_str) def train(self, input_a_dir, input_b_dir, model_dir, gan=False): model_type = "Original" if gan: model_type = "GAN" train = Train( self._subparser, "train", "This command trains the model for the two faces A and B.") args_str = "train --input-A {} --input-B {} --model-dir {} --trainer {} --batch-size {} --write-image" args_str = args_str.format(input_a_dir, input_b_dir, model_dir, model_type, 512) self._run_script(args_str) def _run_script(self, args_str): args = self._parser.parse_args(args_str.split(' ')) args.func(args)
def SPSort(context): args = context.args PARSER = FullHelpArgumentParser() SORT = cli.SortArgs( PARSER, "sort", "This command lets you sort images using various methods.") ARGUMENTS = PARSER.parse_args([ "--input", args.inputData, "--output", args.outputData, "--sort-by", args.sortBy, "--ref_threshold", str(args.refThreshold), "--final-process", args.finalProcess, "--group-by", args.groupBy, "--bins", str(args.bins), ]) ARGUMENTS.func(ARGUMENTS) return args.outputData
if sys.version_info[0] == 3 and sys.version_info[1] < 2: raise Exception("This program requires at least python3.2") def bad_args(args): """ Print help on bad arguments """ PARSER.print_help() exit(0) if __name__ == "__main__": _tools_warning = "Please backup your data and/or test the tool you want " _tools_warning += "to use with a smaller data set to make sure you " _tools_warning += "understand how it works." print(_tools_warning) PARSER = FullHelpArgumentParser() SUBPARSER = PARSER.add_subparsers() EFFMPEG = cli.EffmpegArgs(SUBPARSER, "effmpeg", "This command allows you to easily execute common ffmpeg tasks.") SORT = cli.SortArgs(SUBPARSER, "sort", "This command lets you sort images using various methods.") GUI = GuiArgs(SUBPARSER, "gui", "Launch the Faceswap Tools Graphical User Interface.") PARSER.set_defaults(func=bad_args) ARGUMENTS = PARSER.parse_args() ARGUMENTS.func(ARGUMENTS)
return retval @staticmethod def parse_time(txt): """ Parse Time """ clean_txt = txt.replace(':', '') hours = clean_txt[0:2] minutes = clean_txt[2:4] seconds = clean_txt[4:6] retval = hours + ':' + minutes + ':' + seconds logger.debug("txt: '%s', retval: %s", txt, retval) return retval def bad_args(args): # pylint: disable=unused-argument """ Print help on bad arguments """ PARSER.print_help() exit(0) if __name__ == "__main__": print('"Easy"-ffmpeg wrapper.\n') PARSER = FullHelpArgumentParser() SUBPARSER = PARSER.add_subparsers() EFFMPEG = cli.EffmpegArgs(SUBPARSER, "effmpeg", "Wrapper for various common ffmpeg commands.") PARSER.set_defaults(func=bad_args) ARGUMENTS = PARSER.parse_args() ARGUMENTS.func(ARGUMENTS)
raise Exception("This program requires at least python3.2") if sys.version_info[0] == 3 and sys.version_info[1] < 2: raise Exception("This program requires at least python3.2") from lib.cli import FullHelpArgumentParser from scripts.extract import ExtractTrainingData from scripts.train import TrainingProcessor from scripts.convert import ConvertImage def bad_args(args): parser.print_help() exit(0) if __name__ == "__main__": parser = FullHelpArgumentParser() subparser = parser.add_subparsers() extract = ExtractTrainingData(subparser, "extract", "Extract the faces from a pictures.") train = TrainingProcessor( subparser, "train", "This command trains the model for the two faces A and B.") convert = ConvertImage( subparser, "convert", "Convert a source image to a new one with the face swapped.") parser.set_defaults(func=bad_args) arguments = parser.parse_args() arguments.func(arguments)