perceptron 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.
Files changed (40) hide show
  1. perceptron-0.1.0/HISTORY.md +10 -0
  2. perceptron-0.1.0/LICENSE +80 -0
  3. perceptron-0.1.0/MANIFEST.in +3 -0
  4. perceptron-0.1.0/PKG-INFO +192 -0
  5. perceptron-0.1.0/README.md +168 -0
  6. perceptron-0.1.0/pyproject.toml +41 -0
  7. perceptron-0.1.0/setup.cfg +4 -0
  8. perceptron-0.1.0/src/perceptron/__init__.py +108 -0
  9. perceptron-0.1.0/src/perceptron/annotations.py +267 -0
  10. perceptron-0.1.0/src/perceptron/cli.py +779 -0
  11. perceptron-0.1.0/src/perceptron/client.py +521 -0
  12. perceptron-0.1.0/src/perceptron/config.py +100 -0
  13. perceptron-0.1.0/src/perceptron/dsl/nodes.py +141 -0
  14. perceptron-0.1.0/src/perceptron/dsl/perceive.py +485 -0
  15. perceptron-0.1.0/src/perceptron/errors.py +59 -0
  16. perceptron-0.1.0/src/perceptron/highlevel.py +555 -0
  17. perceptron-0.1.0/src/perceptron/pointing/parser.py +311 -0
  18. perceptron-0.1.0/src/perceptron/pointing/types.py +87 -0
  19. perceptron-0.1.0/src/perceptron/tensorstream/__init__.py +29 -0
  20. perceptron-0.1.0/src/perceptron/tensorstream/ops.py +262 -0
  21. perceptron-0.1.0/src/perceptron/tensorstream/tensorstream.py +721 -0
  22. perceptron-0.1.0/src/perceptron.egg-info/PKG-INFO +192 -0
  23. perceptron-0.1.0/src/perceptron.egg-info/SOURCES.txt +38 -0
  24. perceptron-0.1.0/src/perceptron.egg-info/dependency_links.txt +1 -0
  25. perceptron-0.1.0/src/perceptron.egg-info/entry_points.txt +2 -0
  26. perceptron-0.1.0/src/perceptron.egg-info/requires.txt +17 -0
  27. perceptron-0.1.0/src/perceptron.egg-info/top_level.txt +1 -0
  28. perceptron-0.1.0/tests/test_async_client.py +133 -0
  29. perceptron-0.1.0/tests/test_async_perceive.py +91 -0
  30. perceptron-0.1.0/tests/test_cli.py +209 -0
  31. perceptron-0.1.0/tests/test_dsl_compile.py +18 -0
  32. perceptron-0.1.0/tests/test_highlevel_caption_ocr.py +44 -0
  33. perceptron-0.1.0/tests/test_highlevel_detect.py +299 -0
  34. perceptron-0.1.0/tests/test_perceive_inspect.py +56 -0
  35. perceptron-0.1.0/tests/test_pointing_parser.py +127 -0
  36. perceptron-0.1.0/tests/test_streaming.py +87 -0
  37. perceptron-0.1.0/tests/test_streaming_buffer.py +60 -0
  38. perceptron-0.1.0/tests/test_transport_payloads.py +130 -0
  39. perceptron-0.1.0/tests/test_validation.py +108 -0
  40. perceptron-0.1.0/tests/test_validation_polygon.py +52 -0
