cli package

The CLI Package handles the Command Line Arguments that act as the entry point into Faceswap.

args module

Module Summary

Module

actions module

Module Summary

ContextFullPaths

Adds support for context sensitive browser dialog opening in the GUI.

DirFullPaths

Adds support for a Directory browser in the GUI.

DirOrFileFullPaths

Adds support to the GUI to launch either a file browser or a folder browser.

FileFullPaths

Adds support for a File browser to select a single file in the GUI.

FilesFullPaths

Adds support for a File browser to select multiple files in the GUI.

MultiOption

Adds support for multiple option checkboxes in the GUI.

Radio

Adds support for a GUI Radio options box.

SaveFileFullPaths

Adds support for a Save File dialog in the GUI.

Slider

Adds support for a slider in the GUI.

Module

Custom argparse.Action objects for Faceswap’s Command Line Interface.

The custom actions within this module allow for custom manipulation of Command Line Arguments as well as adding a mechanism for indicating to the GUI how specific options should be rendered.

class lib.cli.actions.ContextFullPaths(*args, filetypes: str | None = None, action_option: str | None = None, **kwargs)

Bases: FileFullPaths

Adds support for context sensitive browser dialog opening in the GUI.

For some tasks, the type of action (file load, folder open, file save etc.) can vary depending on the task to be performed (a good example of this is the effmpeg tool). Using this action indicates to the GUI that the type of dialog to be launched can change depending on another option. As well as the standard parameters, the below parameters are required. NB: nargs are explicitly disallowed.

Parameters:
  • filetypes (str) – The accepted file types for this option. This is the key for the GUIs lookup table which can be found in lib.gui.utils.FileHandler

  • action_option (str) – The command line option that dictates the context of the file dialog to be opened. Bespoke actions are set in lib.gui.utils.FileHandler

Example

Assuming an argument has already been set with option string -a indicating the action to be performed, the following will pop a different type of dialog depending on the action selected:

>>> argument_list = []
>>> argument_list.append(dict(
>>>        opts=("-f", "--input_video"),
>>>        action=ContextFullPaths,
>>>        filetypes="video",
>>>        action_option="-a"))
class lib.cli.actions.DirFullPaths(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)

Bases: _FullPaths

Adds support for a Directory browser in the GUI.

This is a standard argparse.Action (with stock parameters) which indicates to the GUI that a dialog box should be opened in order to browse for a folder.

No additional parameters are required.

Example

>>> argument_list = []
>>> argument_list.append(dict(
>>>        opts=("-f", "--folder_location"),
>>>        action=DirFullPaths)),
class lib.cli.actions.DirOrFileFullPaths(*args, filetypes: str | None = None, **kwargs)

Bases: FileFullPaths

Adds support to the GUI to launch either a file browser or a folder browser.

Some inputs (for example source frames) can come from a folder of images or from a video file. This indicates to the GUI that it should place 2 buttons (one for a folder browser, one for a file browser) for file/folder browsing.

The standard argparse.Action is extended with the additional parameter filetypes, indicating to the GUI that it should pop a file browser, and limit the results to the file types listed. As well as the standard parameters, the following parameter is required:

Parameters:

filetypes (str) – The accepted file types for this option. This is the key for the GUIs lookup table which can be found in lib.gui.utils.FileHandler. NB: This parameter is only used for the file browser and not the folder browser

Example

