imagent-cli 0.1.0__tar.gz
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_cli-0.1.0/CHANGELOG.md +18 -0
- imagent_cli-0.1.0/CONTRIBUTING.md +53 -0
- imagent_cli-0.1.0/LICENSE +21 -0
- imagent_cli-0.1.0/MANIFEST.in +7 -0
- imagent_cli-0.1.0/PKG-INFO +171 -0
- imagent_cli-0.1.0/README.md +128 -0
- imagent_cli-0.1.0/SECURITY.md +16 -0
- imagent_cli-0.1.0/pyproject.toml +63 -0
- imagent_cli-0.1.0/setup.cfg +4 -0
- imagent_cli-0.1.0/src/imagent/__init__.py +0 -0
- imagent_cli-0.1.0/src/imagent/__main__.py +5 -0
- imagent_cli-0.1.0/src/imagent/cli.py +128 -0
- imagent_cli-0.1.0/src/imagent/commands/__init__.py +0 -0
- imagent_cli-0.1.0/src/imagent/commands/after_add.py +82 -0
- imagent_cli-0.1.0/src/imagent/commands/delete.py +200 -0
- imagent_cli-0.1.0/src/imagent/commands/failed.py +24 -0
- imagent_cli-0.1.0/src/imagent/commands/forget.py +63 -0
- imagent_cli-0.1.0/src/imagent/commands/help.py +82 -0
- imagent_cli-0.1.0/src/imagent/commands/menu.py +155 -0
- imagent_cli-0.1.0/src/imagent/commands/scan.py +1394 -0
- imagent_cli-0.1.0/src/imagent/commands/search.py +432 -0
- imagent_cli-0.1.0/src/imagent/commands/settings.py +139 -0
- imagent_cli-0.1.0/src/imagent/commands/setup.py +1409 -0
- imagent_cli-0.1.0/src/imagent/commands/uninstall.py +379 -0
- imagent_cli-0.1.0/src/imagent/config.py +331 -0
- imagent_cli-0.1.0/src/imagent/db/__init__.py +1 -0
- imagent_cli-0.1.0/src/imagent/db/connection.py +237 -0
- imagent_cli-0.1.0/src/imagent/db/operations.py +683 -0
- imagent_cli-0.1.0/src/imagent/db/schema.sql +454 -0
- imagent_cli-0.1.0/src/imagent/image_processing/__init__.py +14 -0
- imagent_cli-0.1.0/src/imagent/image_processing/convert.py +48 -0
- imagent_cli-0.1.0/src/imagent/image_processing/features.py +88 -0
- imagent_cli-0.1.0/src/imagent/image_processing/hashing.py +49 -0
- imagent_cli-0.1.0/src/imagent/image_processing/memory.py +101 -0
- imagent_cli-0.1.0/src/imagent/image_processing/metadata.py +122 -0
- imagent_cli-0.1.0/src/imagent/image_processing/ocr.py +129 -0
- imagent_cli-0.1.0/src/imagent/image_processing/preprocess.py +33 -0
- imagent_cli-0.1.0/src/imagent/image_processing/problems.py +53 -0
- imagent_cli-0.1.0/src/imagent/image_processing/sample_pictures.py +214 -0
- imagent_cli-0.1.0/src/imagent/os_specific/__init__.py +15 -0
- imagent_cli-0.1.0/src/imagent/os_specific/convert.py +34 -0
- imagent_cli-0.1.0/src/imagent/os_specific/files.py +64 -0
- imagent_cli-0.1.0/src/imagent/os_specific/locking.py +31 -0
- imagent_cli-0.1.0/src/imagent/os_specific/memory.py +153 -0
- imagent_cli-0.1.0/src/imagent/os_specific/process.py +19 -0
- imagent_cli-0.1.0/src/imagent/os_specific/storage.py +102 -0
- imagent_cli-0.1.0/src/imagent/pipeline/__init__.py +1 -0
- imagent_cli-0.1.0/src/imagent/pipeline/console.py +111 -0
- imagent_cli-0.1.0/src/imagent/pipeline/discovery.py +107 -0
- imagent_cli-0.1.0/src/imagent/pipeline/error_logger.py +69 -0
- imagent_cli-0.1.0/src/imagent/pipeline/error_messages.py +56 -0
- imagent_cli-0.1.0/src/imagent/pipeline/failure.py +51 -0
- imagent_cli-0.1.0/src/imagent/pipeline/folder_picker.py +289 -0
- imagent_cli-0.1.0/src/imagent/pipeline/locking.py +44 -0
- imagent_cli-0.1.0/src/imagent/pipeline/progress.py +243 -0
- imagent_cli-0.1.0/src/imagent/pipeline/serialisation.py +20 -0
- imagent_cli-0.1.0/src/imagent/pipeline/storage.py +30 -0
- imagent_cli-0.1.0/src/imagent/pipeline/validation.py +68 -0
- imagent_cli-0.1.0/src/imagent/pipeline/versions.py +56 -0
- imagent_cli-0.1.0/src/imagent/prompts/analysis_prompt.txt +8 -0
- imagent_cli-0.1.0/src/imagent/prompts/analysis_schema.json +12 -0
- imagent_cli-0.1.0/src/imagent/prompts/query_prompt.txt +14 -0
- imagent_cli-0.1.0/src/imagent/text_processing/__init__.py +1 -0
- imagent_cli-0.1.0/src/imagent/text_processing/cleaners.py +32 -0
- imagent_cli-0.1.0/src/imagent/text_processing/formatters.py +79 -0
- imagent_cli-0.1.0/src/imagent/vlm/__init__.py +1 -0
- imagent_cli-0.1.0/src/imagent/vlm/analyzer.py +348 -0
- imagent_cli-0.1.0/src/imagent/vlm/calibration.py +288 -0
- imagent_cli-0.1.0/src/imagent/vlm/client.py +302 -0
- imagent_cli-0.1.0/src/imagent/vlm/reply_validation.py +72 -0
- imagent_cli-0.1.0/src/imagent/vlm/response_format.py +7 -0
- imagent_cli-0.1.0/src/imagent_cli.egg-info/PKG-INFO +171 -0
- imagent_cli-0.1.0/src/imagent_cli.egg-info/SOURCES.txt +102 -0
- imagent_cli-0.1.0/src/imagent_cli.egg-info/dependency_links.txt +1 -0
- imagent_cli-0.1.0/src/imagent_cli.egg-info/entry_points.txt +2 -0
- imagent_cli-0.1.0/src/imagent_cli.egg-info/requires.txt +14 -0
- imagent_cli-0.1.0/src/imagent_cli.egg-info/top_level.txt +1 -0
- imagent_cli-0.1.0/tests/test_after_add.py +118 -0
- imagent_cli-0.1.0/tests/test_analysis.py +513 -0
- imagent_cli-0.1.0/tests/test_calibration.py +342 -0
- imagent_cli-0.1.0/tests/test_cli.py +395 -0
- imagent_cli-0.1.0/tests/test_client.py +216 -0
- imagent_cli-0.1.0/tests/test_config.py +182 -0
- imagent_cli-0.1.0/tests/test_convert.py +132 -0
- imagent_cli-0.1.0/tests/test_database.py +135 -0
- imagent_cli-0.1.0/tests/test_delete.py +317 -0
- imagent_cli-0.1.0/tests/test_failed.py +71 -0
- imagent_cli-0.1.0/tests/test_folder_picker.py +287 -0
- imagent_cli-0.1.0/tests/test_forget.py +114 -0
- imagent_cli-0.1.0/tests/test_image_processing.py +554 -0
- imagent_cli-0.1.0/tests/test_indexing.py +804 -0
- imagent_cli-0.1.0/tests/test_model_lock.py +158 -0
- imagent_cli-0.1.0/tests/test_ollama_live.py +121 -0
- imagent_cli-0.1.0/tests/test_os_specific.py +295 -0
- imagent_cli-0.1.0/tests/test_progress.py +21 -0
- imagent_cli-0.1.0/tests/test_sample_pictures.py +237 -0
- imagent_cli-0.1.0/tests/test_scan.py +1035 -0
- imagent_cli-0.1.0/tests/test_search.py +443 -0
- imagent_cli-0.1.0/tests/test_settings.py +231 -0
- imagent_cli-0.1.0/tests/test_setup.py +875 -0
- imagent_cli-0.1.0/tests/test_static.py +93 -0
- imagent_cli-0.1.0/tests/test_storage.py +131 -0
- imagent_cli-0.1.0/tests/test_uninstall.py +320 -0
- imagent_cli-0.1.0/tests/test_versions.py +153 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to Imagent are listed here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project follows [Semantic Versioning](https://semver.org/).
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
## [0.1.0]
|
|
8
|
+
|
|
9
|
+
First beta release.
|
|
10
|
+
|
|
11
|
+
- Index folders of pictures and search them by describing what is in them, all on your own computer.
|
|
12
|
+
- Formats: JPG, PNG, WebP, HEIC/HEIF, BMP, TIFF, GIF and AVIF.
|
|
13
|
+
- A vision model describes each picture and a text-reading step (OCR) reads the words in it; both feed one search index.
|
|
14
|
+
- `imagent setup` installs a private copy of Ollama when the computer has none, locks the three models, and measures the computer.
|
|
15
|
+
- `imagent setup` also downloads a set of 30 CC0 test pictures once (23 MB, checked against a pinned SHA-256) to check that the computer can read them. They are not part of the installed package.
|
|
16
|
+
- Pictures are recognised by their pixels, so copies, renames and moves are not analysed twice.
|
|
17
|
+
- Commands: `setup`, `add`, `scan`, `search`, `delete`, `failed`, `forget`, `settings`, `uninstall` and `help`, plus a menu.
|
|
18
|
+
- macOS, Linux and Windows.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Contributing to Imagent
|
|
2
|
+
|
|
3
|
+
Thank you for helping. Bug reports, fixes and ideas are all welcome.
|
|
4
|
+
|
|
5
|
+
## Set up
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
git clone https://github.com/the-walkerrr/Imagent.git && cd Imagent
|
|
9
|
+
python3 -m venv .venv
|
|
10
|
+
source .venv/bin/activate # Windows: .venv\Scripts\activate
|
|
11
|
+
python -m pip install --upgrade pip # editable installs need a recent pip
|
|
12
|
+
python -m pip install -e ".[dev]"
|
|
13
|
+
git config core.hooksPath .githooks # run the tests before every commit
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The code needs Python 3.11 or newer (CI tests 3.11 to 3.14), so do not use syntax newer than 3.11 outside `from __future__ import annotations` type hints.
|
|
17
|
+
|
|
18
|
+
## Run the tests
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
python -m unittest
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The tests use a temporary Imagent folder and never touch `~/.imagent`. `tests/test_ollama_live.py` runs the real Ollama and the real models, and is skipped unless you ask for it (see the top of that file).
|
|
25
|
+
|
|
26
|
+
The set of test pictures that `imagent setup` downloads is kept in `tests/data/images.zip`. The tests use that copy and never go online. If you change it, update `TEST_PICTURES_SHA256` and `TEST_PICTURES_URL` in `src/imagent/config.py` and attach the new zip to a GitHub release whose tag starts with `v` (for example `v0.1.0`; `TEST_PICTURES_URL` points at `releases/download/<tag>/images.zip`).
|
|
27
|
+
|
|
28
|
+
## Send a change
|
|
29
|
+
|
|
30
|
+
1. Open an issue first for anything bigger than a small fix, so we can agree on the approach.
|
|
31
|
+
2. Make your change on a branch, with a test for it.
|
|
32
|
+
3. Make sure `python -m unittest` passes.
|
|
33
|
+
4. Add a line to `CHANGELOG.md` under **Unreleased**.
|
|
34
|
+
5. Open a pull request that says what changed and why.
|
|
35
|
+
|
|
36
|
+
## Releasing (maintainers)
|
|
37
|
+
|
|
38
|
+
1. Change `APP_VERSION` in `src/imagent/config.py` and move the changelog's **Unreleased** lines under the new version.
|
|
39
|
+
2. Merge to `main`, then publish a GitHub release tagged `v<version>`.
|
|
40
|
+
3. The `Publish` workflow builds the package and uploads it to PyPI with trusted publishing.
|
|
41
|
+
|
|
42
|
+
To try a build by hand: `python -m build && twine check dist/*`.
|
|
43
|
+
|
|
44
|
+
## Project layout
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
src/imagent/
|
|
48
|
+
cli.py __main__.py the `imagent` command
|
|
49
|
+
commands/ one module per command (add is in scan.py), plus the menu and the after-add menu
|
|
50
|
+
config.py every setting
|
|
51
|
+
db/ vlm/ pipeline/ image_processing/ text_processing/ os_specific/ prompts/
|
|
52
|
+
tests/
|
|
53
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Divakar Mahanthi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: imagent-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Local image indexing and search tool: private, offline, and cross-platform.
|
|
5
|
+
Author-email: Divakar Mahanthi <divakarnaidumahanthi@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/the-walkerrr/Imagent
|
|
8
|
+
Project-URL: Source, https://github.com/the-walkerrr/Imagent
|
|
9
|
+
Project-URL: Issues, https://github.com/the-walkerrr/Imagent/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/the-walkerrr/Imagent/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: image search,photo search,semantic search,vision language model,ollama,ocr,offline,privacy
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
15
|
+
Classifier: Operating System :: MacOS
|
|
16
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
17
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
24
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
25
|
+
Classifier: Topic :: Scientific/Engineering :: Image Recognition
|
|
26
|
+
Requires-Python: >=3.11
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: pydantic>=2.0.0
|
|
30
|
+
Requires-Dist: ollama>=0.6.0
|
|
31
|
+
Requires-Dist: httpx>=0.27.0
|
|
32
|
+
Requires-Dist: questionary>=2.0.0
|
|
33
|
+
Requires-Dist: Pillow>=10.0.0
|
|
34
|
+
Requires-Dist: pillow-heif>=1.0.0
|
|
35
|
+
Requires-Dist: numpy>=1.24.0
|
|
36
|
+
Requires-Dist: rapidocr>=3.10.0
|
|
37
|
+
Requires-Dist: onnxruntime>=1.16.0
|
|
38
|
+
Requires-Dist: zstandard>=0.23.0
|
|
39
|
+
Provides-Extra: dev
|
|
40
|
+
Requires-Dist: build; extra == "dev"
|
|
41
|
+
Requires-Dist: twine; extra == "dev"
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
# Imagent (Beta)
|
|
45
|
+
|
|
46
|
+
**Local image indexing and search tool.**
|
|
47
|
+
|
|
48
|
+
- **Private:** everything runs on your computer, and your images never leave it.
|
|
49
|
+
- **Offline:** after setup, no internet connection is needed.
|
|
50
|
+
- **Cross-platform:** macOS, Linux and Windows.
|
|
51
|
+
- **Wide format support:** JPG, PNG, WebP, HEIC/HEIF, BMP, TIFF, GIF and AVIF.
|
|
52
|
+
|
|
53
|
+
## Requirements
|
|
54
|
+
|
|
55
|
+
Python 3.11 or newer (tested on 3.11 to 3.14). You do not need to install [Ollama](https://ollama.com) yourself: setup installs its own copy for Imagent when the computer has none (see below).
|
|
56
|
+
|
|
57
|
+
## Install
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install imagent-cli
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
This adds the `imagent` command to your computer. If `pip` is not found, use `python3 -m pip install imagent-cli` (Windows: `py -m pip install imagent-cli`).
|
|
64
|
+
|
|
65
|
+
If pip stops with `externally-managed-environment` (common with Homebrew Python on macOS and with recent Linux distributions, which do not allow installs into the system Python), install it with [pipx](https://pipx.pypa.io) instead, which gives `imagent` its own hidden environment and still makes the command available everywhere:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pipx install imagent-cli
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
To work on Imagent itself, see [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
72
|
+
|
|
73
|
+
Then set it up (once). It checks Ollama (and installs it if needed), downloads the three models, locks them, downloads a small set of test pictures (23 MB, once) to check that your computer can read them, measures your computer and asks how many deleted pictures to remember (see below):
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
imagent setup
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Use
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
imagent search "red car at night" # show the pictures that best match a description
|
|
83
|
+
imagent search # keep searching until you type exit
|
|
84
|
+
imagent search --full "red car" # show each result's full description instead of its one-line summary (--short for the summary)
|
|
85
|
+
imagent add ~/Pictures # add a folder, then choose what to do next: scan and index it, add another, delete folders, search
|
|
86
|
+
imagent add # the same, picking the folder from suggestions as you type
|
|
87
|
+
imagent scan # scan every folder you added, then index what is pending (asks for a folder if none is added yet)
|
|
88
|
+
imagent delete ~/Pictures # remove a folder from the scan list and what was indexed from it (several folders can be given; quote a path with spaces)
|
|
89
|
+
imagent delete # the same, ticking the folders to remove from the scan list
|
|
90
|
+
imagent failed # list the pictures that could not be indexed, and why
|
|
91
|
+
imagent forget # delete what Imagent remembers about deleted pictures (two confirmations)
|
|
92
|
+
imagent settings # change the settings below from a menu, or uninstall
|
|
93
|
+
imagent help # explain each command briefly
|
|
94
|
+
imagent # open a menu (arrow keys and Enter) with the common choices
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`imagent --help` lists the commands. To index: run `imagent add` with a folder, or without one to pick it from a list, then choose "Scan and index this folder" (the menu comes back after each choice, so you can add more folders), then `imagent search`. Run `imagent scan` later to bring all of them up to date.
|
|
98
|
+
|
|
99
|
+
## Settings
|
|
100
|
+
|
|
101
|
+
`imagent settings` (also in the menu) changes these, each picked from a list; they are kept in the index database:
|
|
102
|
+
|
|
103
|
+
- **Deleted pictures Imagent remembers:** none, 100, 500 (the default), 1000, 2000 or 5000. Choosing fewer than are remembered now forgets the oldest ones, after asking.
|
|
104
|
+
- **Search results show:** the one-line summary (the default) or the whole description. `imagent search --full` and `--short` change it for one search.
|
|
105
|
+
|
|
106
|
+
The models and what setup measured about your computer are not settings: they are locked at setup (see below). Uninstall is in the settings menu too.
|
|
107
|
+
|
|
108
|
+
## Pictures that come back
|
|
109
|
+
|
|
110
|
+
A picture is recognised by its pixels, whatever its name, folder or embedded details (EXIF) are. The vision model looks at each picture once:
|
|
111
|
+
|
|
112
|
+
- **Copies and renames:** a new file with the same pixels as a picture already indexed gets that picture's description and search data again, so it is not analysed a second time. A renamed or moved file keeps its index, also when it was moved into another folder you added, whichever of the two folders is scanned first.
|
|
113
|
+
- **Deleted pictures:** when a scan finds that a picture was deleted, Imagent can remember what it learned about it (its description and search data; not the picture, and not where it was). If the same picture comes back later (restored from a backup, copied, or moved into a folder you add later), it is not analysed again. Search never shows remembered pictures.
|
|
114
|
+
|
|
115
|
+
Setup asks how many deleted pictures to remember: pick one from the list (none, 100, 500, 1000, 2000 or 5000). When there are more than that, the oldest are forgotten first. Until you have answered, nothing is remembered. To delete what is remembered now, run `imagent forget` (or choose it in the menu); your indexed pictures and your choice are not touched.
|
|
116
|
+
|
|
117
|
+
When copies of one picture are indexed (in one folder or several), a search shows them as one result and lists where the other copies are, so its results are different pictures. Deleting a folder does not keep the analysis of a picture whose copy is still indexed in another folder: it is still in use.
|
|
118
|
+
|
|
119
|
+
A picture with transparent parts is shown to the model, and to the text reader, on a white background, as an image viewer shows it. A picture Imagent is not allowed to read (its permissions) is set aside with a message saying so, and tried again on every scan, so allowing it to be read is enough. The scan summary counts pictures that could not be indexed on a line of their own ("Failed"), not as waiting to be indexed.
|
|
120
|
+
|
|
121
|
+
A description is only used again when it was made with the same models, prompt and text-reading engine as a new one would be; otherwise the picture is analysed again.
|
|
122
|
+
|
|
123
|
+
## When a model does not fit your computer
|
|
124
|
+
|
|
125
|
+
Setup tries each model for real. If one cannot run here, or cannot write a description in the form Imagent needs, setup says which one, removes what it downloaded for it (a model that was already on your computer is never removed) and asks again; the prompt you copy for an AI chat then lists the models that already failed.
|
|
126
|
+
|
|
127
|
+
If a picture cannot be indexed because Ollama ran out of memory, stopped or did not reply in time, `imagent scan` lists those pictures and why, and asks whether to try them again with lower settings (a longer wait, the model paged in from disk, a smaller picture). The lower settings apply only to those pictures, each by what went wrong with it; your usual settings do not change. The default answer is no.
|
|
128
|
+
|
|
129
|
+
## The models are locked
|
|
130
|
+
|
|
131
|
+
`imagent setup` saves a private copy of each of the three models (vision, text and embedding), so a later `ollama pull` cannot change them. Different embedding models give different vectors for the same text, so changing a model would break every search of what is already indexed. To use other models, uninstall Imagent and set it up again (this clears the index).
|
|
132
|
+
|
|
133
|
+
## Where your data lives
|
|
134
|
+
|
|
135
|
+
Everything is in `~/.imagent` (on Windows, `.imagent` in your user folder), on every OS.
|
|
136
|
+
|
|
137
|
+
Holds `imagent.db` (the index), `config.json`, `install_record.json` (what setup added, so uninstall removes only that) and `last_error.log`.
|
|
138
|
+
|
|
139
|
+
## Ollama
|
|
140
|
+
|
|
141
|
+
If `imagent setup` finds no Ollama, or one that is too old, it downloads Ollama's official build for your computer into a folder of its own next to the data folder, with no administrator rights, no package manager and no change to `PATH`. The download is large, so make sure there is enough free disk space. Every file is checked against Ollama's published checksums, and those are checked against a checksum built into Imagent. This copy is used only by Imagent, and it keeps its models there too. An Ollama you already have, if it is recent enough, is used as it is and nothing is installed.
|
|
142
|
+
|
|
143
|
+
Imagent's own Ollama is in `~/.imagent-tools/ollama` (on Windows, `.imagent-tools\ollama` in your user folder), on every OS.
|
|
144
|
+
|
|
145
|
+
The copy has no GPU drivers, so an NVIDIA GPU is used only if its driver is already installed. For an AMD GPU (Linux or Windows) or an NVIDIA Jetson board, setup also downloads the extra files Ollama publishes for it. A computer with an NVIDIA GPU gets no extra files, even when it has an AMD one too, and neither does a Mac.
|
|
146
|
+
|
|
147
|
+
## Uninstall
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
imagent uninstall # (or Uninstall in `imagent settings`) deletes the index, the data folder and the models Imagent downloaded (three confirmations), then asks whether to remove Imagent's own Ollama too
|
|
151
|
+
pip uninstall imagent-cli # removes the program itself
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Your pictures, an Ollama you installed yourself and any model you had before Imagent are never touched. Imagent's own Ollama is removed only if you answer yes (the default is to keep it); you can delete its folder yourself at any time.
|
|
155
|
+
|
|
156
|
+
## Troubleshooting
|
|
157
|
+
|
|
158
|
+
| Message | What to do |
|
|
159
|
+
| --- | --- |
|
|
160
|
+
| `Imagent is not set up yet` | Run `imagent setup`. |
|
|
161
|
+
| `No indexed images found` | Run `imagent add` with a folder first. |
|
|
162
|
+
| `The ... model ... is not the same version` | The models are locked. Put the original version back (`imagent setup` restores it when it can), or uninstall and set up again, which clears the index. |
|
|
163
|
+
| `...is on a network drive` / `...external or removable drive` | Copy the pictures to your computer's own disk. |
|
|
164
|
+
|
|
165
|
+
## Contributing
|
|
166
|
+
|
|
167
|
+
Bug reports and pull requests are welcome; see [CONTRIBUTING.md](CONTRIBUTING.md) for how to set up, run the tests and send a change. Changes by version are in [CHANGELOG.md](CHANGELOG.md). To report a security problem, see [SECURITY.md](SECURITY.md).
|
|
168
|
+
|
|
169
|
+
## License
|
|
170
|
+
|
|
171
|
+
Imagent is released under the [MIT License](LICENSE). The test pictures that setup downloads are public-domain or CC0 photographs from Wikimedia Commons; their sources and authors are in the `manifest.json` inside the download.
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Imagent (Beta)
|
|
2
|
+
|
|
3
|
+
**Local image indexing and search tool.**
|
|
4
|
+
|
|
5
|
+
- **Private:** everything runs on your computer, and your images never leave it.
|
|
6
|
+
- **Offline:** after setup, no internet connection is needed.
|
|
7
|
+
- **Cross-platform:** macOS, Linux and Windows.
|
|
8
|
+
- **Wide format support:** JPG, PNG, WebP, HEIC/HEIF, BMP, TIFF, GIF and AVIF.
|
|
9
|
+
|
|
10
|
+
## Requirements
|
|
11
|
+
|
|
12
|
+
Python 3.11 or newer (tested on 3.11 to 3.14). You do not need to install [Ollama](https://ollama.com) yourself: setup installs its own copy for Imagent when the computer has none (see below).
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install imagent-cli
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
This adds the `imagent` command to your computer. If `pip` is not found, use `python3 -m pip install imagent-cli` (Windows: `py -m pip install imagent-cli`).
|
|
21
|
+
|
|
22
|
+
If pip stops with `externally-managed-environment` (common with Homebrew Python on macOS and with recent Linux distributions, which do not allow installs into the system Python), install it with [pipx](https://pipx.pypa.io) instead, which gives `imagent` its own hidden environment and still makes the command available everywhere:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pipx install imagent-cli
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
To work on Imagent itself, see [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
29
|
+
|
|
30
|
+
Then set it up (once). It checks Ollama (and installs it if needed), downloads the three models, locks them, downloads a small set of test pictures (23 MB, once) to check that your computer can read them, measures your computer and asks how many deleted pictures to remember (see below):
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
imagent setup
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Use
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
imagent search "red car at night" # show the pictures that best match a description
|
|
40
|
+
imagent search # keep searching until you type exit
|
|
41
|
+
imagent search --full "red car" # show each result's full description instead of its one-line summary (--short for the summary)
|
|
42
|
+
imagent add ~/Pictures # add a folder, then choose what to do next: scan and index it, add another, delete folders, search
|
|
43
|
+
imagent add # the same, picking the folder from suggestions as you type
|
|
44
|
+
imagent scan # scan every folder you added, then index what is pending (asks for a folder if none is added yet)
|
|
45
|
+
imagent delete ~/Pictures # remove a folder from the scan list and what was indexed from it (several folders can be given; quote a path with spaces)
|
|
46
|
+
imagent delete # the same, ticking the folders to remove from the scan list
|
|
47
|
+
imagent failed # list the pictures that could not be indexed, and why
|
|
48
|
+
imagent forget # delete what Imagent remembers about deleted pictures (two confirmations)
|
|
49
|
+
imagent settings # change the settings below from a menu, or uninstall
|
|
50
|
+
imagent help # explain each command briefly
|
|
51
|
+
imagent # open a menu (arrow keys and Enter) with the common choices
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`imagent --help` lists the commands. To index: run `imagent add` with a folder, or without one to pick it from a list, then choose "Scan and index this folder" (the menu comes back after each choice, so you can add more folders), then `imagent search`. Run `imagent scan` later to bring all of them up to date.
|
|
55
|
+
|
|
56
|
+
## Settings
|
|
57
|
+
|
|
58
|
+
`imagent settings` (also in the menu) changes these, each picked from a list; they are kept in the index database:
|
|
59
|
+
|
|
60
|
+
- **Deleted pictures Imagent remembers:** none, 100, 500 (the default), 1000, 2000 or 5000. Choosing fewer than are remembered now forgets the oldest ones, after asking.
|
|
61
|
+
- **Search results show:** the one-line summary (the default) or the whole description. `imagent search --full` and `--short` change it for one search.
|
|
62
|
+
|
|
63
|
+
The models and what setup measured about your computer are not settings: they are locked at setup (see below). Uninstall is in the settings menu too.
|
|
64
|
+
|
|
65
|
+
## Pictures that come back
|
|
66
|
+
|
|
67
|
+
A picture is recognised by its pixels, whatever its name, folder or embedded details (EXIF) are. The vision model looks at each picture once:
|
|
68
|
+
|
|
69
|
+
- **Copies and renames:** a new file with the same pixels as a picture already indexed gets that picture's description and search data again, so it is not analysed a second time. A renamed or moved file keeps its index, also when it was moved into another folder you added, whichever of the two folders is scanned first.
|
|
70
|
+
- **Deleted pictures:** when a scan finds that a picture was deleted, Imagent can remember what it learned about it (its description and search data; not the picture, and not where it was). If the same picture comes back later (restored from a backup, copied, or moved into a folder you add later), it is not analysed again. Search never shows remembered pictures.
|
|
71
|
+
|
|
72
|
+
Setup asks how many deleted pictures to remember: pick one from the list (none, 100, 500, 1000, 2000 or 5000). When there are more than that, the oldest are forgotten first. Until you have answered, nothing is remembered. To delete what is remembered now, run `imagent forget` (or choose it in the menu); your indexed pictures and your choice are not touched.
|
|
73
|
+
|
|
74
|
+
When copies of one picture are indexed (in one folder or several), a search shows them as one result and lists where the other copies are, so its results are different pictures. Deleting a folder does not keep the analysis of a picture whose copy is still indexed in another folder: it is still in use.
|
|
75
|
+
|
|
76
|
+
A picture with transparent parts is shown to the model, and to the text reader, on a white background, as an image viewer shows it. A picture Imagent is not allowed to read (its permissions) is set aside with a message saying so, and tried again on every scan, so allowing it to be read is enough. The scan summary counts pictures that could not be indexed on a line of their own ("Failed"), not as waiting to be indexed.
|
|
77
|
+
|
|
78
|
+
A description is only used again when it was made with the same models, prompt and text-reading engine as a new one would be; otherwise the picture is analysed again.
|
|
79
|
+
|
|
80
|
+
## When a model does not fit your computer
|
|
81
|
+
|
|
82
|
+
Setup tries each model for real. If one cannot run here, or cannot write a description in the form Imagent needs, setup says which one, removes what it downloaded for it (a model that was already on your computer is never removed) and asks again; the prompt you copy for an AI chat then lists the models that already failed.
|
|
83
|
+
|
|
84
|
+
If a picture cannot be indexed because Ollama ran out of memory, stopped or did not reply in time, `imagent scan` lists those pictures and why, and asks whether to try them again with lower settings (a longer wait, the model paged in from disk, a smaller picture). The lower settings apply only to those pictures, each by what went wrong with it; your usual settings do not change. The default answer is no.
|
|
85
|
+
|
|
86
|
+
## The models are locked
|
|
87
|
+
|
|
88
|
+
`imagent setup` saves a private copy of each of the three models (vision, text and embedding), so a later `ollama pull` cannot change them. Different embedding models give different vectors for the same text, so changing a model would break every search of what is already indexed. To use other models, uninstall Imagent and set it up again (this clears the index).
|
|
89
|
+
|
|
90
|
+
## Where your data lives
|
|
91
|
+
|
|
92
|
+
Everything is in `~/.imagent` (on Windows, `.imagent` in your user folder), on every OS.
|
|
93
|
+
|
|
94
|
+
Holds `imagent.db` (the index), `config.json`, `install_record.json` (what setup added, so uninstall removes only that) and `last_error.log`.
|
|
95
|
+
|
|
96
|
+
## Ollama
|
|
97
|
+
|
|
98
|
+
If `imagent setup` finds no Ollama, or one that is too old, it downloads Ollama's official build for your computer into a folder of its own next to the data folder, with no administrator rights, no package manager and no change to `PATH`. The download is large, so make sure there is enough free disk space. Every file is checked against Ollama's published checksums, and those are checked against a checksum built into Imagent. This copy is used only by Imagent, and it keeps its models there too. An Ollama you already have, if it is recent enough, is used as it is and nothing is installed.
|
|
99
|
+
|
|
100
|
+
Imagent's own Ollama is in `~/.imagent-tools/ollama` (on Windows, `.imagent-tools\ollama` in your user folder), on every OS.
|
|
101
|
+
|
|
102
|
+
The copy has no GPU drivers, so an NVIDIA GPU is used only if its driver is already installed. For an AMD GPU (Linux or Windows) or an NVIDIA Jetson board, setup also downloads the extra files Ollama publishes for it. A computer with an NVIDIA GPU gets no extra files, even when it has an AMD one too, and neither does a Mac.
|
|
103
|
+
|
|
104
|
+
## Uninstall
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
imagent uninstall # (or Uninstall in `imagent settings`) deletes the index, the data folder and the models Imagent downloaded (three confirmations), then asks whether to remove Imagent's own Ollama too
|
|
108
|
+
pip uninstall imagent-cli # removes the program itself
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Your pictures, an Ollama you installed yourself and any model you had before Imagent are never touched. Imagent's own Ollama is removed only if you answer yes (the default is to keep it); you can delete its folder yourself at any time.
|
|
112
|
+
|
|
113
|
+
## Troubleshooting
|
|
114
|
+
|
|
115
|
+
| Message | What to do |
|
|
116
|
+
| --- | --- |
|
|
117
|
+
| `Imagent is not set up yet` | Run `imagent setup`. |
|
|
118
|
+
| `No indexed images found` | Run `imagent add` with a folder first. |
|
|
119
|
+
| `The ... model ... is not the same version` | The models are locked. Put the original version back (`imagent setup` restores it when it can), or uninstall and set up again, which clears the index. |
|
|
120
|
+
| `...is on a network drive` / `...external or removable drive` | Copy the pictures to your computer's own disk. |
|
|
121
|
+
|
|
122
|
+
## Contributing
|
|
123
|
+
|
|
124
|
+
Bug reports and pull requests are welcome; see [CONTRIBUTING.md](CONTRIBUTING.md) for how to set up, run the tests and send a change. Changes by version are in [CHANGELOG.md](CHANGELOG.md). To report a security problem, see [SECURITY.md](SECURITY.md).
|
|
125
|
+
|
|
126
|
+
## License
|
|
127
|
+
|
|
128
|
+
Imagent is released under the [MIT License](LICENSE). The test pictures that setup downloads are public-domain or CC0 photographs from Wikimedia Commons; their sources and authors are in the `manifest.json` inside the download.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Security policy
|
|
2
|
+
|
|
3
|
+
## Supported versions
|
|
4
|
+
|
|
5
|
+
Imagent is in beta. Only the latest release on PyPI gets security fixes.
|
|
6
|
+
|
|
7
|
+
## Reporting a vulnerability
|
|
8
|
+
|
|
9
|
+
Please do not open a public issue for a security problem. Use GitHub's private reporting instead: go to the
|
|
10
|
+
[Security tab](https://github.com/the-walkerrr/Imagent/security/advisories/new) of the repository and choose **Report a vulnerability**.
|
|
11
|
+
|
|
12
|
+
Say what you found, how to reproduce it, and which version and operating system you used. You can expect a first reply within a week.
|
|
13
|
+
|
|
14
|
+
## What counts
|
|
15
|
+
|
|
16
|
+
Imagent runs on your computer and sends nothing off it, except the downloads `imagent setup` makes (Ollama's official build, the models from Ollama's registry, and the test pictures from this project's GitHub release). Every download is checked against a checksum. Reports about those checks, about how files are unpacked, about the local database and about how folders and file names are handled are all in scope.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "imagent-cli"
|
|
7
|
+
description = "Local image indexing and search tool: private, offline, and cross-platform."
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
requires-python = ">=3.11"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
authors = [{ name = "Divakar Mahanthi", email = "divakarnaidumahanthi@gmail.com" }]
|
|
13
|
+
keywords = ["image search", "photo search", "semantic search", "vision language model", "ollama", "ocr", "offline", "privacy"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Environment :: Console",
|
|
17
|
+
"Intended Audience :: End Users/Desktop",
|
|
18
|
+
"Operating System :: MacOS",
|
|
19
|
+
"Operating System :: Microsoft :: Windows",
|
|
20
|
+
"Operating System :: POSIX :: Linux",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Programming Language :: Python :: 3.13",
|
|
26
|
+
"Programming Language :: Python :: 3.14",
|
|
27
|
+
"Topic :: Multimedia :: Graphics",
|
|
28
|
+
"Topic :: Scientific/Engineering :: Image Recognition",
|
|
29
|
+
]
|
|
30
|
+
dynamic = ["version"]
|
|
31
|
+
dependencies = [
|
|
32
|
+
"pydantic>=2.0.0",
|
|
33
|
+
"ollama>=0.6.0",
|
|
34
|
+
"httpx>=0.27.0",
|
|
35
|
+
"questionary>=2.0.0",
|
|
36
|
+
"Pillow>=10.0.0",
|
|
37
|
+
"pillow-heif>=1.0.0",
|
|
38
|
+
"numpy>=1.24.0",
|
|
39
|
+
"rapidocr>=3.10.0",
|
|
40
|
+
"onnxruntime>=1.16.0",
|
|
41
|
+
"zstandard>=0.23.0",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[project.optional-dependencies]
|
|
45
|
+
dev = ["build", "twine"]
|
|
46
|
+
|
|
47
|
+
[project.urls]
|
|
48
|
+
Homepage = "https://github.com/the-walkerrr/Imagent"
|
|
49
|
+
Source = "https://github.com/the-walkerrr/Imagent"
|
|
50
|
+
Issues = "https://github.com/the-walkerrr/Imagent/issues"
|
|
51
|
+
Changelog = "https://github.com/the-walkerrr/Imagent/blob/main/CHANGELOG.md"
|
|
52
|
+
|
|
53
|
+
[project.scripts]
|
|
54
|
+
imagent = "imagent.cli:main"
|
|
55
|
+
|
|
56
|
+
[tool.setuptools.dynamic]
|
|
57
|
+
version = { attr = "imagent.config.APP_VERSION" }
|
|
58
|
+
|
|
59
|
+
[tool.setuptools.packages.find]
|
|
60
|
+
where = ["src"]
|
|
61
|
+
|
|
62
|
+
[tool.setuptools.package-data]
|
|
63
|
+
imagent = ["prompts/*", "db/schema.sql"]
|
|
File without changes
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"""imagent/cli.py — The ``imagent`` command: read the command line and run the command it names.
|
|
2
|
+
|
|
3
|
+
``imagent`` with no command opens the menu. The menu, like every command except ``setup``, ``uninstall`` and ``help``, runs setup first if it has not been done, so it only opens once Imagent is set up. Each command is a module in ``imagent/commands``; it is imported only when it is
|
|
4
|
+
run, so ``imagent --help`` and a mistyped command answer at once, without loading the image and model libraries.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import argparse
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
from imagent import config
|
|
13
|
+
from imagent.pipeline.console import leave_a_gap, run_cli
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
17
|
+
parser = argparse.ArgumentParser(
|
|
18
|
+
prog="imagent",
|
|
19
|
+
description="Index your pictures and find them again by describing them. Everything runs on this computer. "
|
|
20
|
+
"Run it with no command to open a menu.")
|
|
21
|
+
parser.add_argument("--version", action="version", version=f"imagent {config.APP_VERSION}")
|
|
22
|
+
commands = parser.add_subparsers(dest="command", metavar="command", title="commands")
|
|
23
|
+
|
|
24
|
+
search = commands.add_parser("search", help="find pictures by describing them", description="Show the pictures that best match a description.")
|
|
25
|
+
search.add_argument("query", nargs="*", help="what to look for, for example: red car at night. "
|
|
26
|
+
"Leave it out to keep searching until you type exit")
|
|
27
|
+
detail = search.add_mutually_exclusive_group()
|
|
28
|
+
detail.add_argument("--full", dest="full", action="store_const", const=True, default=None,
|
|
29
|
+
help="show each picture's full description instead of its one-line summary (for this search; the usual one is set in settings)")
|
|
30
|
+
detail.add_argument("--short", dest="full", action="store_const", const=False, default=None,
|
|
31
|
+
help="show each picture's one-line summary instead of its full description (for this search; the usual one is set in settings)")
|
|
32
|
+
|
|
33
|
+
scan = commands.add_parser("scan", help="scan the folders you added and index their pictures",
|
|
34
|
+
description="Scan every folder you added for new or changed pictures, then index them. "
|
|
35
|
+
"Add a folder with: add \"folder path\".")
|
|
36
|
+
add = commands.add_parser("add", help="add a folder, then scan and index it",
|
|
37
|
+
description="Add a folder to the folders that are scanned, scan it, then index its pictures. "
|
|
38
|
+
"A folder added before is scanned again.")
|
|
39
|
+
add.add_argument("folder", nargs="?", help="the folder to add (without it you pick one from a list of suggestions)")
|
|
40
|
+
|
|
41
|
+
commands.add_parser("failed", help="list the pictures that could not be indexed",
|
|
42
|
+
description="List the pictures that could not be indexed, with the reason for each.")
|
|
43
|
+
commands.add_parser("forget", help="forget the deleted pictures Imagent remembers",
|
|
44
|
+
description="Delete what Imagent remembers about pictures that were deleted (their descriptions and search data), after two confirmations. "
|
|
45
|
+
"Your indexed pictures are not touched.")
|
|
46
|
+
delete = commands.add_parser("delete", help="remove folders from the scan list, and what was indexed from them",
|
|
47
|
+
description="Remove folders from the scan list and delete what was indexed from them, after showing what will be lost and two questions. "
|
|
48
|
+
"Your pictures are never touched. You can choose to keep the analysis, so adding a folder again does not analyse its pictures again.")
|
|
49
|
+
delete.add_argument("folder", nargs="*", help="the folders to remove from the scan list; put a path with spaces in quotes (without any, you choose from the folders you added)")
|
|
50
|
+
commands.add_parser("settings", help="change how Imagent behaves, or uninstall it",
|
|
51
|
+
description="Open a menu to change how many deleted pictures Imagent remembers, and whether a search shows the summary or the full description. "
|
|
52
|
+
"It also holds Uninstall.")
|
|
53
|
+
commands.add_parser("setup", help="choose the models and prepare this computer (once)",
|
|
54
|
+
description="Check Ollama, download and lock the three models, and measure this computer. "
|
|
55
|
+
"Run it once after installing. Run again, it shows the models and restores a missing one.")
|
|
56
|
+
commands.add_parser("help", help="explain each command briefly",
|
|
57
|
+
description="Explain each command briefly, with an example of how to run it.")
|
|
58
|
+
commands.add_parser("uninstall", help="remove Imagent's data and models",
|
|
59
|
+
description="Delete the index, Imagent's data folder and the models it downloaded, after three confirmations.")
|
|
60
|
+
return parser
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _set_up_first() -> None:
|
|
64
|
+
"""Run setup before the command (or the menu) if it has not been done, so the user is told at the start, not after the command has done its work.
|
|
65
|
+
|
|
66
|
+
Setup ends the program if it fails or is cancelled, so the command or menu only runs once Imagent is set up."""
|
|
67
|
+
from imagent.commands import menu
|
|
68
|
+
if menu.needs_setup():
|
|
69
|
+
from imagent.commands import setup
|
|
70
|
+
setup.say("Imagent is not set up yet, so setup starts now.")
|
|
71
|
+
run_cli(setup.main, cancelled=setup.CANCELLED)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def main(argv: list[str] | None = None) -> None:
|
|
75
|
+
"""Run the command, and however it ends (done, a message, Ctrl+C, ``--help``) leave a blank line before the shell's prompt."""
|
|
76
|
+
try:
|
|
77
|
+
_run(argv)
|
|
78
|
+
except SystemExit as stop:
|
|
79
|
+
if sys.stdout.isatty() and isinstance(stop.code, str): # Python would print this message after the gap, so it is printed here, before it
|
|
80
|
+
print(stop.code, file=sys.stderr)
|
|
81
|
+
stop = SystemExit(1)
|
|
82
|
+
leave_a_gap()
|
|
83
|
+
raise stop
|
|
84
|
+
leave_a_gap()
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _run(argv: list[str] | None = None) -> None:
|
|
88
|
+
args = build_parser().parse_args(argv)
|
|
89
|
+
if args.command == "add" and not args.folder and sys.stdin.isatty():
|
|
90
|
+
from imagent.pipeline import folder_picker
|
|
91
|
+
folder_picker.start_listing() # the folders are listed while setup (if it runs) and the user's typing go on
|
|
92
|
+
if args.command not in ("setup", "uninstall", "help"): # setup is the fix itself, uninstall must work on a broken install, and help needs nothing
|
|
93
|
+
_set_up_first()
|
|
94
|
+
if args.command == "search":
|
|
95
|
+
from imagent.commands import search
|
|
96
|
+
run_cli(lambda: search.main(" ".join(args.query), full=args.full), cancelled="Search cancelled.")
|
|
97
|
+
elif args.command == "add":
|
|
98
|
+
from imagent.commands import scan
|
|
99
|
+
run_cli(lambda: scan.add(args.folder))
|
|
100
|
+
elif args.command == "scan":
|
|
101
|
+
from imagent.commands import scan
|
|
102
|
+
run_cli(scan.main)
|
|
103
|
+
elif args.command == "delete":
|
|
104
|
+
from imagent.commands import delete
|
|
105
|
+
run_cli(lambda: delete.main(args.folder), cancelled=delete.CANCELLED)
|
|
106
|
+
elif args.command == "failed":
|
|
107
|
+
from imagent.commands import failed
|
|
108
|
+
run_cli(failed.main)
|
|
109
|
+
elif args.command == "forget":
|
|
110
|
+
from imagent.commands import forget
|
|
111
|
+
run_cli(forget.main, cancelled=forget.CANCELLED)
|
|
112
|
+
elif args.command == "settings":
|
|
113
|
+
from imagent.commands import settings
|
|
114
|
+
run_cli(settings.main, cancelled=settings.CANCELLED)
|
|
115
|
+
elif args.command == "setup":
|
|
116
|
+
from imagent.commands import setup
|
|
117
|
+
run_cli(setup.main, cancelled=setup.CANCELLED)
|
|
118
|
+
from imagent.commands import menu # setup ends the program if it fails or is cancelled, so the menu opens only once it is done
|
|
119
|
+
run_cli(menu.main)
|
|
120
|
+
elif args.command == "help":
|
|
121
|
+
from imagent.commands import help as show_help
|
|
122
|
+
run_cli(show_help.main)
|
|
123
|
+
elif args.command == "uninstall":
|
|
124
|
+
from imagent.commands import uninstall
|
|
125
|
+
run_cli(uninstall.main, cancelled=uninstall.CANCELLED)
|
|
126
|
+
else:
|
|
127
|
+
from imagent.commands import menu
|
|
128
|
+
run_cli(menu.main)
|
|
File without changes
|