imagent-cli 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- imagent/__init__.py +0 -0
- imagent/__main__.py +5 -0
- imagent/cli.py +128 -0
- imagent/commands/__init__.py +0 -0
- imagent/commands/after_add.py +82 -0
- imagent/commands/delete.py +200 -0
- imagent/commands/failed.py +24 -0
- imagent/commands/forget.py +63 -0
- imagent/commands/help.py +82 -0
- imagent/commands/menu.py +155 -0
- imagent/commands/scan.py +1394 -0
- imagent/commands/search.py +432 -0
- imagent/commands/settings.py +139 -0
- imagent/commands/setup.py +1409 -0
- imagent/commands/uninstall.py +379 -0
- imagent/config.py +331 -0
- imagent/db/__init__.py +1 -0
- imagent/db/connection.py +237 -0
- imagent/db/operations.py +683 -0
- imagent/db/schema.sql +454 -0
- imagent/image_processing/__init__.py +14 -0
- imagent/image_processing/convert.py +48 -0
- imagent/image_processing/features.py +88 -0
- imagent/image_processing/hashing.py +49 -0
- imagent/image_processing/memory.py +101 -0
- imagent/image_processing/metadata.py +122 -0
- imagent/image_processing/ocr.py +129 -0
- imagent/image_processing/preprocess.py +33 -0
- imagent/image_processing/problems.py +53 -0
- imagent/image_processing/sample_pictures.py +214 -0
- imagent/os_specific/__init__.py +15 -0
- imagent/os_specific/convert.py +34 -0
- imagent/os_specific/files.py +64 -0
- imagent/os_specific/locking.py +31 -0
- imagent/os_specific/memory.py +153 -0
- imagent/os_specific/process.py +19 -0
- imagent/os_specific/storage.py +102 -0
- imagent/pipeline/__init__.py +1 -0
- imagent/pipeline/console.py +111 -0
- imagent/pipeline/discovery.py +107 -0
- imagent/pipeline/error_logger.py +69 -0
- imagent/pipeline/error_messages.py +56 -0
- imagent/pipeline/failure.py +51 -0
- imagent/pipeline/folder_picker.py +289 -0
- imagent/pipeline/locking.py +44 -0
- imagent/pipeline/progress.py +243 -0
- imagent/pipeline/serialisation.py +20 -0
- imagent/pipeline/storage.py +30 -0
- imagent/pipeline/validation.py +68 -0
- imagent/pipeline/versions.py +56 -0
- imagent/prompts/analysis_prompt.txt +8 -0
- imagent/prompts/analysis_schema.json +12 -0
- imagent/prompts/query_prompt.txt +14 -0
- imagent/text_processing/__init__.py +1 -0
- imagent/text_processing/cleaners.py +32 -0
- imagent/text_processing/formatters.py +79 -0
- imagent/vlm/__init__.py +1 -0
- imagent/vlm/analyzer.py +348 -0
- imagent/vlm/calibration.py +288 -0
- imagent/vlm/client.py +302 -0
- imagent/vlm/reply_validation.py +72 -0
- imagent/vlm/response_format.py +7 -0
- imagent_cli-0.1.0.dist-info/METADATA +171 -0
- imagent_cli-0.1.0.dist-info/RECORD +68 -0
- imagent_cli-0.1.0.dist-info/WHEEL +5 -0
- imagent_cli-0.1.0.dist-info/entry_points.txt +2 -0
- imagent_cli-0.1.0.dist-info/licenses/LICENSE +21 -0
- imagent_cli-0.1.0.dist-info/top_level.txt +1 -0
imagent/commands/menu.py
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
imagent/commands/menu.py — Imagent: the menu that ``imagent`` opens when it is run with no command. Pick an entry with the arrow keys and Enter.
|
|
4
|
+
|
|
5
|
+
It only opens once setup is complete: when it is not, ``cli.py`` runs setup first (``needs_setup``), then opens the menu.
|
|
6
|
+
It runs the chosen command and ends with that command's exit code; "Exit" just closes the menu. "Show the images that could not be indexed" is only
|
|
7
|
+
offered when there are some (images are retried by themselves; this only tells the user which ones could not be indexed and why).
|
|
8
|
+
"Forget the deleted pictures Imagent remembers" is only offered when it remembers some. "Scan folders and index images" and
|
|
9
|
+
"Delete a folder" are only offered once a folder has been added (until then there is nothing to scan or delete). "Search your images" is only
|
|
10
|
+
offered once some image is indexed (until then there is nothing to search). "Help" (``imagent help``) and "Settings" (``imagent settings``, which also holds Uninstall) are always offered, just before "Exit", Settings last.
|
|
11
|
+
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import subprocess
|
|
17
|
+
import sys
|
|
18
|
+
|
|
19
|
+
import questionary
|
|
20
|
+
|
|
21
|
+
from imagent import config
|
|
22
|
+
from imagent.db.connection import init_db
|
|
23
|
+
from imagent.db.operations import count_deleted_analyses, count_embeddings, get_device_settings, get_exhausted_backlog, get_model_settings, list_roots
|
|
24
|
+
from imagent.pipeline import console
|
|
25
|
+
from imagent.pipeline.console import make_output_safe
|
|
26
|
+
|
|
27
|
+
EXIT = "exit"
|
|
28
|
+
|
|
29
|
+
SEARCH = ("Search your images", "search")
|
|
30
|
+
ADD_FOLDER = ("Add a folder", "add")
|
|
31
|
+
SCAN = ("Scan folders and index images", "scan")
|
|
32
|
+
DELETE_FOLDER = ("Delete a folder", "delete")
|
|
33
|
+
FAILED_COMMAND = "failed"
|
|
34
|
+
FORGET_COMMAND = "forget"
|
|
35
|
+
SETTINGS = ("Settings", "settings")
|
|
36
|
+
HELP = ("Help: what each command does", "help")
|
|
37
|
+
|
|
38
|
+
STYLE = questionary.Style([
|
|
39
|
+
("qmark", "fg:ansidefault bold"),
|
|
40
|
+
("question", "fg:ansidefault bold"),
|
|
41
|
+
("pointer", "fg:ansidefault bold"),
|
|
42
|
+
("highlighted", "fg:ansidefault bold underline"),
|
|
43
|
+
("answer", "fg:ansidefault bold"),
|
|
44
|
+
("instruction", "fg:ansibrightblack"),
|
|
45
|
+
])
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
LOGO = """\
|
|
49
|
+
█████ █ █ ███ ████ █████ █ █ █████
|
|
50
|
+
█ ██ ██ █ █ █ █ ██ █ █
|
|
51
|
+
█ █ █ █ █████ █ ██ ████ █ █ █ █
|
|
52
|
+
█ █ █ █ █ █ █ █ █ ██ █
|
|
53
|
+
█████ █ █ █ █ ████ █████ █ █ █"""
|
|
54
|
+
TAGLINE = "Local image indexing and search tool."
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def show_header() -> None:
|
|
58
|
+
"""The name in big letters with the one-line description under it, after a blank line so it never touches the command typed above."""
|
|
59
|
+
questionary.print("")
|
|
60
|
+
questionary.print(LOGO, style="bold")
|
|
61
|
+
questionary.print("")
|
|
62
|
+
questionary.print(TAGLINE)
|
|
63
|
+
questionary.print("")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def failed_count() -> int:
|
|
67
|
+
"""How many images could not be indexed after every try; 0 if that cannot be found out (the menu must always appear)."""
|
|
68
|
+
try:
|
|
69
|
+
conn = init_db(str(config.DB_PATH))
|
|
70
|
+
try:
|
|
71
|
+
return len(get_exhausted_backlog(conn, config.BACKLOG_MAX_ATTEMPTS))
|
|
72
|
+
finally:
|
|
73
|
+
conn.close()
|
|
74
|
+
except Exception:
|
|
75
|
+
return 0
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def remembered_count() -> int:
|
|
79
|
+
"""How many deleted pictures Imagent remembers; 0 if that cannot be found out (the menu must always appear)."""
|
|
80
|
+
try:
|
|
81
|
+
conn = init_db(str(config.DB_PATH))
|
|
82
|
+
try:
|
|
83
|
+
return count_deleted_analyses(conn)
|
|
84
|
+
finally:
|
|
85
|
+
conn.close()
|
|
86
|
+
except Exception:
|
|
87
|
+
return 0
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def has_folders() -> bool:
|
|
91
|
+
"""True when at least one folder has been added; True if that cannot be found out (the menu must always appear, complete)."""
|
|
92
|
+
try:
|
|
93
|
+
conn = init_db(str(config.DB_PATH))
|
|
94
|
+
try:
|
|
95
|
+
return bool(list_roots(conn))
|
|
96
|
+
finally:
|
|
97
|
+
conn.close()
|
|
98
|
+
except Exception:
|
|
99
|
+
return True
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def has_indexed_images() -> bool:
|
|
103
|
+
"""True when at least one image is indexed (searchable, as search itself counts them); True if that cannot be found out (the menu must always appear, complete)."""
|
|
104
|
+
try:
|
|
105
|
+
conn = init_db(str(config.DB_PATH))
|
|
106
|
+
try:
|
|
107
|
+
return count_embeddings(conn) > 0
|
|
108
|
+
finally:
|
|
109
|
+
conn.close()
|
|
110
|
+
except Exception:
|
|
111
|
+
return True
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def needs_setup() -> bool:
|
|
115
|
+
"""True when setup has not been completed: the models are not locked or this computer has not been measured.
|
|
116
|
+
|
|
117
|
+
False if that cannot be found out, so the menu still appears (it offers Settings, which holds Uninstall, which a damaged database may need).
|
|
118
|
+
"""
|
|
119
|
+
try:
|
|
120
|
+
conn = init_db(str(config.DB_PATH))
|
|
121
|
+
try:
|
|
122
|
+
return get_model_settings(conn) is None or get_device_settings(conn) is None
|
|
123
|
+
finally:
|
|
124
|
+
conn.close()
|
|
125
|
+
except Exception:
|
|
126
|
+
return False
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def choices(failed: int = 0, remembered: int = 0, folders: bool = True, indexed: bool = True) -> list:
|
|
130
|
+
shown = [(f"Show the {failed} image(s) that could not be indexed", FAILED_COMMAND)] if failed else []
|
|
131
|
+
forget = [(f"Forget the {remembered} deleted picture(s) Imagent remembers", FORGET_COMMAND)] if remembered else []
|
|
132
|
+
entries = ([*([SEARCH] if indexed else []), ADD_FOLDER, SCAN, DELETE_FOLDER] if folders else [ADD_FOLDER]) + shown + forget + [HELP, SETTINGS, ("Exit", EXIT)]
|
|
133
|
+
return [questionary.Choice(title, value=command) for title, command in entries]
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def main() -> None:
|
|
137
|
+
make_output_safe()
|
|
138
|
+
show_header()
|
|
139
|
+
# The blank separator is skipped by the arrow keys; it only leaves a gap between the question and the entries.
|
|
140
|
+
choice = questionary.select("What would you like to do?", choices=[questionary.Separator(" ")] + choices(failed_count(), remembered_count(), has_folders(), has_indexed_images()), qmark="▌",
|
|
141
|
+
pointer="»", instruction=" ", style=STYLE).ask()
|
|
142
|
+
if choice is None: # Ctrl+C; questionary already said so
|
|
143
|
+
sys.exit(1)
|
|
144
|
+
if choice == EXIT:
|
|
145
|
+
return
|
|
146
|
+
command = choice.split()
|
|
147
|
+
process = subprocess.Popen([sys.executable, "-m", "imagent", *command])
|
|
148
|
+
while True:
|
|
149
|
+
try:
|
|
150
|
+
code = process.wait()
|
|
151
|
+
except KeyboardInterrupt:
|
|
152
|
+
continue # the command got the same Ctrl+C and is ending by itself: wait for it, do not cut it short
|
|
153
|
+
console.gap_shown = True # the command left the blank line when it ended
|
|
154
|
+
sys.exit(code)
|
|
155
|
+
|