pycivitai.manager.model
ModelManager
- class pycivitai.manager.model.ModelManager(root_dir: str, model_name_or_id: Union[str, int], creator: Optional[str] = None, model_data: Optional[dict] = None, offline: bool = False)[source]
Management of specific model.
- __init__(root_dir: str, model_name_or_id: Union[str, int], creator: Optional[str] = None, model_data: Optional[dict] = None, offline: bool = False)[source]
Manages multiple versions of a model downloaded from civitai.com.
- Parameters:
root_dir – The root directory where the model versions will be managed.
model_name_or_id – The name or ID of the model to manage.
creator – Name of creator.
None
means anyone.model_data – Optional dictionary containing model information to avoid fetching it from the API.
offline – If True, the manager operates in offline mode, using locally downloaded resources.
- __weakref__
list of weak references to the object (if defined)
- delete_version(version: Optional[Union[int, str]] = None)[source]
Delete the specified model version from the local storage.
- Parameters:
version (Union[str, int, None]) – The version ID or name to delete. If None, the latest version is deleted.
- Raises:
LocalVersionNotFound – If the specified version is not found locally.
- get_file(version: Optional[Union[int, str]] = None, pattern: Optional[str] = None)[source]
Get the local file path of the specified model file.
- Parameters:
version (Union[str, int, None]) – The version ID or name of the model version. If None, the latest version is used.
pattern (str) – The pattern or name of the file to get. If None, the primary file will be returned.
- Returns:
The local path of the specified model file.
- Return type:
str
- Raises:
LocalVersionNotFound – If the specified version is not found locally.
LocalVersionDuplicated – If multiple versions matching the version parameter are found locally.
- list_versions() List[VersionManager] [source]
List all the local model versions managed by this ModelManager.
- Returns:
A list of VersionManager objects, one for each version.
- Return type:
List[VersionManager]
- property total_size: int
Get the total size of all the local model files managed by this ModelManager.
- Returns:
The total size in bytes.
- Return type:
int