@@ -0,0 +1,10 @@
1
+ Changelog
2
+ =========
3
+
4
+ 0.1.0 (2025-09-17)
5
+ ------------------
6
+
7
+ - Initial public scaffolding of the Perceptron SDK.
8
+ - CLI entry point `perceptron` with Typer.
9
+ - Core DSL, pointing utilities, and high-level helpers.
10
+
@@ -0,0 +1,80 @@
1
+ # Perceptron, Inc. Non-Production License
2
+
3
+ ## 1. Scope and acceptance
4
+
5
+ **1.1. Scope of the Agreement.**
6
+ This Agreement applies to any use, modification, or Distribution of any Perceptron Model by You, regardless of the source You obtained a copy of such Perceptron Model.
7
+
8
+ **1.2. Acceptance.** By accessing, using, modifying, Distributing a Perceptron Model, or by creating, using or distributing a Derivative of the Perceptron Model, You agree to be bound by this Agreement.
9
+
10
+ **1.3. Acceptance on behalf of a third-party.** If You accept this Agreement on behalf of Your employer or another person or entity, You warrant and represent that You have the authority to act and accept this Agreement on their behalf. In such a case, the word “You” in this Agreement will refer to Your employer or such other person or entity.
11
+
12
+ ## 2. License
13
+ **2.1. Grant of rights.** Subject to Section 3 below, Perceptron, Inc. hereby grants You a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable, limited license to use, copy, modify, and Distribute under the conditions provided in Section 2.2 below, the Perceptron Model and any Derivatives made by or for Perceptron, Inc. and to create Derivatives of the Perceptron Model.
14
+
15
+ **2.2. Distribution of Perceptron Model and Derivatives made by or for Perceptron, Inc..** Subject to Section 3 below, You may Distribute copies of the Perceptron Model and/or Derivatives made by or for Perceptron, Inc., under the following conditions:
16
+ - You must make available a copy of this Agreement to third-party recipients of the Perceptron Models and/or Derivatives made by or for Perceptron, Inc. you Distribute, it being specified that any rights to use the Perceptron Models and/or Derivatives made by or for Perceptron, Inc. shall be directly granted by Perceptron, Inc. to said third-party recipients pursuant to the Perceptron, Inc. Non-Production License agreement executed between these parties;
17
+ - You must retain in all copies of the Perceptron Models the following attribution notice within a “Notice” text file distributed as part of such copies: “Licensed by Perceptron, Inc. under the Perceptron, Inc. Non-Production License”.
18
+
19
+ **2.3. Distribution of Derivatives made by or for You.** Subject to Section 3 below, You may Distribute any Derivatives made by or for You under additional or different terms and conditions, provided that:
20
+ - In any event, the use and modification of Perceptron Model and/or Derivatives made by or for Perceptron, Inc. shall remain governed by the terms and conditions of this Agreement;
21
+ - You include in any such Derivatives made by or for You prominent notices stating that You modified the concerned Perceptron Model; and
22
+ - Any terms and conditions You impose on any third-party recipients relating to Derivatives made by or for You shall neither limit such third-party recipients’ use of the Perceptron Model or any Derivatives made by or for Perceptron, Inc. in accordance with the Perceptron, Inc. Non-Production License nor conflict with any of its terms and conditions.
23
+
24
+ ## 3. Limitations
25
+ **3.1. Misrepresentation.** You must not misrepresent or imply, through any means, that the Derivatives made by or for You and/or any modified version of the Perceptron Model You Distribute under your name and responsibility is an official product of Perceptron, Inc. or has been endorsed, approved or validated by Perceptron, Inc., unless You are authorized by Us to do so in writing.
26
+
27
+ **3.2. Usage Limitation**
28
+ - You shall only use the Perceptron Models and Derivatives (whether or not created by Perceptron, Inc.) for testing, research, Personal, or evaluation purposes in Non-Production Environments;
29
+ - Subject to the foregoing, You shall not supply the Perceptron Models or Derivatives in the course of a commercial activity, whether in return for payment or free of charge, in any medium or form, including but not limited to through a hosted or managed service (e.g. SaaS, cloud instances, etc.), or behind a software layer.
30
+
31
+ **3.3. Usage not permitted under this Agreement.** If You want to use a Perceptron Model or a Derivative for any purpose that is not expressly authorized under this Agreement, You must request a license from Perceptron, Inc., which Perceptron, Inc. may grant to You in Perceptron, Inc.’s sole discretion. Please contact Perceptron, Inc. at the following e-mail address if You want to discuss such a license: sales@perceptron.inc
32
+
33
+ ## 4. Intellectual Property
34
+ **4.1. Trademarks.** No trademark licenses are granted under this Agreement, and in connection with the Perceptron Models, You may not use any name or mark owned by or associated with Perceptron, Inc. or any of its affiliates, except (i) as required for reasonable and customary use in describing and Distributing the Perceptron Models and Derivatives made by or for Perceptron, Inc. and (ii) for attribution purposes as required by this Agreement.
35
+
36
+ **4.2. Outputs.** We claim no ownership rights in and to the Outputs. You are solely responsible for the Outputs You generate and their subsequent uses in accordance with this Agreement.
37
+
38
+ **4.3. Derivatives.** By entering into this Agreement, You accept that any Derivatives that You may create or that may be created for You shall be subject to the restrictions set out in Section 3 of this Agreement.
39
+
40
+ # 5. Liability
41
+ **5.1. Limitation of liability.** In no event, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall Perceptron, Inc. be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this Agreement or out of the use or inability to use the Perceptron Models and Derivatives (including but not limited to damages for loss of data, loss of goodwill, loss of expected profit or savings, work stoppage, computer failure or malfunction, or any damage caused by malware or security breaches), even if Perceptron, Inc. has been advised of the possibility of such damages.
42
+
43
+ **5.2. Indemnification.** You agree to indemnify and hold harmless Perceptron, Inc. from and against any claims, damages, or losses arising out of or related to Your use or Distribution of the Perceptron Models and Derivatives.
44
+
45
+ ## 6. Warranty
46
+ **6.1. Disclaimer.** Unless required by applicable law or agreed to in writing, Perceptron, Inc. provides the Perceptron Models and Derivatives on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. Perceptron, Inc. does not represent nor warrant that the Perceptron Models and Derivatives will be error-free, meet Your or any third party’s requirements, be secure or will allow You or any third party to achieve any kind of result or generate any kind of content. You are solely responsible for determining the appropriateness of using or Distributing the Perceptron Models and Derivatives and assume any risks associated with Your exercise of rights under this Agreement.
47
+
48
+ # 7. Termination
49
+ **7.1. Term.** This Agreement is effective as of the date of your acceptance of this Agreement or access to the concerned Perceptron Models or Derivatives and will continue until terminated in accordance with the following terms.
50
+
51
+ **7.2. Termination.** Perceptron, Inc. may terminate this Agreement at any time if You are in breach of this Agreement. Upon termination of this Agreement, You must cease to use all Perceptron Models and Derivatives and shall permanently delete any copy thereof. Sections 5, 6, 7 and 8 shall survive the termination of this Agreement.
52
+
53
+ **7.3. Litigation.** If You initiate any legal action or proceedings against Us or any other entity (including a cross-claim or counterclaim in a lawsuit), alleging that the Model or a Derivative, or any part thereof, infringe upon intellectual property or other rights owned or licensable by You, then any licenses granted to You under this Agreement will immediately terminate as of the date such legal action or claim is filed or initiated.
54
+
55
+ # 8. General provisions
56
+ 8.1. Governing Law. This Agreement will be governed by and construed in accordance with the laws of the State of Washington, without regard to its conflict of law principles.
57
+
58
+ 8.2. Jurisdiction. The state and federal courts located in King County, Washington shall have exclusive jurisdiction over any dispute arising out of or relating to this Agreement, and You and We consent to personal jurisdiction and venue in such courts.
59
+
60
+ **8.3. Severability.** If any provision of this Agreement is held to be invalid, illegal or unenforceable, the remaining provisions shall be unaffected thereby and remain valid as if such provision had not been set forth herein.
61
+
62
+ # 9. Definitions
63
+ **“Agreement”**: means this Perceptron, Inc. Non-Production License agreement governing the access, use, and Distribution of the Perceptron Models and Derivatives.
64
+
65
+ **“Derivative”**: means any (i) modified version of the Perceptron Model (including but not limited to any customized or fine-tuned version thereof), (ii) work based on the Perceptron Model, or (iii) any other derivative work thereof. For the avoidance of doubt, Outputs are not considered as Derivatives under this Agreement.
66
+
67
+ **“Distribution”**, **“Distributing”**, **“Distribute”** or **“Distributed”**: means providing or making available, by any means, a copy of the Perceptron Models and/or the Derivatives as the case may be, subject to Section 3 of this Agreement.
68
+
69
+ **“Perceptron, Inc.”**, **“We”** or **“Us”**: means Perceptron, Inc., a Delaware corporation with its principal place of business at 10900 NE 8th St Suite 613, Bellevue, WA 98004.
70
+
71
+ **“Perceptron Model”**: means the foundational large language model(s), and its elements which include algorithms, software, instructed checkpoints, parameters, source code (inference code, evaluation code and, if applicable, fine-tuning code) and any other elements associated thereto made available by Perceptron, Inc. under this Agreement, including, if any, the technical documentation, manuals and instructions for the use and operation thereof.
72
+
73
+ **“Non-Production Environment”**: means any setting, use case, or application of the Perceptron Models or Derivatives that expressly excludes live, real-world conditions, commercial operations, revenue-generating activities, or direct interactions with or impacts on end users (such as, for instance, Your employees or customers). Non-Production Environment may include, but is not limited to, any setting, use case, or application for research, development, testing, quality assurance, training, internal evaluation (other than any internal usage by employees in the context of the company’s business activities), and demonstration purposes.
74
+
75
+ **“Outputs”**: means any content generated by the operation of the Perceptron Models or the Derivatives from a prompt (i.e., text instructions) provided by users. For the avoidance of doubt, Outputs do not include any components of a Perceptron Models, such as any fine-tuned versions of the Perceptron Models, the weights, or parameters.
76
+
77
+ **“Personal”**: means any use of a Perceptron Model or a Derivative that is (i) solely for personal, non-profit and non-commercial purposes and (ii) not directly or indirectly connected to any commercial activities, business operations, or employment responsibilities. For illustration purposes, Personal use of a Model or a Derivative does not include any usage by individuals employed in companies in the context of their daily tasks, any activity that is intended to generate revenue, or that is performed on behalf of a commercial entity.
78
+
79
+ **“You”**: means the individual or entity entering into this Agreement with Perceptron, Inc..
80
+
@@ -0,0 +1,3 @@
1
+ include README.md
2
+ include LICENSE
3
+ include HISTORY.md
@@ -0,0 +1,192 @@
1
+ Metadata-Version: 2.4
2
+ Name: perceptron
3
+ Version: 0.1.0
4
+ Summary: Perceptron multimodal SDK
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Requires-Dist: requests>=2.31.0
9
+ Requires-Dist: rich>=13
10
+ Requires-Dist: typer>=0.9.0
11
+ Requires-Dist: Pillow>=9.0.0
12
+ Requires-Dist: numpy>=1.24
13
+ Requires-Dist: httpx>=0.26.0
14
+ Requires-Dist: shellingham>=1.5.0
15
+ Requires-Dist: colorama>=0.4.6
16
+ Provides-Extra: dev
17
+ Requires-Dist: pytest>=8.0; extra == "dev"
18
+ Requires-Dist: pre-commit>=3.5; extra == "dev"
19
+ Requires-Dist: ruff==0.13.0; extra == "dev"
20
+ Requires-Dist: ty==0.0.1-alpha.20; extra == "dev"
21
+ Provides-Extra: torch
22
+ Requires-Dist: torch>=2.0; extra == "torch"
23
+ Dynamic: license-file
24
+
25
+ # Perceptron SDK
26
+
27
+ Python SDK and CLI for perceptive-language models. The SDK is provider-agnostic and lets you compose visual + language tasks, run them locally for inspection, or execute them via a configured provider. Choose a provider and optional model per call; keep your application code stable across model updates.
28
+
29
+ ---
30
+
31
+ ## Installation
32
+ Perceptron currently ships as a source package (the `perceptron` project on PyPI is unrelated). Install directly from this repository.
33
+
34
+ - Prerequisites: Python 3.10+, `pip` 23+ (or [`uv`](https://github.com/astral-sh/uv))
35
+
36
+ ```bash
37
+ python -m venv .venv
38
+ source .venv/bin/activate # Windows: .venv\Scripts\activate
39
+ python -m pip install --upgrade pip setuptools wheel
40
+ python -m pip install -e .
41
+
42
+ # Optional extras
43
+ python -m pip install -e .[torch] # TensorStream helpers (requires PyTorch)
44
+ python -m pip install -e .[dev] # Dev tooling
45
+ ```
46
+
47
+ Using `uv`:
48
+ ```bash
49
+ uv pip install --editable .
50
+ uv pip install --editable .[torch]
51
+ ```
52
+
53
+ The CLI entry point `perceptron` is available after install.
54
+
55
+ ---
56
+
57
+ ## Configuration
58
+ Set credentials and defaults via environment, programmatically, or the CLI. The SDK ships with a `fal` provider; you can add others by extending `perceptron.client._PROVIDER_CONFIG`.
59
+
60
+ - `PERCEPTRON_PROVIDER`: provider identifier (default `fal`)
61
+ - `PERCEPTRON_API_KEY`: API key for the selected provider
62
+ - `PERCEPTRON_BASE_URL`: override provider base URL when needed
63
+ - `FAL_KEY`: alternative env var used when `provider=fal`
64
+
65
+ Programmatic configuration:
66
+ ```python
67
+ from perceptron import configure, config
68
+
69
+ configure(provider="fal", api_key="sk_live_...", base_url="https://api.example/v1")
70
+
71
+ with config(max_tokens=512):
72
+ ... # temporary overrides inside the context
73
+ ```
74
+
75
+ CLI helper:
76
+ ```bash
77
+ perceptron config --provider fal --api-key sk_live_...
78
+ ```
79
+
80
+ No credentials? Helpers return compile-only payloads so you can inspect tasks without sending requests.
81
+
82
+ ---
83
+
84
+ ## Python Quickstart
85
+ ```python
86
+ from perceptron import caption, detect
87
+
88
+ # Caption an image (provider default model)
89
+ result = caption("/path/to/image.png", style="concise")
90
+ print(result.text)
91
+
92
+ # Stream grounded detections; optionally select a specific model
93
+ for event in detect("local.png", classes=["person", "forklift"], model="perceptron", stream=True):
94
+ if event["type"] == "text.delta":
95
+ print("chunk", event["chunk"])
96
+ elif event["type"] == "points.delta":
97
+ print("bbox", event["points"])
98
+ elif event["type"] == "final":
99
+ print("final", event["result"]["points"])
100
+ ```
101
+
102
+ ### Few-shot detection from COCO
103
+ ```python
104
+ from perceptron import detect_from_coco
105
+
106
+ runs = detect_from_coco(
107
+ "/datasets/demo",
108
+ split="train",
109
+ shots=4, # build balanced in-context examples automatically
110
+ classes=["defect", "ok"],
111
+ )
112
+
113
+ for sample in runs:
114
+ print(sample.image_path.name)
115
+ for box in sample.result.points or []:
116
+ print(" -", box.mention, box)
117
+ ```
118
+
119
+ ---
120
+
121
+ ## CLI Usage
122
+ The CLI mirrors the high-level helpers and supports directory batching (JSON summaries written alongside input folders).
123
+
124
+ ```bash
125
+ # Generate captions
126
+ perceptron caption image.jpg
127
+ perceptron caption ./images --style detailed
128
+
129
+ # OCR with a custom prompt
130
+ perceptron ocr schematic.png --prompt "Extract component labels"
131
+
132
+ # Batched detection (writes detections.json)
133
+ perceptron detect ./frames --classes defect,warning
134
+
135
+ # Grounded question answering
136
+ perceptron question image.jpg "What stands out?" --expects box --format json
137
+ ```
138
+
139
+ Directory mode disables streaming and logs raw responses, plus per-file validation issues.
140
+
141
+ ---
142
+
143
+ ## High-Level APIs
144
+ - `caption(image, *, style="concise", stream=False, **kwargs)`
145
+ - `ocr(image, *, prompt=None, stream=False, **kwargs)`
146
+ - `detect(image, *, classes=None, examples=None, stream=False, **kwargs)`
147
+ - `detect_from_coco(dataset_dir, *, split=None, classes=None, shots=0, limit=None, **kwargs)`
148
+
149
+ Notes
150
+ - Pass `model="..."`, `provider="..."`, `max_tokens=...`, etc., through `**kwargs` on any helper.
151
+ - `detect_from_coco` discovers annotations, constructs balanced examples when `shots > 0`, and returns `CocoDetectResult` objects.
152
+ - For advanced workflows, build tasks with the typed DSL (`text`, `system`, `image`, `point`, `box`, `polygon`, `collection`) and decorate with `@perceive` / `@async_perceive`. Use the inspector attached to decorated functions to view compiled payloads without executing.
153
+
154
+ ---
155
+
156
+ ## Troubleshooting
157
+ | Symptom | Likely Cause | Resolution |
158
+ | --- | --- | --- |
159
+ | Compile-only result (no text) | Missing provider credentials | Export `FAL_KEY` / `PERCEPTRON_API_KEY` or call `configure(...)` |
160
+ | `stream_buffer_overflow` warning | Long streaming responses exceeded buffer | Increase `max_buffer_bytes` via `configure` |
161
+ | Empty JSON output in directory mode | No supported image extensions | Ensure files end with `.jpg`, `.png`, `.webp`, `.gif`, `.bmp`, `.tif`, `.tiff`, `.heic`, or `.heif` |
162
+ | Bounding-box bounds errors | Inconsistent coordinates or missing `image=` anchors | Validate input annotations and ensure images are attached |
163
+
164
+ ---
165
+
166
+ ## Development
167
+ - Install tooling: `python -m pip install -e .[dev]` (or `uv pip install --editable .[dev]`)
168
+ - Enable git hooks: `pre-commit install`
169
+ - Run all checks: `pre-commit run --all-files`
170
+
171
+ Repository layout
172
+ - `src/perceptron` – core SDK and DSL
173
+ - `examples` – runnable usage samples
174
+ - `tests` – high-level API and DSL tests
175
+
176
+ ---
177
+
178
+ ## Releases
179
+ - Publishing is automated: pushing a change to `HISTORY.md` on `main` builds and uploads to PyPI.
180
+ - Before updating `HISTORY.md`, bump the version in both `pyproject.toml` and `src/perceptron/__init__.py` (they must match).
181
+ - Configure the GitHub secret `PYPI_API_TOKEN` with your PyPI token (scoped to the project) to enable publishing.
182
+
183
+ Manual run: you can also trigger the workflow via the “Run workflow” button in GitHub Actions.
184
+
185
+ If a version was already uploaded, the workflow skips re-uploading that same version.
186
+
187
+ ---
188
+
189
+ ## Contacts & Support
190
+ - Technical: [support@perceptron.inc](mailto:support@perceptron.inc)
191
+ - Commercial: [sales@perceptron.inc](mailto:sales@perceptron.inc)
192
+ - Careers: [join-us@perceptron.inc](mailto:join-us@perceptron.inc)
@@ -0,0 +1,168 @@
1
+ # Perceptron SDK
2
+
3
+ Python SDK and CLI for perceptive-language models. The SDK is provider-agnostic and lets you compose visual + language tasks, run them locally for inspection, or execute them via a configured provider. Choose a provider and optional model per call; keep your application code stable across model updates.
4
+
5
+ ---
6
+
7
+ ## Installation
8
+ Perceptron currently ships as a source package (the `perceptron` project on PyPI is unrelated). Install directly from this repository.
9
+
10
+ - Prerequisites: Python 3.10+, `pip` 23+ (or [`uv`](https://github.com/astral-sh/uv))
11
+
12
+ ```bash
13
+ python -m venv .venv
14
+ source .venv/bin/activate # Windows: .venv\Scripts\activate
15
+ python -m pip install --upgrade pip setuptools wheel
16
+ python -m pip install -e .
17
+
18
+ # Optional extras
19
+ python -m pip install -e .[torch] # TensorStream helpers (requires PyTorch)
20
+ python -m pip install -e .[dev] # Dev tooling
21
+ ```
22
+
23
+ Using `uv`:
24
+ ```bash
25
+ uv pip install --editable .
26
+ uv pip install --editable .[torch]
27
+ ```
28
+
29
+ The CLI entry point `perceptron` is available after install.
30
+
31
+ ---
32
+
33
+ ## Configuration
34
+ Set credentials and defaults via environment, programmatically, or the CLI. The SDK ships with a `fal` provider; you can add others by extending `perceptron.client._PROVIDER_CONFIG`.
35
+
36
+ - `PERCEPTRON_PROVIDER`: provider identifier (default `fal`)
37
+ - `PERCEPTRON_API_KEY`: API key for the selected provider
38
+ - `PERCEPTRON_BASE_URL`: override provider base URL when needed
39
+ - `FAL_KEY`: alternative env var used when `provider=fal`
40
+
41
+ Programmatic configuration:
42
+ ```python
43
+ from perceptron import configure, config
44
+
45
+ configure(provider="fal", api_key="sk_live_...", base_url="https://api.example/v1")
46
+
47
+ with config(max_tokens=512):
48
+ ... # temporary overrides inside the context
49
+ ```
50
+
51
+ CLI helper:
52
+ ```bash
53
+ perceptron config --provider fal --api-key sk_live_...
54
+ ```
55
+
56
+ No credentials? Helpers return compile-only payloads so you can inspect tasks without sending requests.
57
+
58
+ ---
59
+
60
+ ## Python Quickstart
61
+ ```python
62
+ from perceptron import caption, detect
63
+
64
+ # Caption an image (provider default model)
65
+ result = caption("/path/to/image.png", style="concise")
66
+ print(result.text)
67
+
68
+ # Stream grounded detections; optionally select a specific model
69
+ for event in detect("local.png", classes=["person", "forklift"], model="perceptron", stream=True):
70
+ if event["type"] == "text.delta":
71
+ print("chunk", event["chunk"])
72
+ elif event["type"] == "points.delta":
73
+ print("bbox", event["points"])
74
+ elif event["type"] == "final":
75
+ print("final", event["result"]["points"])
76
+ ```
77
+
78
+ ### Few-shot detection from COCO
79
+ ```python
80
+ from perceptron import detect_from_coco
81
+
82
+ runs = detect_from_coco(
83
+ "/datasets/demo",
84
+ split="train",
85
+ shots=4, # build balanced in-context examples automatically
86
+ classes=["defect", "ok"],
87
+ )
88
+
89
+ for sample in runs:
90
+ print(sample.image_path.name)
91
+ for box in sample.result.points or []:
92
+ print(" -", box.mention, box)
93
+ ```
94
+
95
+ ---
96
+
97
+ ## CLI Usage
98
+ The CLI mirrors the high-level helpers and supports directory batching (JSON summaries written alongside input folders).
99
+
100
+ ```bash
101
+ # Generate captions
102
+ perceptron caption image.jpg
103
+ perceptron caption ./images --style detailed
104
+
105
+ # OCR with a custom prompt
106
+ perceptron ocr schematic.png --prompt "Extract component labels"
107
+
108
+ # Batched detection (writes detections.json)
109
+ perceptron detect ./frames --classes defect,warning
110
+
111
+ # Grounded question answering
112
+ perceptron question image.jpg "What stands out?" --expects box --format json
113
+ ```
114
+
115
+ Directory mode disables streaming and logs raw responses, plus per-file validation issues.
116
+
117
+ ---
118
+
119
+ ## High-Level APIs
120
+ - `caption(image, *, style="concise", stream=False, **kwargs)`
121
+ - `ocr(image, *, prompt=None, stream=False, **kwargs)`
122
+ - `detect(image, *, classes=None, examples=None, stream=False, **kwargs)`
123
+ - `detect_from_coco(dataset_dir, *, split=None, classes=None, shots=0, limit=None, **kwargs)`
124
+
125
+ Notes
126
+ - Pass `model="..."`, `provider="..."`, `max_tokens=...`, etc., through `**kwargs` on any helper.
127
+ - `detect_from_coco` discovers annotations, constructs balanced examples when `shots > 0`, and returns `CocoDetectResult` objects.
128
+ - For advanced workflows, build tasks with the typed DSL (`text`, `system`, `image`, `point`, `box`, `polygon`, `collection`) and decorate with `@perceive` / `@async_perceive`. Use the inspector attached to decorated functions to view compiled payloads without executing.
129
+
130
+ ---
131
+
132
+ ## Troubleshooting
133
+ | Symptom | Likely Cause | Resolution |
134
+ | --- | --- | --- |
135
+ | Compile-only result (no text) | Missing provider credentials | Export `FAL_KEY` / `PERCEPTRON_API_KEY` or call `configure(...)` |
136
+ | `stream_buffer_overflow` warning | Long streaming responses exceeded buffer | Increase `max_buffer_bytes` via `configure` |
137
+ | Empty JSON output in directory mode | No supported image extensions | Ensure files end with `.jpg`, `.png`, `.webp`, `.gif`, `.bmp`, `.tif`, `.tiff`, `.heic`, or `.heif` |
138
+ | Bounding-box bounds errors | Inconsistent coordinates or missing `image=` anchors | Validate input annotations and ensure images are attached |
139
+
140
+ ---
141
+
142
+ ## Development
143
+ - Install tooling: `python -m pip install -e .[dev]` (or `uv pip install --editable .[dev]`)
144
+ - Enable git hooks: `pre-commit install`
145
+ - Run all checks: `pre-commit run --all-files`
146
+
147
+ Repository layout
148
+ - `src/perceptron` – core SDK and DSL
149
+ - `examples` – runnable usage samples
150
+ - `tests` – high-level API and DSL tests
151
+
152
+ ---
153
+
154
+ ## Releases
155
+ - Publishing is automated: pushing a change to `HISTORY.md` on `main` builds and uploads to PyPI.
156
+ - Before updating `HISTORY.md`, bump the version in both `pyproject.toml` and `src/perceptron/__init__.py` (they must match).
157
+ - Configure the GitHub secret `PYPI_API_TOKEN` with your PyPI token (scoped to the project) to enable publishing.
158
+
159
+ Manual run: you can also trigger the workflow via the “Run workflow” button in GitHub Actions.
160
+
161
+ If a version was already uploaded, the workflow skips re-uploading that same version.
162
+
163
+ ---
164
+
165
+ ## Contacts & Support
166
+ - Technical: [support@perceptron.inc](mailto:support@perceptron.inc)
167
+ - Commercial: [sales@perceptron.inc](mailto:sales@perceptron.inc)
168
+ - Careers: [join-us@perceptron.inc](mailto:join-us@perceptron.inc)
@@ -0,0 +1,41 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "perceptron"
7
+ version = "0.1.0"
8
+ description = "Perceptron multimodal SDK"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ dependencies = [
12
+ "requests>=2.31.0",
13
+ "rich>=13",
14
+ "typer>=0.9.0",
15
+ "Pillow>=9.0.0",
16
+ "numpy>=1.24",
17
+ "httpx>=0.26.0",
18
+ "shellingham>=1.5.0",
19
+ "colorama>=0.4.6",
20
+ ]
21
+
22
+ [project.scripts]
23
+ perceptron = "perceptron.cli:app"
24
+
25
+ [project.optional-dependencies]
26
+ dev = [
27
+ "pytest>=8.0",
28
+ "pre-commit>=3.5",
29
+ "ruff==0.13.0",
30
+ "ty==0.0.1-alpha.20",
31
+ ]
32
+ torch = [
33
+ "torch>=2.0",
34
+ ]
35
+
36
+ [tool.setuptools.package-dir]
37
+ "" = "src"
38
+
39
+ [tool.setuptools.packages.find]
40
+ where = ["src"]
41
+ include = ["perceptron*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,108 @@
1
+ """
2
+ perceptron – Python SDK (v0.1 scaffolding)
3
+
4
+ Public surface (subject to refinement):
5
+ - DSL: perceive (decorator), text, system, agent, image, point, box, polygon, block
6
+ - Pointing: PointParser, parse_text, extract_points, strip_tags
7
+ - Data constructors for annotations/examples: pt, bbox, poly
8
+ - Config: configure, config (context manager), settings
9
+
10
+ This initial scaffold focuses on the compile/runtime pieces that do not require
11
+ network access. Transport and streaming are added in later phases.
12
+ """
13
+
14
+ __version__ = "0.1.0"
15
+
16
+ from .config import configure, config, settings
17
+ from .client import Client, AsyncClient
18
+ from .errors import (
19
+ SDKError,
20
+ TransportError,
21
+ TimeoutError,
22
+ AuthError,
23
+ RateLimitError,
24
+ ServerError,
25
+ BadRequestError,
26
+ ExpectationError,
27
+ AnchorError,
28
+ )
29
+ from .pointing.types import (
30
+ SinglePoint,
31
+ BoundingBox,
32
+ Polygon,
33
+ Collection,
34
+ pt,
35
+ bbox,
36
+ poly,
37
+ collection,
38
+ )
39
+ from .pointing.parser import (
40
+ PointParser,
41
+ ReasoningExtraction,
42
+ ReasoningStreamCleaner,
43
+ extract_points,
44
+ extract_reasoning,
45
+ parse_text,
46
+ strip_tags,
47
+ )
48
+ from .dsl.nodes import text, system, agent, image, point, box, polygon, block
49
+ from .dsl.perceive import perceive, async_perceive, inspect_task, PerceiveResult
50
+ from .annotations import annotate_image
51
+ from .highlevel import caption, ocr, detect, detect_from_coco, question
52
+
53
+ __all__ = [
54
+ # Config
55
+ "configure",
56
+ "config",
57
+ "settings",
58
+ "Client",
59
+ "AsyncClient",
60
+ # Errors
61
+ "SDKError",
62
+ "TransportError",
63
+ "TimeoutError",
64
+ "AuthError",
65
+ "RateLimitError",
66
+ "ServerError",
67
+ "BadRequestError",
68
+ "ExpectationError",
69
+ "AnchorError",
70
+ # Pointing types & constructors
71
+ "SinglePoint",
72
+ "BoundingBox",
73
+ "Polygon",
74
+ "Collection",
75
+ "pt",
76
+ "bbox",
77
+ "poly",
78
+ "collection",
79
+ # Parser & helpers
80
+ "PointParser",
81
+ "ReasoningExtraction",
82
+ "ReasoningStreamCleaner",
83
+ "parse_text",
84
+ "extract_points",
85
+ "extract_reasoning",
86
+ "strip_tags",
87
+ # DSL nodes & decorator
88
+ "text",
89
+ "system",
90
+ "agent",
91
+ "image",
92
+ "point",
93
+ "box",
94
+ "polygon",
95
+ "block",
96
+ "perceive",
97
+ "async_perceive",
98
+ "inspect_task",
99
+ "PerceiveResult",
100
+ # High-level helpers
101
+ "annotate_image",
102
+ "caption",
103
+ "ocr",
104
+ "detect",
105
+ "question",
106
+ "detect_from_coco",
107
+ "__version__",
108
+ ]