cvassist 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.
- cvassist-0.1.0/MANIFEST.in +9 -0
- cvassist-0.1.0/PKG-INFO +71 -0
- cvassist-0.1.0/README.md +48 -0
- cvassist-0.1.0/cvassist/__init__.py +2 -0
- cvassist-0.1.0/cvassist/__main__.py +3 -0
- cvassist-0.1.0/cvassist/cli.py +244 -0
- cvassist-0.1.0/cvassist/download.py +80 -0
- cvassist-0.1.0/cvassist.egg-info/PKG-INFO +71 -0
- cvassist-0.1.0/cvassist.egg-info/SOURCES.txt +76 -0
- cvassist-0.1.0/cvassist.egg-info/dependency_links.txt +1 -0
- cvassist-0.1.0/cvassist.egg-info/entry_points.txt +2 -0
- cvassist-0.1.0/cvassist.egg-info/requires.txt +8 -0
- cvassist-0.1.0/cvassist.egg-info/top_level.txt +1 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/knowledge.sqlite +0 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/records/apis.jsonl +143 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/records/corrections.jsonl +32 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/records/external_sources.json +299 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/records/facts.jsonl +588 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/records/manual_examples.jsonl +38 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/records/pages.jsonl +135 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/records/qa.jsonl +164 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/records/snippets.jsonl +41 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/records/sources.json +237 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/records/tasks.jsonl +41 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/records/terminology.json +26 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/records/topics.jsonl +82 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/records/triples.jsonl +220 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/search.py +62 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/solutions/cv_core.py +336 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/solutions/lab01.py +106 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/solutions/lab02.py +38 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/solutions/lab03.py +80 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/solutions/lab04.py +21 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/solutions/lab05.py +85 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/solutions/lab06.py +140 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/solutions/manual_examples.py +101 -0
- cvassist-0.1.0/outputs/cv_knowledge_base/solutions/run_synthetic.py +169 -0
- cvassist-0.1.0/pyproject.toml +51 -0
- cvassist-0.1.0/setup.cfg +4 -0
- cvassist-0.1.0/work/ask.py +343 -0
- cvassist-0.1.0/work/build_all.py +29 -0
- cvassist-0.1.0/work/build_apis.py +112 -0
- cvassist-0.1.0/work/build_content.py +444 -0
- cvassist-0.1.0/work/build_coverage.py +127 -0
- cvassist-0.1.0/work/build_index.py +137 -0
- cvassist-0.1.0/work/build_plans.py +45 -0
- cvassist-0.1.0/work/codegen.py +229 -0
- cvassist-0.1.0/work/combine_laya.py +55 -0
- cvassist-0.1.0/work/compare_readers.py +52 -0
- cvassist-0.1.0/work/cvpaths.py +42 -0
- cvassist-0.1.0/work/eval_codegen.py +70 -0
- cvassist-0.1.0/work/eval_mcq.py +32 -0
- cvassist-0.1.0/work/eval_search.py +125 -0
- cvassist-0.1.0/work/extract_sources.py +28 -0
- cvassist-0.1.0/work/facts_concepts.py +78 -0
- cvassist-0.1.0/work/facts_gaps.py +70 -0
- cvassist-0.1.0/work/facts_introspect.py +80 -0
- cvassist-0.1.0/work/facts_lab01.py +83 -0
- cvassist-0.1.0/work/facts_lab03.py +46 -0
- cvassist-0.1.0/work/facts_lab05.py +53 -0
- cvassist-0.1.0/work/facts_lab06.py +60 -0
- cvassist-0.1.0/work/facts_manuals.py +164 -0
- cvassist-0.1.0/work/facts_opencv_api.py +196 -0
- cvassist-0.1.0/work/mcq_answer.py +173 -0
- cvassist-0.1.0/work/mcq_engine.py +280 -0
- cvassist-0.1.0/work/merge_ocr.py +16 -0
- cvassist-0.1.0/work/plan_eval.py +60 -0
- cvassist-0.1.0/work/plan_recipes.py +232 -0
- cvassist-0.1.0/work/plan_selftest.py +319 -0
- cvassist-0.1.0/work/plan_steps.py +809 -0
- cvassist-0.1.0/work/planner.py +526 -0
- cvassist-0.1.0/work/quiz.py +142 -0
- cvassist-0.1.0/work/render_sources.py +29 -0
- cvassist-0.1.0/work/supplement_topics.py +253 -0
- cvassist-0.1.0/work/test_supplement.py +88 -0
- cvassist-0.1.0/work/test_topics.py +53 -0
- cvassist-0.1.0/work/topic_setups.py +80 -0
- cvassist-0.1.0/work/tune_reader.py +55 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# sdist: only what the package needs
|
|
2
|
+
prune work
|
|
3
|
+
prune outputs
|
|
4
|
+
prune models
|
|
5
|
+
include work/*.py
|
|
6
|
+
include outputs/cv_knowledge_base/search.py
|
|
7
|
+
include outputs/cv_knowledge_base/knowledge.sqlite
|
|
8
|
+
recursive-include outputs/cv_knowledge_base/records *.jsonl *.json
|
|
9
|
+
recursive-include outputs/cv_knowledge_base/solutions *.py
|
cvassist-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cvassist
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Offline OpenCV / computer-vision study assistant: theory answers, MCQs, step-by-step plans and code from a lab-manual knowledge base.
|
|
5
|
+
Author: Abdul Rahman Azam
|
|
6
|
+
Project-URL: Homepage, https://github.com/AbdulRahmanAzam/ChatSheet-of-OpenCV
|
|
7
|
+
Project-URL: Documentation, https://github.com/AbdulRahmanAzam/ChatSheet-of-OpenCV/blob/main/HOW_TO_USE.md
|
|
8
|
+
Keywords: opencv,computer-vision,study,mcq,offline,assistant
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Topic :: Education
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Image Recognition
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
Requires-Dist: numpy>=1.24
|
|
17
|
+
Requires-Dist: opencv-python-headless<5,>=4.8
|
|
18
|
+
Requires-Dist: matplotlib>=3.7
|
|
19
|
+
Requires-Dist: onnxruntime>=1.16
|
|
20
|
+
Requires-Dist: tokenizers>=0.15
|
|
21
|
+
Provides-Extra: code
|
|
22
|
+
Requires-Dist: llama-cpp-python>=0.3; extra == "code"
|
|
23
|
+
|
|
24
|
+
# ChatSheet of OpenCV (cvassist)
|
|
25
|
+
|
|
26
|
+
Offline OpenCV / computer-vision study assistant. Answers theory questions, plans and writes code for
|
|
27
|
+
lab-style tasks, and answers MCQs from a knowledge base built from lab manuals (Labs 01-06), with page refs.
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
Requires Python 3.10 or newer.
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install cvassist
|
|
35
|
+
cvassist setup # downloads the model files once (about 213 MB); also happens on first use
|
|
36
|
+
cvassist check
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
If the `cvassist` command is not found, use `python -m cvassist <command>` instead.
|
|
40
|
+
|
|
41
|
+
The knowledge base ships inside the package. The model files are downloaded from this repo's
|
|
42
|
+
[GitHub release](https://github.com/AbdulRahmanAzam/ChatSheet-of-OpenCV/releases/tag/models-v1) into a per-user
|
|
43
|
+
cache folder (`%LOCALAPPDATA%\cvassist` on Windows, `~/.cache/cvassist` on Linux, `~/Library/Caches/cvassist` on
|
|
44
|
+
macOS). Set `CVASSIST_HOME` to use another folder.
|
|
45
|
+
|
|
46
|
+
Optional (experimental `code` command): `pip install "cvassist[code]"`, then download
|
|
47
|
+
`qwen2.5-coder-0.5b-instruct-q4_k_m.gguf` from
|
|
48
|
+
[Qwen/Qwen2.5-Coder-0.5B-Instruct-GGUF](https://huggingface.co/Qwen/Qwen2.5-Coder-0.5B-Instruct-GGUF) into
|
|
49
|
+
`<cache folder>/models/qwen2.5-coder/`.
|
|
50
|
+
|
|
51
|
+
### From source
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
git clone https://github.com/AbdulRahmanAzam/ChatSheet-of-OpenCV.git
|
|
55
|
+
cd ChatSheet-of-OpenCV
|
|
56
|
+
pip install -e .
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Use
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
cvassist help
|
|
63
|
+
cvassist ask "Why do we blur before Canny?"
|
|
64
|
+
cvassist mcq "Question? A) .. B) .. C) .. D) .."
|
|
65
|
+
cvassist plan "Count coins using Hough circles" --out plan.md --script solution.py
|
|
66
|
+
cvassist search "ratio test"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
Full guide: [HOW_TO_USE.md](HOW_TO_USE.md).
|
cvassist-0.1.0/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# ChatSheet of OpenCV (cvassist)
|
|
2
|
+
|
|
3
|
+
Offline OpenCV / computer-vision study assistant. Answers theory questions, plans and writes code for
|
|
4
|
+
lab-style tasks, and answers MCQs from a knowledge base built from lab manuals (Labs 01-06), with page refs.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
Requires Python 3.10 or newer.
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pip install cvassist
|
|
12
|
+
cvassist setup # downloads the model files once (about 213 MB); also happens on first use
|
|
13
|
+
cvassist check
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
If the `cvassist` command is not found, use `python -m cvassist <command>` instead.
|
|
17
|
+
|
|
18
|
+
The knowledge base ships inside the package. The model files are downloaded from this repo's
|
|
19
|
+
[GitHub release](https://github.com/AbdulRahmanAzam/ChatSheet-of-OpenCV/releases/tag/models-v1) into a per-user
|
|
20
|
+
cache folder (`%LOCALAPPDATA%\cvassist` on Windows, `~/.cache/cvassist` on Linux, `~/Library/Caches/cvassist` on
|
|
21
|
+
macOS). Set `CVASSIST_HOME` to use another folder.
|
|
22
|
+
|
|
23
|
+
Optional (experimental `code` command): `pip install "cvassist[code]"`, then download
|
|
24
|
+
`qwen2.5-coder-0.5b-instruct-q4_k_m.gguf` from
|
|
25
|
+
[Qwen/Qwen2.5-Coder-0.5B-Instruct-GGUF](https://huggingface.co/Qwen/Qwen2.5-Coder-0.5B-Instruct-GGUF) into
|
|
26
|
+
`<cache folder>/models/qwen2.5-coder/`.
|
|
27
|
+
|
|
28
|
+
### From source
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
git clone https://github.com/AbdulRahmanAzam/ChatSheet-of-OpenCV.git
|
|
32
|
+
cd ChatSheet-of-OpenCV
|
|
33
|
+
pip install -e .
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Use
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
cvassist help
|
|
40
|
+
cvassist ask "Why do we blur before Canny?"
|
|
41
|
+
cvassist mcq "Question? A) .. B) .. C) .. D) .."
|
|
42
|
+
cvassist plan "Count coins using Hough circles" --out plan.md --script solution.py
|
|
43
|
+
cvassist search "ratio test"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
Full guide: [HOW_TO_USE.md](HOW_TO_USE.md).
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"""cvassist: offline OpenCV study assistant. One entry point for every command.
|
|
2
|
+
|
|
3
|
+
python cvassist.py help # what you can do, with examples
|
|
4
|
+
python cvassist.py <command> --help # details of one command
|
|
5
|
+
"""
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
import argparse, os, sys
|
|
8
|
+
|
|
9
|
+
PKG = Path(__file__).resolve().parent
|
|
10
|
+
WORK = PKG / 'work' if (PKG / 'work').is_dir() else PKG.parent / 'work' # pip install / repo checkout
|
|
11
|
+
sys.path.insert(0, str(WORK))
|
|
12
|
+
import cvpaths # noqa: E402
|
|
13
|
+
os.environ.setdefault('PYTHONIOENCODING', 'utf-8')
|
|
14
|
+
try:
|
|
15
|
+
sys.stdout.reconfigure(encoding='utf-8')
|
|
16
|
+
except Exception:
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
HELP = r"""
|
|
20
|
+
cvassist - offline OpenCV / computer-vision study assistant (no internet, no big AI model)
|
|
21
|
+
|
|
22
|
+
COMMANDS
|
|
23
|
+
ask Answer a theory question, or plan + write code for a task (main command)
|
|
24
|
+
mcq Answer multiple-choice questions: type them, paste them, or give a file
|
|
25
|
+
plan Full step-by-step plan for a task (every step: why, settings, code, warnings, manual facts)
|
|
26
|
+
search Look up topics in the knowledge base
|
|
27
|
+
code EXPERIMENTAL: write new code for a custom "write solve(img) that ..." question
|
|
28
|
+
setup Download the model files (about 213 MB, once; also happens on first use)
|
|
29
|
+
check Check that this machine has everything installed
|
|
30
|
+
help Show this help
|
|
31
|
+
|
|
32
|
+
EXAMPLES
|
|
33
|
+
cvassist ask "Why do we blur before Canny edge detection?"
|
|
34
|
+
cvassist ask "Why do we blur before Canny edge detection? answer in one line"
|
|
35
|
+
cvassist ask "Explain watershed segmentation in 3 points"
|
|
36
|
+
cvassist ask "How does Otsu thresholding work? with code"
|
|
37
|
+
cvassist ask "Detect lane markings on the road using Hough lines" --out answer.md
|
|
38
|
+
cvassist mcq "Why blur before Canny? A) more contrast B) reduce noise C) grayscale D) thicker edges"
|
|
39
|
+
cvassist mcq (then paste one or many MCQs, press Enter twice)
|
|
40
|
+
cvassist mcq mcqs.txt (answers printed; add --out answers.md for a sheet file)
|
|
41
|
+
cvassist plan "Count the coins using Hough circles" --out plan.md --script solution.py
|
|
42
|
+
cvassist search "ratio test"
|
|
43
|
+
cvassist check
|
|
44
|
+
|
|
45
|
+
HOW TO PHRASE AN ASK QUESTION
|
|
46
|
+
Theory question -> starts with what / why / how / explain / define / difference ...
|
|
47
|
+
Task question -> detect / count / segment / implement / "You are working on ..." ...
|
|
48
|
+
Add to the question to control the answer:
|
|
49
|
+
"in one line" one sentence "briefly" answer + 2 points
|
|
50
|
+
"in 3 points" numbered list "in detail" everything
|
|
51
|
+
"with code" add runnable code "only code" just the code
|
|
52
|
+
|
|
53
|
+
MCQ FORMAT (when pasting or in a file; one blank line between questions)
|
|
54
|
+
1. Why is the image blurred before applying Canny?
|
|
55
|
+
A) To increase contrast
|
|
56
|
+
B) To reduce noise that would create false edges
|
|
57
|
+
C) To convert it to grayscale
|
|
58
|
+
D) To make edges thicker
|
|
59
|
+
Correct Answer: B <- optional; if given, the sheet is marked right/wrong
|
|
60
|
+
|
|
61
|
+
Run cvassist <command> --help for the options of one command.
|
|
62
|
+
(If the cvassist command is not found, use: python -m cvassist <command> ...)
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def ensure_models(names, required=True):
|
|
67
|
+
"""Download missing model files on first use."""
|
|
68
|
+
from cvassist import download
|
|
69
|
+
if all(download.installed(cvpaths.MODELS, n) for n in names):
|
|
70
|
+
return True
|
|
71
|
+
ok = download.download(cvpaths.MODELS, names)
|
|
72
|
+
if not ok and required:
|
|
73
|
+
sys.exit('The model files are missing. Connect to the internet and run: cvassist setup')
|
|
74
|
+
return ok
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def cmd_setup(a):
|
|
78
|
+
from cvassist import download
|
|
79
|
+
ok = download.download(cvpaths.MODELS, force=a.force)
|
|
80
|
+
print(('Models ready in ' if ok else 'Some downloads failed. Run cvassist setup again. Folder: ') + str(cvpaths.MODELS))
|
|
81
|
+
if not ok:
|
|
82
|
+
sys.exit(1)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def cmd_ask(a):
|
|
86
|
+
ensure_models(['ms-marco-MiniLM-L-6-v2'], required=False)
|
|
87
|
+
import ask
|
|
88
|
+
argv = [a.question] + (['--out=' + a.out] if a.out else []) + (['--detail'] if a.detail else [])
|
|
89
|
+
ask.main(argv)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def read_pasted():
|
|
93
|
+
"""Read pasted MCQs from the terminal until an empty line follows a complete question (or Ctrl+Z / Ctrl+D)."""
|
|
94
|
+
print('Paste or type the MCQ(s): question line, then options A) B) C) D) (a "Correct Answer: X" line is optional).\n'
|
|
95
|
+
'Press Enter on an empty line twice to get the answers.\n', file=sys.stderr)
|
|
96
|
+
lines, blanks = [], 0
|
|
97
|
+
while True:
|
|
98
|
+
try:
|
|
99
|
+
line = input()
|
|
100
|
+
except EOFError:
|
|
101
|
+
break
|
|
102
|
+
blanks = blanks + 1 if not line.strip() else 0
|
|
103
|
+
if blanks >= 2 and any(l.strip() for l in lines):
|
|
104
|
+
break
|
|
105
|
+
lines.append(line)
|
|
106
|
+
return '\n'.join(lines)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def cmd_mcq(a):
|
|
110
|
+
import quiz
|
|
111
|
+
source = ' '.join(a.text) if a.text else ''
|
|
112
|
+
if source and Path(source).is_file(): # a file of questions
|
|
113
|
+
if a.out:
|
|
114
|
+
ensure_models(['nli-deberta-v3-base'])
|
|
115
|
+
quiz.main([source, '--out=' + a.out] + (['--model=' + a.model] if a.model else []))
|
|
116
|
+
return
|
|
117
|
+
items = quiz.load(source)
|
|
118
|
+
else: # typed inline, or pasted
|
|
119
|
+
text = quiz.split_inline(source) if source else read_pasted()
|
|
120
|
+
items = quiz.parse_text(text)
|
|
121
|
+
if not items:
|
|
122
|
+
sys.exit('No question with options found. Format: Question? A) ... B) ... C) ... D) ... (see: cvassist help)')
|
|
123
|
+
ensure_models(['nli-deberta-v3-base'])
|
|
124
|
+
print('Loading the answer model ...', file=sys.stderr)
|
|
125
|
+
quiz.answer_terminal(items)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def cmd_plan(a):
|
|
129
|
+
import planner
|
|
130
|
+
argv = [a.task] + (['--out=' + a.out] if a.out else []) + (['--script=' + a.script] if a.script else [])
|
|
131
|
+
planner.main(argv)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def cmd_search(a):
|
|
135
|
+
sys.path.insert(0, str(cvpaths.KB))
|
|
136
|
+
import search
|
|
137
|
+
results = search.search(a.query, limit=a.limit)
|
|
138
|
+
if not results:
|
|
139
|
+
print('Nothing found. Try other words, or use: cvassist ask "your question"')
|
|
140
|
+
for r in results:
|
|
141
|
+
rec = r['record']
|
|
142
|
+
text = (rec.get('answer') or rec.get('statement') or rec.get('text') or rec.get('summary') or '')[:300]
|
|
143
|
+
print(f"- [{r['kind']}] {r['title']}" + ('' if text.strip() == str(r['title']).strip() else f'\n {text}') + '\n')
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def cmd_code(a):
|
|
147
|
+
import codegen
|
|
148
|
+
if not (codegen.MODELS.exists() and any(codegen.MODELS.glob('*.gguf'))):
|
|
149
|
+
sys.exit(f'The code model is not installed ({codegen.MODELS} / *.gguf). See HOW_TO_USE.md, section "Optional".')
|
|
150
|
+
argv = [a.question] + (['--out=' + a.out] if a.out else []) + (['--model=' + a.model] if a.model else [])
|
|
151
|
+
codegen.main(argv)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def cmd_check(a):
|
|
155
|
+
ok = True
|
|
156
|
+
print(f'Python {sys.version.split()[0]}', 'OK' if sys.version_info >= (3, 10) else 'TOO OLD (need 3.10+)')
|
|
157
|
+
for mod, need in [('numpy', ''), ('cv2', '4.x (not 5.x)'), ('matplotlib', ''), ('onnxruntime', ''), ('tokenizers', '')]:
|
|
158
|
+
try:
|
|
159
|
+
m = __import__(mod)
|
|
160
|
+
v = getattr(m, '__version__', '?')
|
|
161
|
+
bad = mod == 'cv2' and not v.startswith('4.')
|
|
162
|
+
print(f' {mod:12s} {v:10s} {"WRONG VERSION, need " + need if bad else "OK"}')
|
|
163
|
+
ok &= not bad
|
|
164
|
+
except Exception as e:
|
|
165
|
+
print(f' {mod:12s} MISSING -> pip install --upgrade cvassist'); ok = False
|
|
166
|
+
for name, path, needed_for in [
|
|
167
|
+
('knowledge base', cvpaths.KB / 'records' / 'facts.jsonl', 'everything'),
|
|
168
|
+
('MCQ reader', cvpaths.MODELS / 'nli-deberta-v3-base' / 'model_quint8_avx2.onnx', 'mcq'),
|
|
169
|
+
('answer re-ranker', cvpaths.MODELS / 'ms-marco-MiniLM-L-6-v2' / 'model_quantized.onnx', 'ask (better answers)'),
|
|
170
|
+
]:
|
|
171
|
+
print(f' {name:18s} {"OK" if path.exists() else "MISSING (" + str(path) + ") -> cvassist setup"} needed for: {needed_for}')
|
|
172
|
+
ok &= path.exists()
|
|
173
|
+
code_dir = cvpaths.MODELS / 'qwen2.5-coder'
|
|
174
|
+
gguf = list(code_dir.glob('*.gguf')) if code_dir.exists() else []
|
|
175
|
+
print(f' {"code model":18s} {"OK" if gguf else "not installed (optional, only for: code)"}')
|
|
176
|
+
if ok:
|
|
177
|
+
import ask
|
|
178
|
+
print('\nTest answer:', ask.answer('What is HOG? in one line').strip()[:150])
|
|
179
|
+
print('\nAll set.' if ok else '\nFix the items above, then run cvassist check again.')
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def main(argv=None):
|
|
183
|
+
p = argparse.ArgumentParser(prog='cvassist', add_help=False,
|
|
184
|
+
description='Offline OpenCV study assistant. Run "cvassist help" for examples.')
|
|
185
|
+
sub = p.add_subparsers(dest='command')
|
|
186
|
+
|
|
187
|
+
s = sub.add_parser('ask', help='answer a theory question or plan + code a task',
|
|
188
|
+
description='Theory question -> written answer from the course knowledge base. '
|
|
189
|
+
'Task -> approach, steps and complete code. Add "in one line", "briefly", '
|
|
190
|
+
'"in 3 points", "in detail", "with code" or "only code" to the question.')
|
|
191
|
+
s.add_argument('question', help='the question in quotes, or a .txt file containing it')
|
|
192
|
+
s.add_argument('--out', help='save the answer to this file (e.g. answer.md) instead of printing it')
|
|
193
|
+
s.add_argument('--detail', action='store_true', help='tasks: full plan with settings, warnings and manual facts per step')
|
|
194
|
+
s.set_defaults(fn=cmd_ask)
|
|
195
|
+
|
|
196
|
+
s = sub.add_parser('mcq', help='answer multiple-choice questions (typed, pasted or from a file)',
|
|
197
|
+
description='Three ways: (1) type it inline: cvassist mcq "Question? A) .. B) .. C) .. D) .." '
|
|
198
|
+
'(2) run "cvassist mcq" alone and paste one or many questions, then press Enter twice '
|
|
199
|
+
'(3) give a .txt file. Answers are printed with the fact they rely on. A "Correct '
|
|
200
|
+
'Answer: X" line is hidden from the engine and only used to mark it right/wrong.')
|
|
201
|
+
s.add_argument('text', nargs='*', help='the question with its options in quotes, or a .txt file; leave empty to paste')
|
|
202
|
+
s.add_argument('--out', help='with a file: save a markdown answer sheet instead of printing')
|
|
203
|
+
s.add_argument('--model', help=argparse.SUPPRESS)
|
|
204
|
+
s.set_defaults(fn=cmd_mcq)
|
|
205
|
+
|
|
206
|
+
s = sub.add_parser('plan', help='full step-by-step plan for a task',
|
|
207
|
+
description='Detailed plan: method, every step with reason, settings, code, warnings and manual '
|
|
208
|
+
'pages, plus the full script.')
|
|
209
|
+
s.add_argument('task', help='the task in quotes, or a .txt file containing it')
|
|
210
|
+
s.add_argument('--out', help='save the plan (markdown) to this file')
|
|
211
|
+
s.add_argument('--script', help='also save the runnable Python script to this file')
|
|
212
|
+
s.set_defaults(fn=cmd_plan)
|
|
213
|
+
|
|
214
|
+
s = sub.add_parser('search', help='look up topics in the knowledge base')
|
|
215
|
+
s.add_argument('query')
|
|
216
|
+
s.add_argument('--limit', type=int, default=5)
|
|
217
|
+
s.set_defaults(fn=cmd_search)
|
|
218
|
+
|
|
219
|
+
s = sub.add_parser('code', help='EXPERIMENTAL: new code for a custom question (needs the optional code model)',
|
|
220
|
+
description='Writes code for a question like: Write solve(img) that ... returns ... . The code is '
|
|
221
|
+
'checked and repaired; if it still fails, the tested planner script is shown instead. '
|
|
222
|
+
'About 55%% of custom tasks come out fully correct: always test the code.')
|
|
223
|
+
s.add_argument('question')
|
|
224
|
+
s.add_argument('--out', help='save the code to this file')
|
|
225
|
+
s.add_argument('--model', help=argparse.SUPPRESS)
|
|
226
|
+
s.set_defaults(fn=cmd_code)
|
|
227
|
+
|
|
228
|
+
s = sub.add_parser('setup', help='download the model files (once)')
|
|
229
|
+
s.add_argument('--force', action='store_true', help='download again even if present')
|
|
230
|
+
s.set_defaults(fn=cmd_setup)
|
|
231
|
+
|
|
232
|
+
s = sub.add_parser('check', help='check that this machine has everything installed')
|
|
233
|
+
s.set_defaults(fn=cmd_check)
|
|
234
|
+
sub.add_parser('help', help='show help with examples')
|
|
235
|
+
|
|
236
|
+
args = p.parse_args(argv)
|
|
237
|
+
if args.command in (None, 'help'):
|
|
238
|
+
print(HELP)
|
|
239
|
+
return
|
|
240
|
+
args.fn(args)
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
if __name__ == '__main__':
|
|
244
|
+
main()
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""Download the model files cvassist needs (once) into the user cache folder."""
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
import hashlib, shutil, sys, tempfile, urllib.request, zipfile
|
|
4
|
+
|
|
5
|
+
BASE_URL = 'https://github.com/AbdulRahmanAzam/ChatSheet-of-OpenCV/releases/download/models-v1/'
|
|
6
|
+
|
|
7
|
+
# name -> (zip file, size in bytes, sha256, file that proves it is installed, what it is for)
|
|
8
|
+
MODELS = {
|
|
9
|
+
'nli-deberta-v3-base': ('nli-deberta-v3-base.zip', 196831506,
|
|
10
|
+
'8d30d327b8d900ae6670063fea6a498ad595dd71448754e7ac5437f630de2ed9',
|
|
11
|
+
'model_quint8_avx2.onnx', 'MCQ reader'),
|
|
12
|
+
'ms-marco-MiniLM-L-6-v2': ('ms-marco-MiniLM-L-6-v2.zip', 16244121,
|
|
13
|
+
'377b2395e1c723e3b36746090ad0a266f92115c376f8ef09baba1f242f0b7ce8',
|
|
14
|
+
'model_quantized.onnx', 'answer re-ranker'),
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def installed(models_dir: Path, name: str) -> bool:
|
|
19
|
+
return (models_dir / name / MODELS[name][3]).is_file()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def missing(models_dir: Path) -> list:
|
|
23
|
+
return [n for n in MODELS if not installed(models_dir, n)]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _fetch(url: str, dest: Path, size: int, label: str) -> None:
|
|
27
|
+
req = urllib.request.Request(url, headers={'User-Agent': 'cvassist'})
|
|
28
|
+
with urllib.request.urlopen(req, timeout=60) as r, open(dest, 'wb') as f:
|
|
29
|
+
done, last = 0, -1
|
|
30
|
+
while True:
|
|
31
|
+
chunk = r.read(1 << 20)
|
|
32
|
+
if not chunk:
|
|
33
|
+
break
|
|
34
|
+
f.write(chunk)
|
|
35
|
+
done += len(chunk)
|
|
36
|
+
pct = int(done * 100 / size) if size else 0
|
|
37
|
+
if pct != last:
|
|
38
|
+
print(f'\r {label}: {done / 1e6:6.1f} / {size / 1e6:.1f} MB ({pct}%)', end='', file=sys.stderr, flush=True)
|
|
39
|
+
last = pct
|
|
40
|
+
print(file=sys.stderr)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def download(models_dir: Path, names=None, force: bool = False) -> bool:
|
|
44
|
+
"""Download and unpack the given models (default: all missing ones). Returns True if all are present."""
|
|
45
|
+
names = list(names or MODELS)
|
|
46
|
+
todo = [n for n in names if force or not installed(models_dir, n)]
|
|
47
|
+
if not todo:
|
|
48
|
+
return True
|
|
49
|
+
models_dir.mkdir(parents=True, exist_ok=True)
|
|
50
|
+
total = sum(MODELS[n][1] for n in todo) / 1e6
|
|
51
|
+
print(f'Downloading model files ({total:.0f} MB, one time only) into {models_dir}', file=sys.stderr)
|
|
52
|
+
ok = True
|
|
53
|
+
for name in todo:
|
|
54
|
+
zip_name, size, sha, _, label = MODELS[name]
|
|
55
|
+
with tempfile.TemporaryDirectory(dir=models_dir) as tmp:
|
|
56
|
+
zpath = Path(tmp) / zip_name
|
|
57
|
+
try:
|
|
58
|
+
_fetch(BASE_URL + zip_name, zpath, size, label)
|
|
59
|
+
except OSError as e:
|
|
60
|
+
print(f' {label}: download failed ({e}). Check your internet and run: cvassist setup', file=sys.stderr)
|
|
61
|
+
ok = False
|
|
62
|
+
continue
|
|
63
|
+
h = hashlib.sha256()
|
|
64
|
+
with open(zpath, 'rb') as f:
|
|
65
|
+
for chunk in iter(lambda: f.read(1 << 20), b''):
|
|
66
|
+
h.update(chunk)
|
|
67
|
+
if h.hexdigest() != sha:
|
|
68
|
+
print(f' {label}: file is corrupt (checksum mismatch). Run: cvassist setup', file=sys.stderr)
|
|
69
|
+
ok = False
|
|
70
|
+
continue
|
|
71
|
+
with zipfile.ZipFile(zpath) as zf:
|
|
72
|
+
for member in zf.namelist(): # only plain files inside <name>/
|
|
73
|
+
if not member.startswith(name + '/') or '..' in member:
|
|
74
|
+
raise RuntimeError(f'unexpected file in {zip_name}: {member}')
|
|
75
|
+
zf.extractall(tmp)
|
|
76
|
+
target = models_dir / name
|
|
77
|
+
if target.exists():
|
|
78
|
+
shutil.rmtree(target)
|
|
79
|
+
shutil.move(str(Path(tmp) / name), str(target))
|
|
80
|
+
return ok and not [n for n in names if not installed(models_dir, n)]
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cvassist
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Offline OpenCV / computer-vision study assistant: theory answers, MCQs, step-by-step plans and code from a lab-manual knowledge base.
|
|
5
|
+
Author: Abdul Rahman Azam
|
|
6
|
+
Project-URL: Homepage, https://github.com/AbdulRahmanAzam/ChatSheet-of-OpenCV
|
|
7
|
+
Project-URL: Documentation, https://github.com/AbdulRahmanAzam/ChatSheet-of-OpenCV/blob/main/HOW_TO_USE.md
|
|
8
|
+
Keywords: opencv,computer-vision,study,mcq,offline,assistant
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Topic :: Education
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Image Recognition
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
Requires-Dist: numpy>=1.24
|
|
17
|
+
Requires-Dist: opencv-python-headless<5,>=4.8
|
|
18
|
+
Requires-Dist: matplotlib>=3.7
|
|
19
|
+
Requires-Dist: onnxruntime>=1.16
|
|
20
|
+
Requires-Dist: tokenizers>=0.15
|
|
21
|
+
Provides-Extra: code
|
|
22
|
+
Requires-Dist: llama-cpp-python>=0.3; extra == "code"
|
|
23
|
+
|
|
24
|
+
# ChatSheet of OpenCV (cvassist)
|
|
25
|
+
|
|
26
|
+
Offline OpenCV / computer-vision study assistant. Answers theory questions, plans and writes code for
|
|
27
|
+
lab-style tasks, and answers MCQs from a knowledge base built from lab manuals (Labs 01-06), with page refs.
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
Requires Python 3.10 or newer.
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install cvassist
|
|
35
|
+
cvassist setup # downloads the model files once (about 213 MB); also happens on first use
|
|
36
|
+
cvassist check
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
If the `cvassist` command is not found, use `python -m cvassist <command>` instead.
|
|
40
|
+
|
|
41
|
+
The knowledge base ships inside the package. The model files are downloaded from this repo's
|
|
42
|
+
[GitHub release](https://github.com/AbdulRahmanAzam/ChatSheet-of-OpenCV/releases/tag/models-v1) into a per-user
|
|
43
|
+
cache folder (`%LOCALAPPDATA%\cvassist` on Windows, `~/.cache/cvassist` on Linux, `~/Library/Caches/cvassist` on
|
|
44
|
+
macOS). Set `CVASSIST_HOME` to use another folder.
|
|
45
|
+
|
|
46
|
+
Optional (experimental `code` command): `pip install "cvassist[code]"`, then download
|
|
47
|
+
`qwen2.5-coder-0.5b-instruct-q4_k_m.gguf` from
|
|
48
|
+
[Qwen/Qwen2.5-Coder-0.5B-Instruct-GGUF](https://huggingface.co/Qwen/Qwen2.5-Coder-0.5B-Instruct-GGUF) into
|
|
49
|
+
`<cache folder>/models/qwen2.5-coder/`.
|
|
50
|
+
|
|
51
|
+
### From source
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
git clone https://github.com/AbdulRahmanAzam/ChatSheet-of-OpenCV.git
|
|
55
|
+
cd ChatSheet-of-OpenCV
|
|
56
|
+
pip install -e .
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Use
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
cvassist help
|
|
63
|
+
cvassist ask "Why do we blur before Canny?"
|
|
64
|
+
cvassist mcq "Question? A) .. B) .. C) .. D) .."
|
|
65
|
+
cvassist plan "Count coins using Hough circles" --out plan.md --script solution.py
|
|
66
|
+
cvassist search "ratio test"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
Full guide: [HOW_TO_USE.md](HOW_TO_USE.md).
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
MANIFEST.in
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
cvassist/__init__.py
|
|
5
|
+
cvassist/__main__.py
|
|
6
|
+
cvassist/cli.py
|
|
7
|
+
cvassist/download.py
|
|
8
|
+
cvassist.egg-info/PKG-INFO
|
|
9
|
+
cvassist.egg-info/SOURCES.txt
|
|
10
|
+
cvassist.egg-info/dependency_links.txt
|
|
11
|
+
cvassist.egg-info/entry_points.txt
|
|
12
|
+
cvassist.egg-info/requires.txt
|
|
13
|
+
cvassist.egg-info/top_level.txt
|
|
14
|
+
outputs/cv_knowledge_base/knowledge.sqlite
|
|
15
|
+
outputs/cv_knowledge_base/search.py
|
|
16
|
+
outputs/cv_knowledge_base/records/apis.jsonl
|
|
17
|
+
outputs/cv_knowledge_base/records/corrections.jsonl
|
|
18
|
+
outputs/cv_knowledge_base/records/external_sources.json
|
|
19
|
+
outputs/cv_knowledge_base/records/facts.jsonl
|
|
20
|
+
outputs/cv_knowledge_base/records/manual_examples.jsonl
|
|
21
|
+
outputs/cv_knowledge_base/records/pages.jsonl
|
|
22
|
+
outputs/cv_knowledge_base/records/qa.jsonl
|
|
23
|
+
outputs/cv_knowledge_base/records/snippets.jsonl
|
|
24
|
+
outputs/cv_knowledge_base/records/sources.json
|
|
25
|
+
outputs/cv_knowledge_base/records/tasks.jsonl
|
|
26
|
+
outputs/cv_knowledge_base/records/terminology.json
|
|
27
|
+
outputs/cv_knowledge_base/records/topics.jsonl
|
|
28
|
+
outputs/cv_knowledge_base/records/triples.jsonl
|
|
29
|
+
outputs/cv_knowledge_base/solutions/cv_core.py
|
|
30
|
+
outputs/cv_knowledge_base/solutions/lab01.py
|
|
31
|
+
outputs/cv_knowledge_base/solutions/lab02.py
|
|
32
|
+
outputs/cv_knowledge_base/solutions/lab03.py
|
|
33
|
+
outputs/cv_knowledge_base/solutions/lab04.py
|
|
34
|
+
outputs/cv_knowledge_base/solutions/lab05.py
|
|
35
|
+
outputs/cv_knowledge_base/solutions/lab06.py
|
|
36
|
+
outputs/cv_knowledge_base/solutions/manual_examples.py
|
|
37
|
+
outputs/cv_knowledge_base/solutions/run_synthetic.py
|
|
38
|
+
work/ask.py
|
|
39
|
+
work/build_all.py
|
|
40
|
+
work/build_apis.py
|
|
41
|
+
work/build_content.py
|
|
42
|
+
work/build_coverage.py
|
|
43
|
+
work/build_index.py
|
|
44
|
+
work/build_plans.py
|
|
45
|
+
work/codegen.py
|
|
46
|
+
work/combine_laya.py
|
|
47
|
+
work/compare_readers.py
|
|
48
|
+
work/cvpaths.py
|
|
49
|
+
work/eval_codegen.py
|
|
50
|
+
work/eval_mcq.py
|
|
51
|
+
work/eval_search.py
|
|
52
|
+
work/extract_sources.py
|
|
53
|
+
work/facts_concepts.py
|
|
54
|
+
work/facts_gaps.py
|
|
55
|
+
work/facts_introspect.py
|
|
56
|
+
work/facts_lab01.py
|
|
57
|
+
work/facts_lab03.py
|
|
58
|
+
work/facts_lab05.py
|
|
59
|
+
work/facts_lab06.py
|
|
60
|
+
work/facts_manuals.py
|
|
61
|
+
work/facts_opencv_api.py
|
|
62
|
+
work/mcq_answer.py
|
|
63
|
+
work/mcq_engine.py
|
|
64
|
+
work/merge_ocr.py
|
|
65
|
+
work/plan_eval.py
|
|
66
|
+
work/plan_recipes.py
|
|
67
|
+
work/plan_selftest.py
|
|
68
|
+
work/plan_steps.py
|
|
69
|
+
work/planner.py
|
|
70
|
+
work/quiz.py
|
|
71
|
+
work/render_sources.py
|
|
72
|
+
work/supplement_topics.py
|
|
73
|
+
work/test_supplement.py
|
|
74
|
+
work/test_topics.py
|
|
75
|
+
work/topic_setups.py
|
|
76
|
+
work/tune_reader.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cvassist
|
|
Binary file
|