>>> argument_list = []
>>> argument_list.append(dict(
>>>        opts=("-f", "--input_frames"),
>>>        action=DirOrFileFullPaths,
>>>        filetypes="video))"
class lib.cli.actions.DirOrFilesFullPaths(*args, filetypes: str | None = None, **kwargs)

Bases: FileFullPaths

Adds support to the GUI to launch either a file browser for selecting multiple files or a folder browser.

Some inputs (for example face filter) can come from a folder of images or from multiple image file. This indicates to the GUI that it should place 2 buttons (one for a folder browser, one for a multi-file browser) for file/folder browsing.

The standard argparse.Action is extended with the additional parameter filetypes, indicating to the GUI that it should pop a file browser, and limit the results to the file types listed. As well as the standard parameters, the following parameter is required:

Parameters:

filetypes (str) – The accepted file types for this option. This is the key for the GUIs lookup table which can be found in lib.gui.utils.FileHandler. NB: This parameter is only used for the file browser and not the folder browser

Example

>>> argument_list = []
>>> argument_list.append(dict(
>>>        opts=("-f", "--input_frames"),
>>>        action=DirOrFileFullPaths,
>>>        filetypes="video))"
class lib.cli.actions.FileFullPaths(*args, filetypes: str | None = None, **kwargs)

Bases: _FullPaths

Adds support for a File browser to select a single file in the GUI.

This extends the standard argparse.Action and adds an additional parameter filetypes, indicating to the GUI that it should pop a file browser for opening a file and limit the results to the file types listed. As well as the standard parameters, the following parameter is required:

Parameters:

filetypes (str) – The accepted file types for this option. This is the key for the GUIs lookup table which can be found in lib.gui.utils.FileHandler

Example

>>> argument_list = []
>>> argument_list.append(dict(
>>>        opts=("-f", "--video_location"),
>>>        action=FileFullPaths,
>>>        filetypes="video))"
class lib.cli.actions.FilesFullPaths(*args, filetypes: str | None = None, **kwargs)

Bases: FileFullPaths

Adds support for a File browser to select multiple files in the GUI.

This extends the standard argparse.Action and adds an additional parameter filetypes, indicating to the GUI that it should pop a file browser, and limit the results to the file types listed. Multiple files can be selected for opening, so the nargs parameter must be set. As well as the standard parameters, the following parameter is required:

Parameters:

filetypes (str) – The accepted file types for this option. This is the key for the GUIs lookup table which can be found in lib.gui.utils.FileHandler

Example

>>> argument_list = []
>>> argument_list.append(dict(
>>>        opts=("-f", "--images"),
>>>        action=FilesFullPaths,
>>>        filetypes="image",
>>>        nargs="+"))
class lib.cli.actions.MultiOption(*args, **kwargs)

Bases: Action

Adds support for multiple option checkboxes in the GUI.

This is a standard argparse.Action (with stock parameters) which indicates to the GUI that the options passed should be rendered as a group of Radio Buttons rather than a combo box.

The choices parameter must be provided as this provides the valid option choices.

Example

>>> argument_list = []
>>> argument_list.append(dict(
>>>        opts=("-f", "--foobar"),
>>>        action=MultiOption,
>>>        choices=["foo", "bar"))
class lib.cli.actions.Radio(*args, **kwargs)

Bases: Action

Adds support for a GUI Radio options box.

This is a standard argparse.Action (with stock parameters) which indicates to the GUI that the options passed should be rendered as a group of Radio Buttons rather than a combo box.

No additional parameters are required, but the choices parameter must be provided as these will be the Radio Box options. nargs are explicitly disallowed.

Example

>>> argument_list = []
>>> argument_list.append(dict(
>>>        opts=("-f", "--foobar"),
>>>        action=Radio,
>>>        choices=["foo", "bar"))
class lib.cli.actions.SaveFileFullPaths(*args, filetypes: str | None = None, **kwargs)

Bases: FileFullPaths

Adds support for a Save File dialog in the GUI.

This extends the standard argparse.Action and adds an additional parameter filetypes, indicating to the GUI that it should pop a save file browser, and limit the results to the file types listed. As well as the standard parameters, the following parameter is required:

Parameters:

filetypes (str) – The accepted file types for this option. This is the key for the GUIs lookup table which can be found in lib.gui.utils.FileHandler

Example

>>> argument_list = []
>>> argument_list.append(dict(
>>>        opts=("-f", "--video_out"),
>>>        action=SaveFileFullPaths,
>>>        filetypes="video"))
class lib.cli.actions.Slider(*args, min_max: tuple[int, int] | tuple[float, float] | None = None, rounding: int | None = None, **kwargs)

Bases: Action

Adds support for a slider in the GUI.

The standard argparse.Action is extended with the additional parameters listed below. The default value must be supplied and the type must be either int or float. nargs are explicitly disallowed.

Parameters:
  • min_max (tuple) – The (min, max) values that the slider’s range should be set to. The values should be a pair of float or int data types, depending on the data type of the slider. NB: These min/max values are not enforced, they are purely for setting the slider range. Values outside of this range can still be explicitly passed in from the cli.

  • rounding (int) – If the underlying data type for the option is a float then this value is the number of decimal places to round the slider values to. If the underlying data type for the option is an int then this is the step interval between each value for the slider.

Examples

For integer values:

>>> argument_list = []
>>> argument_list.append(dict(
>>>        opts=("-f", "--foobar"),
>>>        action=Slider,
>>>        min_max=(0, 10)
>>>        rounding=1
>>>        type=int,
>>>        default=5))

For floating point values:

>>> argument_list = []
>>> argument_list.append(dict(
>>>        opts=("-f", "--foobar"),
>>>        action=Slider,
>>>        min_max=(0.00, 1.00)
>>>        rounding=2
>>>        type=float,
>>>        default=5.00))

launcher module

Launches the correct script with the given Command Line Arguments

class lib.cli.launcher.ScriptExecutor(command: str)

Bases: object

Loads the relevant script modules and executes the script.

This class is initialized in each of the argparsers for the relevant command, then execute script is called within their set_default function.

Parameters:

command (str) – The faceswap command that is being executed

execute_script(arguments: argparse.Namespace) None

Performs final set up and launches the requested _command with the given command line arguments.

Monitors for errors and attempts to shut down the process cleanly on exit.

Parameters:

arguments (argparse.Namespace) – The command line arguments to be passed to the executing script.