nock-cli 0.0.0__tar.gz → 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.
- nock_cli-0.1.0/LICENSE +202 -0
- nock_cli-0.1.0/PKG-INFO +90 -0
- nock_cli-0.1.0/README.md +67 -0
- nock_cli-0.1.0/pyproject.toml +37 -0
- nock_cli-0.1.0/setup.cfg +4 -0
- nock_cli-0.1.0/src/nock_cli/__init__.py +3 -0
- nock_cli-0.1.0/src/nock_cli/__main__.py +3 -0
- nock_cli-0.1.0/src/nock_cli/download.py +54 -0
- nock_cli-0.1.0/src/nock_cli/engine.py +180 -0
- nock_cli-0.1.0/src/nock_cli/main.py +124 -0
- nock_cli-0.1.0/src/nock_cli/models.py +42 -0
- nock_cli-0.1.0/src/nock_cli/paths.py +38 -0
- nock_cli-0.1.0/src/nock_cli/video.py +182 -0
- nock_cli-0.1.0/src/nock_cli.egg-info/PKG-INFO +90 -0
- nock_cli-0.1.0/src/nock_cli.egg-info/SOURCES.txt +18 -0
- nock_cli-0.1.0/src/nock_cli.egg-info/dependency_links.txt +1 -0
- nock_cli-0.1.0/src/nock_cli.egg-info/entry_points.txt +2 -0
- nock_cli-0.1.0/src/nock_cli.egg-info/requires.txt +3 -0
- nock_cli-0.1.0/src/nock_cli.egg-info/top_level.txt +1 -0
- nock_cli-0.1.0/tests/test_cli.py +101 -0
- nock_cli-0.0.0/PKG-INFO +0 -5
- nock_cli-0.0.0/nock_cli/__init__.py +0 -0
- nock_cli-0.0.0/pyproject.toml +0 -9
nock_cli-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
nock_cli-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nock-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Open models that live on your machine. Ask questions about your videos, offline.
|
|
5
|
+
Author: NockAI
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://nockai.dev
|
|
8
|
+
Project-URL: Model, https://huggingface.co/Nock-AI/nock-video-4b-GGUF
|
|
9
|
+
Keywords: local,offline,llm,video,llama.cpp,gguf
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
12
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
13
|
+
Classifier: Operating System :: MacOS
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Multimedia :: Video
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Provides-Extra: links
|
|
21
|
+
Requires-Dist: yt-dlp; extra == "links"
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# Nock CLI
|
|
25
|
+
|
|
26
|
+
Open models that live on your machine. Ask questions about your videos, offline.
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
nock video summarize my_video.mp4
|
|
30
|
+
nock video ask my_video.mp4 "What error message shows on screen?"
|
|
31
|
+
nock video find my_video.mp4 "when the error message shows up"
|
|
32
|
+
nock video summarize "https://www.youtube.com/watch?v=..."
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Everything runs on your computer. Frames are read into a temporary folder, sent to a model running on
|
|
36
|
+
`127.0.0.1`, and deleted when the answer is ready. Nothing is uploaded.
|
|
37
|
+
|
|
38
|
+
## Install
|
|
39
|
+
|
|
40
|
+
You need Python 3.9 or newer and [ffmpeg](https://ffmpeg.org/download.html).
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pipx install nock-cli
|
|
44
|
+
nock setup
|
|
45
|
+
nock doctor
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`nock setup` downloads, once:
|
|
49
|
+
- the engine: an official [llama.cpp](https://github.com/ggml-org/llama.cpp) build (about 35 MB; Vulkan on Windows
|
|
50
|
+
and Linux, Metal on Apple Silicon). Already have `llama-server`? Nock uses it.
|
|
51
|
+
- the model: [Nock Video 4B](https://huggingface.co/Nock-AI/nock-video-4b-GGUF) (about 3.4 GB).
|
|
52
|
+
|
|
53
|
+
Files go to `~/.nock` (set `NOCK_HOME` to use another folder).
|
|
54
|
+
|
|
55
|
+
### Links
|
|
56
|
+
|
|
57
|
+
Links are downloaded to your own machine with [yt-dlp](https://github.com/yt-dlp/yt-dlp), which you install
|
|
58
|
+
yourself:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pipx inject nock-cli yt-dlp
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Only use videos you have the right to use.
|
|
65
|
+
|
|
66
|
+
## What to expect
|
|
67
|
+
|
|
68
|
+
Nock Video 4B is a **preview**. On our test of 20 videos, through llama.cpp at 64 frames, it found the moment in
|
|
69
|
+
42 of 56 questions, answered 56 of 60 questions about what is on screen, and gave 6 of 7 good summaries. Full
|
|
70
|
+
results, including the misses, are on the [model card](https://huggingface.co/Nock-AI/nock-video-4b-GGUF).
|
|
71
|
+
|
|
72
|
+
- It reads frames only, not sound.
|
|
73
|
+
- A long video is read as at most 64 frames, so short events in long videos can be missed.
|
|
74
|
+
- 64 frames used about 5.5 GB of GPU memory in our test. On GPUs under 6 GB, Nock uses 32 frames (finding the
|
|
75
|
+
moment drops: 42 to 35 of 56 on our test). `--frames` overrides it.
|
|
76
|
+
- Without a GPU it works, but slowly: minutes per question.
|
|
77
|
+
|
|
78
|
+
## Options
|
|
79
|
+
|
|
80
|
+
| Option | Meaning |
|
|
81
|
+
|---|---|
|
|
82
|
+
| `--frames N` | frames to read (default 64, 32 on GPUs under 6 GB) |
|
|
83
|
+
| `nock setup --backend cpu` | CPU-only engine |
|
|
84
|
+
| `NOCK_LLAMA_SERVER=/path/llama-server` | use your own llama.cpp build |
|
|
85
|
+
|
|
86
|
+
Server logs are in `~/.nock/logs/` if something goes wrong.
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
Apache-2.0. The model has its own license on its model card (Apache-2.0, from Qwen3.5 4B).
|
nock_cli-0.1.0/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Nock CLI
|
|
2
|
+
|
|
3
|
+
Open models that live on your machine. Ask questions about your videos, offline.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
nock video summarize my_video.mp4
|
|
7
|
+
nock video ask my_video.mp4 "What error message shows on screen?"
|
|
8
|
+
nock video find my_video.mp4 "when the error message shows up"
|
|
9
|
+
nock video summarize "https://www.youtube.com/watch?v=..."
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Everything runs on your computer. Frames are read into a temporary folder, sent to a model running on
|
|
13
|
+
`127.0.0.1`, and deleted when the answer is ready. Nothing is uploaded.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
You need Python 3.9 or newer and [ffmpeg](https://ffmpeg.org/download.html).
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pipx install nock-cli
|
|
21
|
+
nock setup
|
|
22
|
+
nock doctor
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`nock setup` downloads, once:
|
|
26
|
+
- the engine: an official [llama.cpp](https://github.com/ggml-org/llama.cpp) build (about 35 MB; Vulkan on Windows
|
|
27
|
+
and Linux, Metal on Apple Silicon). Already have `llama-server`? Nock uses it.
|
|
28
|
+
- the model: [Nock Video 4B](https://huggingface.co/Nock-AI/nock-video-4b-GGUF) (about 3.4 GB).
|
|
29
|
+
|
|
30
|
+
Files go to `~/.nock` (set `NOCK_HOME` to use another folder).
|
|
31
|
+
|
|
32
|
+
### Links
|
|
33
|
+
|
|
34
|
+
Links are downloaded to your own machine with [yt-dlp](https://github.com/yt-dlp/yt-dlp), which you install
|
|
35
|
+
yourself:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pipx inject nock-cli yt-dlp
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Only use videos you have the right to use.
|
|
42
|
+
|
|
43
|
+
## What to expect
|
|
44
|
+
|
|
45
|
+
Nock Video 4B is a **preview**. On our test of 20 videos, through llama.cpp at 64 frames, it found the moment in
|
|
46
|
+
42 of 56 questions, answered 56 of 60 questions about what is on screen, and gave 6 of 7 good summaries. Full
|
|
47
|
+
results, including the misses, are on the [model card](https://huggingface.co/Nock-AI/nock-video-4b-GGUF).
|
|
48
|
+
|
|
49
|
+
- It reads frames only, not sound.
|
|
50
|
+
- A long video is read as at most 64 frames, so short events in long videos can be missed.
|
|
51
|
+
- 64 frames used about 5.5 GB of GPU memory in our test. On GPUs under 6 GB, Nock uses 32 frames (finding the
|
|
52
|
+
moment drops: 42 to 35 of 56 on our test). `--frames` overrides it.
|
|
53
|
+
- Without a GPU it works, but slowly: minutes per question.
|
|
54
|
+
|
|
55
|
+
## Options
|
|
56
|
+
|
|
57
|
+
| Option | Meaning |
|
|
58
|
+
|---|---|
|
|
59
|
+
| `--frames N` | frames to read (default 64, 32 on GPUs under 6 GB) |
|
|
60
|
+
| `nock setup --backend cpu` | CPU-only engine |
|
|
61
|
+
| `NOCK_LLAMA_SERVER=/path/llama-server` | use your own llama.cpp build |
|
|
62
|
+
|
|
63
|
+
Server logs are in `~/.nock/logs/` if something goes wrong.
|
|
64
|
+
|
|
65
|
+
## License
|
|
66
|
+
|
|
67
|
+
Apache-2.0. The model has its own license on its model card (Apache-2.0, from Qwen3.5 4B).
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=69"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "nock-cli"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Open models that live on your machine. Ask questions about your videos, offline."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
authors = [{ name = "NockAI" }]
|
|
13
|
+
keywords = ["local", "offline", "llm", "video", "llama.cpp", "gguf"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Environment :: Console",
|
|
16
|
+
"Operating System :: Microsoft :: Windows",
|
|
17
|
+
"Operating System :: POSIX :: Linux",
|
|
18
|
+
"Operating System :: MacOS",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Topic :: Multimedia :: Video",
|
|
21
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
22
|
+
]
|
|
23
|
+
# No required dependencies: the standard library only. yt-dlp is optional, for links.
|
|
24
|
+
dependencies = []
|
|
25
|
+
|
|
26
|
+
[project.optional-dependencies]
|
|
27
|
+
links = ["yt-dlp"]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://nockai.dev"
|
|
31
|
+
Model = "https://huggingface.co/Nock-AI/nock-video-4b-GGUF"
|
|
32
|
+
|
|
33
|
+
[project.scripts]
|
|
34
|
+
nock = "nock_cli.main:main"
|
|
35
|
+
|
|
36
|
+
[tool.setuptools.packages.find]
|
|
37
|
+
where = ["src"]
|
nock_cli-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""Plain HTTPS downloads with a progress line and resume, using only the standard library."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import sys
|
|
5
|
+
import urllib.request
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
USER_AGENT = "nock-cli"
|
|
9
|
+
CHUNK_SIZE = 1024 * 1024
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def get_json(url):
|
|
13
|
+
request = urllib.request.Request(url, headers={"User-Agent": USER_AGENT, "Accept": "application/json"})
|
|
14
|
+
with urllib.request.urlopen(request, timeout=60) as response:
|
|
15
|
+
return json.load(response)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def download(url, target, label):
|
|
19
|
+
"""Downloads `url` to `target`. A partial `.part` file from an earlier try is resumed, not started over."""
|
|
20
|
+
target = Path(target)
|
|
21
|
+
if target.exists():
|
|
22
|
+
return target
|
|
23
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
24
|
+
partial = target.with_name(target.name + ".part")
|
|
25
|
+
done = partial.stat().st_size if partial.exists() else 0
|
|
26
|
+
headers = {"User-Agent": USER_AGENT}
|
|
27
|
+
if done:
|
|
28
|
+
headers["Range"] = f"bytes={done}-"
|
|
29
|
+
request = urllib.request.Request(url, headers=headers)
|
|
30
|
+
with urllib.request.urlopen(request, timeout=60) as response:
|
|
31
|
+
# 206 means the server honoured the range; anything else sends the whole file again.
|
|
32
|
+
if done and response.status != 206:
|
|
33
|
+
done = 0
|
|
34
|
+
total = done + int(response.headers.get("Content-Length") or 0)
|
|
35
|
+
with open(partial, "ab" if done else "wb") as handle:
|
|
36
|
+
while True:
|
|
37
|
+
chunk = response.read(CHUNK_SIZE)
|
|
38
|
+
if not chunk:
|
|
39
|
+
break
|
|
40
|
+
handle.write(chunk)
|
|
41
|
+
done += len(chunk)
|
|
42
|
+
show_progress(label, done, total)
|
|
43
|
+
sys.stderr.write("\n")
|
|
44
|
+
partial.replace(target)
|
|
45
|
+
return target
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def show_progress(label, done, total):
|
|
49
|
+
megabytes = done / 1048576
|
|
50
|
+
if total:
|
|
51
|
+
sys.stderr.write(f"\r {label}: {megabytes:,.0f} / {total / 1048576:,.0f} MB ({done * 100 // total}%)")
|
|
52
|
+
else:
|
|
53
|
+
sys.stderr.write(f"\r {label}: {megabytes:,.0f} MB")
|
|
54
|
+
sys.stderr.flush()
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"""The engine: an official llama.cpp build (llama-server), downloaded once by `nock setup` and run on 127.0.0.1 only.
|
|
2
|
+
|
|
3
|
+
Nock does not bundle llama.cpp. It fetches a pinned release from github.com/ggml-org/llama.cpp so every user runs
|
|
4
|
+
the same tested build. An existing llama-server can be used instead (NOCK_LLAMA_SERVER, or on the PATH).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
import platform
|
|
9
|
+
import shutil
|
|
10
|
+
import socket
|
|
11
|
+
import subprocess
|
|
12
|
+
import tarfile
|
|
13
|
+
import time
|
|
14
|
+
import urllib.error
|
|
15
|
+
import urllib.request
|
|
16
|
+
import zipfile
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
from nock_cli import paths
|
|
20
|
+
from nock_cli.download import download
|
|
21
|
+
|
|
22
|
+
LLAMA_CPP_BUILD = "b11804"
|
|
23
|
+
RELEASE_URL = f"https://github.com/ggml-org/llama.cpp/releases/download/{LLAMA_CPP_BUILD}"
|
|
24
|
+
|
|
25
|
+
# Vulkan is the default on Windows and Linux: one small build (about 35 MB) that runs on NVIDIA, AMD and Intel GPUs.
|
|
26
|
+
# Macs use Metal, which is built into the macOS release.
|
|
27
|
+
ASSETS = {
|
|
28
|
+
("windows", "x64", "vulkan"): "llama-{build}-bin-win-vulkan-x64.zip",
|
|
29
|
+
("windows", "x64", "cpu"): "llama-{build}-bin-win-cpu-x64.zip",
|
|
30
|
+
("windows", "arm64", "vulkan"): "llama-{build}-bin-win-vulkan-arm64.zip",
|
|
31
|
+
("windows", "arm64", "cpu"): "llama-{build}-bin-win-cpu-arm64.zip",
|
|
32
|
+
("linux", "x64", "vulkan"): "llama-{build}-bin-ubuntu-vulkan-x64.tar.gz",
|
|
33
|
+
("linux", "x64", "cpu"): "llama-{build}-bin-ubuntu-x64.tar.gz",
|
|
34
|
+
("linux", "arm64", "vulkan"): "llama-{build}-bin-ubuntu-vulkan-arm64.tar.gz",
|
|
35
|
+
("linux", "arm64", "cpu"): "llama-{build}-bin-ubuntu-arm64.tar.gz",
|
|
36
|
+
("macos", "arm64", "metal"): "llama-{build}-bin-macos-arm64.tar.gz",
|
|
37
|
+
("macos", "x64", "cpu"): "llama-{build}-bin-macos-x64.tar.gz",
|
|
38
|
+
}
|
|
39
|
+
BACKENDS = ("vulkan", "cpu", "metal")
|
|
40
|
+
SERVER_START_TIMEOUT = 300 # loading 3.4 GB from a slow disk can take a while
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class EngineError(Exception):
|
|
44
|
+
pass
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def current_system():
|
|
48
|
+
system = {"Windows": "windows", "Linux": "linux", "Darwin": "macos"}.get(platform.system())
|
|
49
|
+
machine = platform.machine().lower()
|
|
50
|
+
arch = "arm64" if machine in ("arm64", "aarch64") else "x64" if machine in ("amd64", "x86_64", "x64") else machine
|
|
51
|
+
return system, arch
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def default_backend(system, arch):
|
|
55
|
+
if system == "macos":
|
|
56
|
+
return "metal" if arch == "arm64" else "cpu"
|
|
57
|
+
return "vulkan"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def asset_name(system, arch, backend):
|
|
61
|
+
template = ASSETS.get((system, arch, backend))
|
|
62
|
+
if not template:
|
|
63
|
+
supported = ", ".join(f"{s}/{a}/{b}" for s, a, b in ASSETS)
|
|
64
|
+
raise EngineError(f"No llama.cpp build for {system}/{arch}/{backend}. Supported: {supported}")
|
|
65
|
+
return template.format(build=LLAMA_CPP_BUILD)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def server_binary_name():
|
|
69
|
+
return "llama-server.exe" if platform.system() == "Windows" else "llama-server"
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def find_server_in(folder):
|
|
73
|
+
matches = sorted(Path(folder).rglob(server_binary_name()))
|
|
74
|
+
return matches[0] if matches else None
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def install(backend=None):
|
|
78
|
+
"""Downloads and unpacks the pinned llama.cpp build. Returns the path to llama-server."""
|
|
79
|
+
system, arch = current_system()
|
|
80
|
+
backend = backend or default_backend(system, arch)
|
|
81
|
+
name = asset_name(system, arch, backend)
|
|
82
|
+
target = paths.engine_dir() / f"{LLAMA_CPP_BUILD}-{backend}"
|
|
83
|
+
existing = find_server_in(target) if target.exists() else None
|
|
84
|
+
if existing:
|
|
85
|
+
return existing
|
|
86
|
+
archive = download(f"{RELEASE_URL}/{name}", paths.engine_dir() / "downloads" / name, f"llama.cpp {LLAMA_CPP_BUILD} ({backend})")
|
|
87
|
+
target.mkdir(parents=True, exist_ok=True)
|
|
88
|
+
unpack(archive, target)
|
|
89
|
+
server = find_server_in(target)
|
|
90
|
+
if not server:
|
|
91
|
+
raise EngineError(f"{name} did not contain {server_binary_name()}")
|
|
92
|
+
if platform.system() != "Windows":
|
|
93
|
+
server.chmod(0o755)
|
|
94
|
+
archive.unlink()
|
|
95
|
+
return server
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def unpack(archive, target):
|
|
99
|
+
target = Path(target).resolve()
|
|
100
|
+
if archive.name.endswith(".zip"):
|
|
101
|
+
with zipfile.ZipFile(archive) as bundle:
|
|
102
|
+
for member in bundle.namelist():
|
|
103
|
+
ensure_inside(target, member)
|
|
104
|
+
bundle.extractall(target)
|
|
105
|
+
else:
|
|
106
|
+
with tarfile.open(archive) as bundle:
|
|
107
|
+
for member in bundle.getmembers():
|
|
108
|
+
ensure_inside(target, member.name)
|
|
109
|
+
if member.issym() or member.islnk():
|
|
110
|
+
ensure_inside(target, os.path.join(os.path.dirname(member.name), member.linkname))
|
|
111
|
+
bundle.extractall(target)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def ensure_inside(target, member_name):
|
|
115
|
+
"""Refuses archive entries that would land outside the engine folder."""
|
|
116
|
+
resolved = (target / member_name).resolve()
|
|
117
|
+
if resolved != target and target not in resolved.parents:
|
|
118
|
+
raise EngineError(f"Unsafe path in archive: {member_name}")
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def locate_server(settings):
|
|
122
|
+
"""The llama-server to use: NOCK_LLAMA_SERVER, then the one `nock setup` installed, then one on the PATH."""
|
|
123
|
+
override = os.environ.get("NOCK_LLAMA_SERVER")
|
|
124
|
+
if override:
|
|
125
|
+
return Path(override)
|
|
126
|
+
installed = settings.get("llama_server")
|
|
127
|
+
if installed and Path(installed).exists():
|
|
128
|
+
return Path(installed)
|
|
129
|
+
on_path = shutil.which("llama-server")
|
|
130
|
+
return Path(on_path) if on_path else None
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def free_port():
|
|
134
|
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as probe:
|
|
135
|
+
probe.bind(("127.0.0.1", 0))
|
|
136
|
+
return probe.getsockname()[1]
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
class LocalServer:
|
|
140
|
+
"""Runs llama-server for one command and stops it afterwards. It listens on 127.0.0.1 only."""
|
|
141
|
+
|
|
142
|
+
def __init__(self, server_binary, model_path, mmproj_path, context, gpu_layers, log_path):
|
|
143
|
+
self.port = free_port()
|
|
144
|
+
self.url = f"http://127.0.0.1:{self.port}"
|
|
145
|
+
self.command = [str(server_binary), "-m", str(model_path), "--mmproj", str(mmproj_path), "--jinja",
|
|
146
|
+
"-c", str(context), "-ngl", str(gpu_layers), "--host", "127.0.0.1", "--port", str(self.port)]
|
|
147
|
+
self.log_path = Path(log_path)
|
|
148
|
+
self.process = None
|
|
149
|
+
self.log_handle = None
|
|
150
|
+
|
|
151
|
+
def __enter__(self):
|
|
152
|
+
self.log_path.parent.mkdir(parents=True, exist_ok=True)
|
|
153
|
+
self.log_handle = open(self.log_path, "w", encoding="utf-8", errors="replace")
|
|
154
|
+
self.process = subprocess.Popen(self.command, stdout=self.log_handle, stderr=subprocess.STDOUT)
|
|
155
|
+
self.wait_until_ready()
|
|
156
|
+
return self
|
|
157
|
+
|
|
158
|
+
def __exit__(self, *exc_info):
|
|
159
|
+
if self.process and self.process.poll() is None:
|
|
160
|
+
self.process.terminate()
|
|
161
|
+
try:
|
|
162
|
+
self.process.wait(timeout=15)
|
|
163
|
+
except subprocess.TimeoutExpired:
|
|
164
|
+
self.process.kill()
|
|
165
|
+
if self.log_handle:
|
|
166
|
+
self.log_handle.close()
|
|
167
|
+
|
|
168
|
+
def wait_until_ready(self):
|
|
169
|
+
deadline = time.time() + SERVER_START_TIMEOUT
|
|
170
|
+
while time.time() < deadline:
|
|
171
|
+
if self.process.poll() is not None:
|
|
172
|
+
raise EngineError(f"llama-server stopped while loading the model. Log: {self.log_path}")
|
|
173
|
+
try:
|
|
174
|
+
with urllib.request.urlopen(f"{self.url}/health", timeout=5) as response:
|
|
175
|
+
if response.status == 200:
|
|
176
|
+
return
|
|
177
|
+
except (urllib.error.URLError, ConnectionError, OSError):
|
|
178
|
+
pass # still loading: /health answers 503 or refuses the connection until the model is in memory
|
|
179
|
+
time.sleep(1)
|
|
180
|
+
raise EngineError(f"llama-server was not ready after {SERVER_START_TIMEOUT} s. Log: {self.log_path}")
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"""Command line entry point: `nock setup`, `nock doctor`, `nock video ...`."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import shutil
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
import urllib.error
|
|
8
|
+
|
|
9
|
+
from nock_cli import __version__, engine, models, paths, video
|
|
10
|
+
|
|
11
|
+
SKILLS = sorted(models.MODELS)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def command_setup(args):
|
|
15
|
+
settings = paths.load_settings()
|
|
16
|
+
print(f"Nock home: {paths.nock_home()}")
|
|
17
|
+
existing = engine.locate_server(settings)
|
|
18
|
+
if existing and not args.backend:
|
|
19
|
+
print(f"Engine: {existing} (nock setup --backend vulkan|cpu|metal installs Nock's own build)")
|
|
20
|
+
else:
|
|
21
|
+
print("Installing the engine (llama.cpp, from github.com/ggml-org/llama.cpp)...")
|
|
22
|
+
settings["llama_server"] = str(engine.install(args.backend))
|
|
23
|
+
settings["llama_cpp_build"] = engine.LLAMA_CPP_BUILD
|
|
24
|
+
for skill in args.skills or SKILLS:
|
|
25
|
+
spec = models.MODELS[skill]
|
|
26
|
+
print(f"Downloading {spec['title']} from huggingface.co/{spec['repo']}...")
|
|
27
|
+
settings.setdefault("models", {})[skill] = models.install(skill)
|
|
28
|
+
paths.save_settings(settings)
|
|
29
|
+
print("Ready. Try: nock video summarize my_video.mp4")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def check(label, ok, detail):
|
|
33
|
+
print(f" [{'ok' if ok else '--'}] {label}: {detail}")
|
|
34
|
+
return ok
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def command_doctor(args):
|
|
38
|
+
settings = paths.load_settings()
|
|
39
|
+
print(f"nock {__version__}, home {paths.nock_home()}")
|
|
40
|
+
server = engine.locate_server(settings)
|
|
41
|
+
ready = check("engine", bool(server), server or "missing: run `nock setup`")
|
|
42
|
+
ready &= check("ffmpeg", bool(shutil.which("ffmpeg") and shutil.which("ffprobe")),
|
|
43
|
+
shutil.which("ffmpeg") or "missing: install ffmpeg (https://ffmpeg.org/download.html)")
|
|
44
|
+
check("yt-dlp (optional, for links)", bool(shutil.which("yt-dlp")), shutil.which("yt-dlp") or "not installed: pipx inject nock-cli yt-dlp")
|
|
45
|
+
for skill in SKILLS:
|
|
46
|
+
installed = settings.get("models", {}).get(skill)
|
|
47
|
+
ready &= check(f"model {skill}", bool(installed), f"{installed['repo']}@{installed['revision'][:7]}" if installed else "missing: run `nock setup`")
|
|
48
|
+
memory = video.gpu_memory_mb()
|
|
49
|
+
check("NVIDIA GPU", memory is not None,
|
|
50
|
+
f"{memory} MB" if memory is not None else "not found (other GPUs work through Vulkan or Metal; CPU only is slow)")
|
|
51
|
+
free_gb = shutil.disk_usage(paths.nock_home().anchor or "/").free / 1e9
|
|
52
|
+
check("free disk", free_gb > 5, f"{free_gb:.0f} GB (setup needs about 4 GB)")
|
|
53
|
+
return 0 if ready else 1
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def start_server_factory(skill):
|
|
57
|
+
settings = paths.load_settings()
|
|
58
|
+
server_binary = engine.locate_server(settings)
|
|
59
|
+
installed = settings.get("models", {}).get(skill)
|
|
60
|
+
if not server_binary or not installed:
|
|
61
|
+
sys.exit("Nock is not set up yet. Run: nock setup")
|
|
62
|
+
log_path = paths.nock_home() / "logs" / f"{skill}-server.log"
|
|
63
|
+
|
|
64
|
+
def start(context):
|
|
65
|
+
return engine.LocalServer(server_binary, installed["model"], installed["mmproj"], context, 99, log_path)
|
|
66
|
+
|
|
67
|
+
return start
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def command_video(args):
|
|
71
|
+
kind = {"summarize": "summary", "ask": "ask", "find": "moment"}[args.action]
|
|
72
|
+
question = video.SUMMARY_QUESTION if kind == "summary" else args.question
|
|
73
|
+
frames = video.choose_frames(args.frames)
|
|
74
|
+
answer = video.run(args.source, question, kind, frames, start_server_factory("video"))
|
|
75
|
+
print(answer)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def build_parser():
|
|
79
|
+
parser = argparse.ArgumentParser(prog="nock", description="Open models that live on your machine.")
|
|
80
|
+
parser.add_argument("--version", action="version", version=f"nock {__version__}")
|
|
81
|
+
commands = parser.add_subparsers(dest="command", required=True)
|
|
82
|
+
|
|
83
|
+
setup = commands.add_parser("setup", help="download the engine and the models (once)")
|
|
84
|
+
setup.add_argument("skills", nargs="*", choices=SKILLS, help="which models (default: all)")
|
|
85
|
+
setup.add_argument("--backend", choices=engine.BACKENDS, help="llama.cpp build: vulkan (default), cpu, metal (Mac)")
|
|
86
|
+
setup.set_defaults(handler=command_setup)
|
|
87
|
+
|
|
88
|
+
doctor = commands.add_parser("doctor", help="check that everything is in place")
|
|
89
|
+
doctor.set_defaults(handler=command_doctor)
|
|
90
|
+
|
|
91
|
+
video_parser = commands.add_parser("video", help="ask about a video file or link, offline")
|
|
92
|
+
actions = video_parser.add_subparsers(dest="action", required=True)
|
|
93
|
+
summarize = actions.add_parser("summarize", help="a few short points about the video")
|
|
94
|
+
summarize.add_argument("source", help="video file or link")
|
|
95
|
+
ask = actions.add_parser("ask", help="a question about what the video shows")
|
|
96
|
+
ask.add_argument("source", help="video file or link")
|
|
97
|
+
ask.add_argument("question")
|
|
98
|
+
find = actions.add_parser("find", help="when does something happen")
|
|
99
|
+
find.add_argument("source", help="video file or link")
|
|
100
|
+
find.add_argument("question", help='what to find, for example "the error message shows up"')
|
|
101
|
+
for action in (summarize, ask, find):
|
|
102
|
+
action.add_argument("--frames", type=int, help=f"frames to read (default {video.MAX_FRAMES}, "
|
|
103
|
+
f"{video.LOW_MEMORY_FRAMES} on GPUs under 6 GB)")
|
|
104
|
+
video_parser.set_defaults(handler=command_video)
|
|
105
|
+
return parser
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def main(argv=None):
|
|
109
|
+
args = build_parser().parse_args(argv)
|
|
110
|
+
try:
|
|
111
|
+
result = args.handler(args)
|
|
112
|
+
except KeyboardInterrupt:
|
|
113
|
+
sys.exit("Stopped.")
|
|
114
|
+
except (engine.EngineError, models.ModelError, video.VideoError) as error:
|
|
115
|
+
sys.exit(f"nock: {error}")
|
|
116
|
+
except subprocess.CalledProcessError as error:
|
|
117
|
+
sys.exit(f"nock: {error.cmd[0]} failed (exit code {error.returncode})")
|
|
118
|
+
except urllib.error.URLError as error:
|
|
119
|
+
sys.exit(f"nock: network error: {error.reason}")
|
|
120
|
+
sys.exit(result or 0)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
if __name__ == "__main__":
|
|
124
|
+
main()
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Model files from Hugging Face. The file names are read from the repo, so a new release needs no CLI update."""
|
|
2
|
+
|
|
3
|
+
import fnmatch
|
|
4
|
+
|
|
5
|
+
from nock_cli import paths
|
|
6
|
+
from nock_cli.download import download, get_json
|
|
7
|
+
|
|
8
|
+
MODELS = {
|
|
9
|
+
"video": {
|
|
10
|
+
"repo": "Nock-AI/nock-video-4b-GGUF",
|
|
11
|
+
"title": "Nock Video 4B",
|
|
12
|
+
"model_pattern": "*Q4_K_M.gguf",
|
|
13
|
+
"mmproj_pattern": "mmproj*.gguf",
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ModelError(Exception):
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def pick_file(files, pattern, exclude_pattern=None):
|
|
23
|
+
matches = [name for name in files if fnmatch.fnmatch(name, pattern)
|
|
24
|
+
and not (exclude_pattern and fnmatch.fnmatch(name, exclude_pattern))]
|
|
25
|
+
if len(matches) != 1:
|
|
26
|
+
raise ModelError(f"Expected one file matching {pattern}, found {matches or 'none'}")
|
|
27
|
+
return matches[0]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def install(skill):
|
|
31
|
+
"""Downloads the model and its vision projector into ~/.nock/models/<skill>/<revision>/."""
|
|
32
|
+
spec = MODELS[skill]
|
|
33
|
+
info = get_json(f"https://huggingface.co/api/models/{spec['repo']}")
|
|
34
|
+
revision = info["sha"]
|
|
35
|
+
files = [entry["rfilename"] for entry in info.get("siblings", [])]
|
|
36
|
+
model_file = pick_file(files, spec["model_pattern"], exclude_pattern=spec["mmproj_pattern"])
|
|
37
|
+
mmproj_file = pick_file(files, spec["mmproj_pattern"])
|
|
38
|
+
folder = paths.models_dir() / skill / revision[:7]
|
|
39
|
+
base = f"https://huggingface.co/{spec['repo']}/resolve/{revision}"
|
|
40
|
+
model_path = download(f"{base}/{model_file}", folder / model_file, model_file)
|
|
41
|
+
mmproj_path = download(f"{base}/{mmproj_file}", folder / mmproj_file, mmproj_file)
|
|
42
|
+
return {"repo": spec["repo"], "revision": revision, "model": str(model_path), "mmproj": str(mmproj_path)}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Where Nock keeps its files, and the small settings file that remembers what `nock setup` installed."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def nock_home():
|
|
9
|
+
"""~/.nock by default; NOCK_HOME moves everything (for example to a bigger drive)."""
|
|
10
|
+
return Path(os.environ.get("NOCK_HOME") or Path.home() / ".nock")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def engine_dir():
|
|
14
|
+
return nock_home() / "engine"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def models_dir():
|
|
18
|
+
return nock_home() / "models"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def settings_path():
|
|
22
|
+
return nock_home() / "settings.json"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def load_settings():
|
|
26
|
+
path = settings_path()
|
|
27
|
+
if not path.exists():
|
|
28
|
+
return {}
|
|
29
|
+
try:
|
|
30
|
+
return json.loads(path.read_text(encoding="utf-8"))
|
|
31
|
+
except (OSError, ValueError):
|
|
32
|
+
return {}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def save_settings(settings):
|
|
36
|
+
path = settings_path()
|
|
37
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
38
|
+
path.write_text(json.dumps(settings, indent=2), encoding="utf-8")
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"""Nock Video: summarize a video, ask about it, or find a moment, offline.
|
|
2
|
+
|
|
3
|
+
The input matches the setup our published scores were measured with: up to 64 frames (1 per second for short
|
|
4
|
+
videos), 768 px wide, each labelled "Frame at N s:", then the question and a fixed instruction, greedy decoding,
|
|
5
|
+
thinking off. The frames are written to a temporary folder and deleted afterwards.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import base64
|
|
9
|
+
import json
|
|
10
|
+
import math
|
|
11
|
+
import re
|
|
12
|
+
import shutil
|
|
13
|
+
import subprocess
|
|
14
|
+
import sys
|
|
15
|
+
import tempfile
|
|
16
|
+
import urllib.request
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
MAX_FRAMES = 64
|
|
20
|
+
LOW_MEMORY_FRAMES = 32
|
|
21
|
+
FRAME_WIDTH = 768
|
|
22
|
+
SMALL_GPU_MB = 6000 # 64 frames peaked at 5.5 GB on the GPU in our test, so smaller cards start at 32
|
|
23
|
+
PREAMBLE = "These are frames from one video, in order. Each frame is labeled with its time in seconds."
|
|
24
|
+
INSTRUCTIONS = {
|
|
25
|
+
"moment": "Give the whole stretch of time when this is happening, from the first frame where it starts to the last "
|
|
26
|
+
"frame where it is still visible. Answer only with START-END in seconds.",
|
|
27
|
+
"ask": "Answer in one short sentence.",
|
|
28
|
+
"summary": "Answer with 3 to 5 short bullet points. Only include what the video shows.",
|
|
29
|
+
}
|
|
30
|
+
MAX_TOKENS = {"moment": 32, "ask": 64, "summary": 256}
|
|
31
|
+
SUMMARY_QUESTION = "Summarize this video in a few short points."
|
|
32
|
+
REQUEST_TIMEOUT = 1800 # CPU-only machines can take many minutes for 64 frames
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class VideoError(Exception):
|
|
36
|
+
pass
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def is_link(source):
|
|
40
|
+
return re.match(r"^https?://", source, re.IGNORECASE) is not None
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def require_tool(name, hint):
|
|
44
|
+
if not shutil.which(name):
|
|
45
|
+
raise VideoError(f"{name} was not found on the PATH. {hint}")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def fetch_link(url, folder):
|
|
49
|
+
"""Downloads a link to this machine with yt-dlp, which the user installs themselves (pipx inject nock-cli yt-dlp)."""
|
|
50
|
+
command = [shutil.which("yt-dlp")] if shutil.which("yt-dlp") else None
|
|
51
|
+
if not command:
|
|
52
|
+
try:
|
|
53
|
+
import yt_dlp # noqa: F401 (only checks that the module is there)
|
|
54
|
+
command = [sys.executable, "-m", "yt_dlp"]
|
|
55
|
+
except ImportError:
|
|
56
|
+
raise VideoError("Links need yt-dlp. Install it with: pipx inject nock-cli yt-dlp (or: pip install yt-dlp)")
|
|
57
|
+
print("Downloading the video to this machine with yt-dlp. Only use videos you have the right to use.", file=sys.stderr)
|
|
58
|
+
template = str(Path(folder) / "video.%(ext)s")
|
|
59
|
+
# 720p is plenty: frames are scaled to 768 px wide anyway. Audio is not used.
|
|
60
|
+
subprocess.run(command + ["-q", "--no-playlist", "-f", "bv*[height<=720]/b[height<=720]/bv*/b", "-o", template, url], check=True)
|
|
61
|
+
downloaded = [path for path in Path(folder).glob("video.*") if path.suffix != ".part"]
|
|
62
|
+
if not downloaded:
|
|
63
|
+
raise VideoError("yt-dlp finished but no video file was written")
|
|
64
|
+
return downloaded[0]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def video_duration(path):
|
|
68
|
+
output = subprocess.run(["ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "csv=p=0", str(path)],
|
|
69
|
+
capture_output=True, text=True)
|
|
70
|
+
try:
|
|
71
|
+
return float(output.stdout.strip())
|
|
72
|
+
except ValueError:
|
|
73
|
+
raise VideoError(f"Could not read the length of {path}. Is it a video file?")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def frame_times(duration, max_frames=MAX_FRAMES):
|
|
77
|
+
"""Evenly spaced frame times: 1 per second for short videos, at most max_frames for long ones."""
|
|
78
|
+
count = min(max_frames, max(1, math.ceil(duration)))
|
|
79
|
+
return [round((index + 0.5) * duration / count, 1) for index in range(count)]
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def extract_frames(video, folder, max_frames):
|
|
83
|
+
# 0.2 s off the end: some files report a length a little past their last frame.
|
|
84
|
+
duration = max(0.5, video_duration(video) - 0.2)
|
|
85
|
+
frames = []
|
|
86
|
+
for index, seconds in enumerate(frame_times(duration, max_frames)):
|
|
87
|
+
path = Path(folder) / f"{index:03d}.jpg"
|
|
88
|
+
subprocess.run(["ffmpeg", "-loglevel", "error", "-y", "-ss", str(seconds), "-i", str(video), "-frames:v", "1",
|
|
89
|
+
"-vf", f"scale={FRAME_WIDTH}:-2", "-q:v", "3", str(path)], check=True)
|
|
90
|
+
frames.append((seconds, path))
|
|
91
|
+
return frames
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def build_request(frames, question, kind):
|
|
95
|
+
content = [{"type": "text", "text": PREAMBLE}]
|
|
96
|
+
for seconds, path in frames:
|
|
97
|
+
encoded = base64.b64encode(Path(path).read_bytes()).decode()
|
|
98
|
+
content.append({"type": "text", "text": f"Frame at {seconds} s:"})
|
|
99
|
+
content.append({"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{encoded}"}})
|
|
100
|
+
content.append({"type": "text", "text": f"{question} {INSTRUCTIONS[kind]}"})
|
|
101
|
+
return {"messages": [{"role": "user", "content": content}], "temperature": 0, "max_tokens": MAX_TOKENS[kind],
|
|
102
|
+
"chat_template_kwargs": {"enable_thinking": False}}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def ask_server(server_url, body):
|
|
106
|
+
request = urllib.request.Request(f"{server_url}/v1/chat/completions", data=json.dumps(body).encode(),
|
|
107
|
+
headers={"Content-Type": "application/json"})
|
|
108
|
+
with urllib.request.urlopen(request, timeout=REQUEST_TIMEOUT) as response:
|
|
109
|
+
return json.load(response)["choices"][0]["message"]["content"].strip()
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def parse_span(text):
|
|
113
|
+
"""First two numbers (seconds, or m:ss) in the answer, as a (start, end) pair."""
|
|
114
|
+
values = []
|
|
115
|
+
for match in re.finditer(r"(\d+):(\d{1,2}(?:\.\d+)?)|(\d+(?:\.\d+)?)", text):
|
|
116
|
+
values.append(int(match.group(1)) * 60 + float(match.group(2)) if match.group(1) else float(match.group(3)))
|
|
117
|
+
if len(values) == 2:
|
|
118
|
+
break
|
|
119
|
+
if len(values) < 2:
|
|
120
|
+
return None
|
|
121
|
+
start, end = sorted(values)
|
|
122
|
+
return start, end
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def clock(seconds):
|
|
126
|
+
seconds = int(round(seconds))
|
|
127
|
+
hours, rest = divmod(seconds, 3600)
|
|
128
|
+
minutes, secs = divmod(rest, 60)
|
|
129
|
+
return f"{hours}:{minutes:02d}:{secs:02d}" if hours else f"{minutes}:{secs:02d}"
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def format_answer(kind, answer):
|
|
133
|
+
if kind != "moment":
|
|
134
|
+
return answer
|
|
135
|
+
span = parse_span(answer)
|
|
136
|
+
if not span:
|
|
137
|
+
return f"No clear moment found. The model answered: {answer}"
|
|
138
|
+
return f"{clock(span[0])} to {clock(span[1])} ({span[0]:g}-{span[1]:g} s)"
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def gpu_memory_mb():
|
|
142
|
+
"""Total memory of the first NVIDIA GPU, or None when nvidia-smi is not there (other GPUs are not measured)."""
|
|
143
|
+
if not shutil.which("nvidia-smi"):
|
|
144
|
+
return None
|
|
145
|
+
output = subprocess.run(["nvidia-smi", "--query-gpu=memory.total", "--format=csv,noheader,nounits"],
|
|
146
|
+
capture_output=True, text=True)
|
|
147
|
+
try:
|
|
148
|
+
return int(output.stdout.strip().splitlines()[0])
|
|
149
|
+
except (ValueError, IndexError):
|
|
150
|
+
return None
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def choose_frames(requested):
|
|
154
|
+
if requested:
|
|
155
|
+
return requested
|
|
156
|
+
memory = gpu_memory_mb()
|
|
157
|
+
if memory is not None and memory < SMALL_GPU_MB:
|
|
158
|
+
print(f"GPU has {memory} MB: using {LOW_MEMORY_FRAMES} frames (less accurate at finding moments; "
|
|
159
|
+
f"--frames {MAX_FRAMES} to override).", file=sys.stderr)
|
|
160
|
+
return LOW_MEMORY_FRAMES
|
|
161
|
+
return MAX_FRAMES
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def context_for(frame_count):
|
|
165
|
+
# 64 frames took about 22K prompt tokens in our test; leave room for the answer.
|
|
166
|
+
return 32768 if frame_count > LOW_MEMORY_FRAMES else 16384
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def run(source, question, kind, frame_count, start_server):
|
|
170
|
+
"""start_server(context) returns a context manager with a .url; it is started only after the frames are ready."""
|
|
171
|
+
require_tool("ffmpeg", "Install ffmpeg (https://ffmpeg.org/download.html), then try again. Run `nock doctor` to check.")
|
|
172
|
+
require_tool("ffprobe", "ffprobe comes with ffmpeg. Run `nock doctor` to check.")
|
|
173
|
+
with tempfile.TemporaryDirectory(prefix="nock-") as folder:
|
|
174
|
+
video = fetch_link(source, folder) if is_link(source) else Path(source)
|
|
175
|
+
if not video.exists():
|
|
176
|
+
raise VideoError(f"File not found: {video}")
|
|
177
|
+
frames = extract_frames(video, folder, frame_count)
|
|
178
|
+
print(f"Read {len(frames)} frames.", file=sys.stderr)
|
|
179
|
+
body = build_request(frames, question, kind)
|
|
180
|
+
with start_server(context_for(frame_count)) as server:
|
|
181
|
+
print("Thinking...", file=sys.stderr)
|
|
182
|
+
return format_answer(kind, ask_server(server.url, body))
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nock-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Open models that live on your machine. Ask questions about your videos, offline.
|
|
5
|
+
Author: NockAI
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://nockai.dev
|
|
8
|
+
Project-URL: Model, https://huggingface.co/Nock-AI/nock-video-4b-GGUF
|
|
9
|
+
Keywords: local,offline,llm,video,llama.cpp,gguf
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
12
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
13
|
+
Classifier: Operating System :: MacOS
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Multimedia :: Video
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Provides-Extra: links
|
|
21
|
+
Requires-Dist: yt-dlp; extra == "links"
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# Nock CLI
|
|
25
|
+
|
|
26
|
+
Open models that live on your machine. Ask questions about your videos, offline.
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
nock video summarize my_video.mp4
|
|
30
|
+
nock video ask my_video.mp4 "What error message shows on screen?"
|
|
31
|
+
nock video find my_video.mp4 "when the error message shows up"
|
|
32
|
+
nock video summarize "https://www.youtube.com/watch?v=..."
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Everything runs on your computer. Frames are read into a temporary folder, sent to a model running on
|
|
36
|
+
`127.0.0.1`, and deleted when the answer is ready. Nothing is uploaded.
|
|
37
|
+
|
|
38
|
+
## Install
|
|
39
|
+
|
|
40
|
+
You need Python 3.9 or newer and [ffmpeg](https://ffmpeg.org/download.html).
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pipx install nock-cli
|
|
44
|
+
nock setup
|
|
45
|
+
nock doctor
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`nock setup` downloads, once:
|
|
49
|
+
- the engine: an official [llama.cpp](https://github.com/ggml-org/llama.cpp) build (about 35 MB; Vulkan on Windows
|
|
50
|
+
and Linux, Metal on Apple Silicon). Already have `llama-server`? Nock uses it.
|
|
51
|
+
- the model: [Nock Video 4B](https://huggingface.co/Nock-AI/nock-video-4b-GGUF) (about 3.4 GB).
|
|
52
|
+
|
|
53
|
+
Files go to `~/.nock` (set `NOCK_HOME` to use another folder).
|
|
54
|
+
|
|
55
|
+
### Links
|
|
56
|
+
|
|
57
|
+
Links are downloaded to your own machine with [yt-dlp](https://github.com/yt-dlp/yt-dlp), which you install
|
|
58
|
+
yourself:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pipx inject nock-cli yt-dlp
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Only use videos you have the right to use.
|
|
65
|
+
|
|
66
|
+
## What to expect
|
|
67
|
+
|
|
68
|
+
Nock Video 4B is a **preview**. On our test of 20 videos, through llama.cpp at 64 frames, it found the moment in
|
|
69
|
+
42 of 56 questions, answered 56 of 60 questions about what is on screen, and gave 6 of 7 good summaries. Full
|
|
70
|
+
results, including the misses, are on the [model card](https://huggingface.co/Nock-AI/nock-video-4b-GGUF).
|
|
71
|
+
|
|
72
|
+
- It reads frames only, not sound.
|
|
73
|
+
- A long video is read as at most 64 frames, so short events in long videos can be missed.
|
|
74
|
+
- 64 frames used about 5.5 GB of GPU memory in our test. On GPUs under 6 GB, Nock uses 32 frames (finding the
|
|
75
|
+
moment drops: 42 to 35 of 56 on our test). `--frames` overrides it.
|
|
76
|
+
- Without a GPU it works, but slowly: minutes per question.
|
|
77
|
+
|
|
78
|
+
## Options
|
|
79
|
+
|
|
80
|
+
| Option | Meaning |
|
|
81
|
+
|---|---|
|
|
82
|
+
| `--frames N` | frames to read (default 64, 32 on GPUs under 6 GB) |
|
|
83
|
+
| `nock setup --backend cpu` | CPU-only engine |
|
|
84
|
+
| `NOCK_LLAMA_SERVER=/path/llama-server` | use your own llama.cpp build |
|
|
85
|
+
|
|
86
|
+
Server logs are in `~/.nock/logs/` if something goes wrong.
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
Apache-2.0. The model has its own license on its model card (Apache-2.0, from Qwen3.5 4B).
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/nock_cli/__init__.py
|
|
5
|
+
src/nock_cli/__main__.py
|
|
6
|
+
src/nock_cli/download.py
|
|
7
|
+
src/nock_cli/engine.py
|
|
8
|
+
src/nock_cli/main.py
|
|
9
|
+
src/nock_cli/models.py
|
|
10
|
+
src/nock_cli/paths.py
|
|
11
|
+
src/nock_cli/video.py
|
|
12
|
+
src/nock_cli.egg-info/PKG-INFO
|
|
13
|
+
src/nock_cli.egg-info/SOURCES.txt
|
|
14
|
+
src/nock_cli.egg-info/dependency_links.txt
|
|
15
|
+
src/nock_cli.egg-info/entry_points.txt
|
|
16
|
+
src/nock_cli.egg-info/requires.txt
|
|
17
|
+
src/nock_cli.egg-info/top_level.txt
|
|
18
|
+
tests/test_cli.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
nock_cli
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""Fast checks that need no model, GPU or network: python -m unittest discover -s tests"""
|
|
2
|
+
|
|
3
|
+
import io
|
|
4
|
+
import tarfile
|
|
5
|
+
import tempfile
|
|
6
|
+
import unittest
|
|
7
|
+
import zipfile
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from nock_cli import engine, main, models, video
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class FrameTimesTest(unittest.TestCase):
|
|
14
|
+
def test_short_video_gets_one_frame_per_second(self):
|
|
15
|
+
self.assertEqual(video.frame_times(4.0), [0.5, 1.5, 2.5, 3.5])
|
|
16
|
+
|
|
17
|
+
def test_long_video_is_capped(self):
|
|
18
|
+
times = video.frame_times(600.0, max_frames=64)
|
|
19
|
+
self.assertEqual(len(times), 64)
|
|
20
|
+
self.assertLess(times[-1], 600.0)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ParseSpanTest(unittest.TestCase):
|
|
24
|
+
def test_seconds(self):
|
|
25
|
+
self.assertEqual(video.parse_span("12-20"), (12.0, 20.0))
|
|
26
|
+
|
|
27
|
+
def test_minutes_and_reversed(self):
|
|
28
|
+
self.assertEqual(video.parse_span("from 1:30 to 0:45"), (45.0, 90.0))
|
|
29
|
+
|
|
30
|
+
def test_no_span(self):
|
|
31
|
+
self.assertIsNone(video.parse_span("I could not find it"))
|
|
32
|
+
|
|
33
|
+
def test_format(self):
|
|
34
|
+
self.assertEqual(video.format_answer("moment", "75-130"), "1:15 to 2:10 (75-130 s)")
|
|
35
|
+
self.assertTrue(video.format_answer("moment", "never").startswith("No clear moment"))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class RequestTest(unittest.TestCase):
|
|
39
|
+
def test_matches_the_measured_prompt(self):
|
|
40
|
+
with tempfile.TemporaryDirectory() as folder:
|
|
41
|
+
frame = Path(folder) / "000.jpg"
|
|
42
|
+
frame.write_bytes(b"jpg")
|
|
43
|
+
body = video.build_request([(0.5, frame)], "When?", "moment")
|
|
44
|
+
content = body["messages"][0]["content"]
|
|
45
|
+
self.assertEqual(content[0]["text"], video.PREAMBLE)
|
|
46
|
+
self.assertEqual(content[1]["text"], "Frame at 0.5 s:")
|
|
47
|
+
self.assertTrue(content[-1]["text"].startswith("When? Give the whole stretch"))
|
|
48
|
+
self.assertEqual(body["temperature"], 0)
|
|
49
|
+
self.assertFalse(body["chat_template_kwargs"]["enable_thinking"])
|
|
50
|
+
|
|
51
|
+
def test_links(self):
|
|
52
|
+
self.assertTrue(video.is_link("https://www.youtube.com/watch?v=x"))
|
|
53
|
+
self.assertFalse(video.is_link("C:/videos/https.mp4"))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class EngineTest(unittest.TestCase):
|
|
57
|
+
def test_assets_exist_for_main_systems(self):
|
|
58
|
+
self.assertEqual(engine.asset_name("windows", "x64", "vulkan"), f"llama-{engine.LLAMA_CPP_BUILD}-bin-win-vulkan-x64.zip")
|
|
59
|
+
self.assertTrue(engine.asset_name("macos", "arm64", "metal").endswith("macos-arm64.tar.gz"))
|
|
60
|
+
with self.assertRaises(engine.EngineError):
|
|
61
|
+
engine.asset_name("macos", "arm64", "vulkan")
|
|
62
|
+
|
|
63
|
+
def test_refuses_archive_escape(self):
|
|
64
|
+
with tempfile.TemporaryDirectory() as folder:
|
|
65
|
+
archive = Path(folder) / "bad.zip"
|
|
66
|
+
with zipfile.ZipFile(archive, "w") as bundle:
|
|
67
|
+
bundle.writestr("../evil.txt", "x")
|
|
68
|
+
with self.assertRaises(engine.EngineError):
|
|
69
|
+
engine.unpack(archive, Path(folder) / "out")
|
|
70
|
+
|
|
71
|
+
def test_unpacks_tar(self):
|
|
72
|
+
with tempfile.TemporaryDirectory() as folder:
|
|
73
|
+
archive = Path(folder) / "ok.tar.gz"
|
|
74
|
+
with tarfile.open(archive, "w:gz") as bundle:
|
|
75
|
+
data = b"#!/bin/sh"
|
|
76
|
+
info = tarfile.TarInfo("build/bin/llama-server")
|
|
77
|
+
info.size = len(data)
|
|
78
|
+
bundle.addfile(info, io.BytesIO(data))
|
|
79
|
+
engine.unpack(archive, Path(folder) / "out")
|
|
80
|
+
self.assertTrue((Path(folder) / "out/build/bin/llama-server").exists())
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class ModelsTest(unittest.TestCase):
|
|
84
|
+
def test_picks_model_not_projector(self):
|
|
85
|
+
files = ["README.md", "mmproj-F16.gguf", "nock-video-4b-run1-Q4_K_M.gguf"]
|
|
86
|
+
self.assertEqual(models.pick_file(files, "*Q4_K_M.gguf", "mmproj*.gguf"), "nock-video-4b-run1-Q4_K_M.gguf")
|
|
87
|
+
self.assertEqual(models.pick_file(files, "mmproj*.gguf"), "mmproj-F16.gguf")
|
|
88
|
+
with self.assertRaises(models.ModelError):
|
|
89
|
+
models.pick_file(files + ["other-Q4_K_M.gguf"], "*Q4_K_M.gguf", "mmproj*.gguf")
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class ParserTest(unittest.TestCase):
|
|
93
|
+
def test_commands_parse(self):
|
|
94
|
+
parser = main.build_parser()
|
|
95
|
+
args = parser.parse_args(["video", "find", "clip.mp4", "the goal", "--frames", "32"])
|
|
96
|
+
self.assertEqual((args.action, args.source, args.question, args.frames), ("find", "clip.mp4", "the goal", 32))
|
|
97
|
+
self.assertEqual(parser.parse_args(["video", "summarize", "https://youtu.be/x"]).source, "https://youtu.be/x")
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
if __name__ == "__main__":
|
|
101
|
+
unittest.main()
|
nock_cli-0.0.0/PKG-INFO
DELETED
|
File without changes
|