Skip to content

Commit

Permalink
Version Bump
Browse files Browse the repository at this point in the history
  • Loading branch information
regiellis committed Nov 20, 2024
1 parent 8baf6d6 commit b1109c1
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 33 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## All notable changes to this project will be documented in this file

### [1.2.0] - 2024-9-27

- **Fix**: Fix formatting issues in README.md. Version bump to 1.2.0.

### [1.1.0] - 2024-9-27

- **Fix**: Fix issue with static files not be available when installing via pipx.
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# InvokeAI Models CLI

[![PyPI](https://img.shields.io/pypi/v/invokeai-models)](https://pypi.org/project/invokeai-models-cli/)
[![Python Versions](https://img.shields.io/pypi/pyversions/invokeai-models)](https://pypi.org/project/invokeai-models-cli/)
[![PyPI](https://img.shields.io/pypi/v/invokeai-models-cli)](https://pypi.org/project/invokeai-models-cli/)
[![Python Versions](https://img.shields.io/pypi/pyversions/invokeai-models-cli)](https://pypi.org/project/invokeai-models-cli/)

> [!NOTE]
> Project features were driven by personal needs and not a sense to create a general-purpose tool. As such, the tool may not be suitable for all use cases. Please use it with caution and always back up your data before making any changes. It is not intended to replace the official Invoke AI web UI but provides additional functionality for managing orphaned models.
> This project feature set were driven by personal needs and not a sense to create a general-purpose tool. As such, the tool may not be suitable for all use cases. Please use it with caution and always back up your data before making any changes. It is not intended to replace the official Invoke AI web UI but provides additional functionality for managing orphaned models.
**InvokeAI Models CLI** is a simplified command-line tool for managing orphaned Invoke AI models left in the database after their external sources have been deleted. This tool allows you to list, compare, and delete models automatically or via an interactive selection menu.

## Why Use This Tool?
![screenshot](https://raw.githubusercontent.com/regiellis/invokeai-models-cli/main/screen.png)


This tool addresses a personal pain point with unmanaged external models not handled by Invoke AI. It is not intended to replace the official Invoke AI web UI but provides additional functionality for managing orphaned models.

## Installation

Expand Down
6 changes: 5 additions & 1 deletion invokeai_models_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os
import inquirer
import importlib.resources
from pathlib import Path
from typing import Final
from dotenv import load_dotenv, set_key
import typer
import platform

from .helpers import feedback_message
from .helpers import feedback_message, ensure_snapshots_dir


def get_required_input(prompt: str) -> str:
Expand Down Expand Up @@ -163,3 +164,6 @@ def load_environment_variables() -> None:
INVOKE_AI_DIR: Final = os.environ["INVOKE_AI_DIR"]
MODELS_DIR: Final = os.environ["MODELS_DIR"]
SNAPSHOTS: Final = os.environ["SNAPSHOTS"]

SNAPSHOTS_DIR = Path(importlib.resources.files("invokeai_models_cli")) / "snapshots"
ensure_snapshots_dir(SNAPSHOTS_DIR)
2 changes: 1 addition & 1 deletion invokeai_models_cli/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.1.0"
__version__ = "1.2.0"
29 changes: 9 additions & 20 deletions invokeai_models_cli/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
# Get the package directory
PACKAGE_DIR = os.path.dirname(os.path.abspath(__file__))
DATABASE_PATH = os.path.join(INVOKE_AI_DIR, "databases", "invokeai.db")
SNAPSHOTS_DIR = os.path.join(PACKAGE_DIR, "snapshots")
SNAPSHOTS_JSON = os.path.join(SNAPSHOTS_DIR, "snapshots.json")
MODELS_INDEX_JSON = os.path.join(SNAPSHOTS_DIR, "models-index.json")
SNAPSHOTS_DIR = importlib.resources.files("invokeai_models_cli") / "snapshots"
SNAPSHOTS_JSON = SNAPSHOTS_DIR / "snapshots.json"
MODELS_INDEX_JSON = SNAPSHOTS_DIR / "models-index.json"

__all__ = [
"create_snapshot",
Expand Down Expand Up @@ -174,10 +174,14 @@ def create_snapshot() -> None:

def load_snapshots():
try:
with importlib.resources.open_text('invokeai_models_cli.snapshots', 'snapshots.json') as f:
with importlib.resources.open_text(
"invokeai_models_cli.snapshots", "snapshots.json"
) as f:
return json.load(f)
except FileNotFoundError:
console.print("[bold yellow]Warning:[/bold yellow] Snapshots file not found. Starting with an empty list.")
console.print(
"[bold yellow]Warning:[/bold yellow] Snapshots file not found. Starting with an empty list."
)
return []


Expand Down Expand Up @@ -356,21 +360,6 @@ def restore_snapshot():
os.remove(backup_path)


def ensure_snapshots_dir():
if not os.path.exists(SNAPSHOTS_DIR):
try:
os.makedirs(SNAPSHOTS_DIR)
console.print(
f"[green]Created snapshots directory: {SNAPSHOTS_DIR}[/green]"
)
except Exception as e:
console.print(
f"[bold red]Error creating snapshots directory:[/bold red] {str(e)}"
)
return False
return True


# ANCHOR: DATABASE FUNCTIONS END


Expand Down
16 changes: 15 additions & 1 deletion invokeai_models_cli/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json

from typing import Dict, Any, Tuple, List
from pathlib import Path
from rich.console import Console
from rich.table import Table

Expand Down Expand Up @@ -156,11 +157,24 @@ def tuple_to_dict(input_tuple: Tuple) -> Dict[str, Any]:

result = dict(zip(keys, input_tuple))

# Parse the JSON string in metadata_json

if result["metadata_json"]:
result["metadata"] = json.loads(result["metadata_json"])
del result["metadata_json"]
else:
result["metadata"] = None

return result


def ensure_snapshots_dir(directory: Path) -> bool:
if not directory.exists():
try:
directory.mkdir(parents=True, exist_ok=True)
console.print(f"[green]Created snapshots directory: {directory}[/green]")
except Exception as e:
console.print(
f"[bold red]Error creating snapshots directory:[/bold red] {str(e)}"
)
return False
return True
7 changes: 2 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,14 @@ include = [
]

[tool.hatch.build]
include = [
artifacts = [
"invokeai_models_cli/**/*.py",
"invokeai_models_cli/**/*.json",
"invokeai_models_cli/**/*.md",
"invokeai_models_cli/snapshots/*",
"invokeai_models_cli/snapshots/*.json",
"invokeai_models_cli/snapshots/*.db",
"README.md",
"LICENSE"
]


[project.urls]
Repository = "https://github.com/regiellis/invokeai_models_cli"
Documentation = "https://github.com/regiellis/invokeai_models_cli/blob/main/README.md"
Expand Down
Binary file modified screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b1109c1

Please sign in to comment.