@eyepop.ai/eyepop 0.14.1 → 0.15.0

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.
package/README.md CHANGED
@@ -2,9 +2,14 @@
2
2
  The EyePop.ai Node SDK provides convenient access to the EyePop.ai's inference API from applications written in the
3
3
  TypeScript or JavaScript language.
4
4
  ## Installation
5
+ ### Node
5
6
  ```shell
6
7
  npm install --save @eyepop.ai/eyepop
7
8
  ```
9
+ ### Browser
10
+ ```html
11
+ <script src="https://cdn.jsdelivr.net/npm/@eyepop.ai/eyepop/dist/eyepop.min.js"></script>
12
+ ```
8
13
  ## Configuration
9
14
  The EyePop SDK needs to be configured with the __Pop Id__ and your __Authentication Credentials__. Credentials can
10
15
  be provided as:
@@ -20,9 +25,9 @@ to your .env file so that your API Key is not stored in source control. By defau
20
25
  ### Authentication with Api Key
21
26
  Configuration and authorization with explicit defaults:
22
27
  ```typescript
23
- import { EyePopSdk } from '@eyepop.ai/eyepop'
28
+ import { EyePop } from '@eyepop.ai/eyepop'
24
29
  (async() => {
25
- const endpoint = EyePopSdk.endpoint({
30
+ const endpoint = EyePop.endpoint({
26
31
  // This is the default and can be omitted
27
32
  popId: process.env['EYEPOP_POP_ID'],
28
33
  // This is the default and can be omitted
@@ -35,9 +40,9 @@ import { EyePopSdk } from '@eyepop.ai/eyepop'
35
40
  ```
36
41
  Equivalent, but shorter:
37
42
  ```typescript
38
- import { EyePopSdk } from '@eyepop.ai/eyepop'
43
+ import { EyePop } from '@eyepop.ai/eyepop'
39
44
  (async() => {
40
- const endpoint = await EyePopSdk.endpoint().connect()
45
+ const endpoint = await EyePop.endpoint().connect()
41
46
  // do work ....
42
47
  await endpoint.disconnect()
43
48
  })
@@ -45,9 +50,9 @@ import { EyePopSdk } from '@eyepop.ai/eyepop'
45
50
  ### Authentication with session generated from Api Key
46
51
  #### Server Side
47
52
  ```javascript
48
- import { EyePopSdk } from '@eyepop.ai/eyepop'
53
+ import { EyePop } from '@eyepop.ai/eyepop'
49
54
  const getSession = async function (req, res) {
50
- const endpoint = await EyePopSdk.endpoint().connect();
55
+ const endpoint = await EyePop.endpoint().connect();
51
56
  res.setHeader("Content-Type", "application/json");
52
57
  res.writeHead(200);
53
58
  res.end(JSON.stringify(await endpoint.session()));
@@ -57,13 +62,13 @@ server.listen(8080, '127.0.0.1');
57
62
  ```
58
63
  #### Client Side
59
64
  ```javascript
60
- import { EyePopSdk } from '@eyepop.ai/eyepop'
65
+ import { EyePop } from '@eyepop.ai/eyepop'
61
66
  (async() => {
62
67
  const session = await (await fetch("http://127.0.0.1:8080")).json();
63
- const endpoint = await EyePopSdk.endpoint({ auth: { session: session } }).connect();
68
+ const endpoint = await EyePop.endpoint({ auth: { session: session } }).connect();
64
69
  // do work ....
65
70
  await endpoint.disconnect();
66
- });
71
+ })();
67
72
  ```
68
73
  ### Authentication with Current Browser Session
69
74
  ```html
@@ -76,7 +81,7 @@ import { EyePopSdk } from '@eyepop.ai/eyepop'
76
81
  <body>
77
82
  <script>
78
83
  document.addEventListener("DOMContentLoaded", async (event) => {
79
- let endpoint = await EyePopSdk.endpoint({ auth: { oAuth2: true }, popId: '< Pop Id>' }).connect();
84
+ let endpoint = await EyePop.endpoint({ auth: { oAuth2: true }, popId: '< Pop Id>' }).connect();
80
85
  // do work ....
81
86
  await endpoint.disconnect();
82
87
  });
@@ -86,7 +91,7 @@ import { EyePopSdk } from '@eyepop.ai/eyepop'
86
91
  To use an alternative environment, e.g. STAGING vs PRODUCTION, pass in the adjusted Auth0 configuration:
87
92
  ```javascript
88
93
  // ...
89
- let endpoint = await EyePopSdk.endpoint({
94
+ let endpoint = await EyePop.endpoint({
90
95
  auth: { oAuth2: {
91
96
  audience: "https://dev-app.eyepop.ai",
92
97
  domain: "dev-eyepop.us.auth0.com",
@@ -97,12 +102,12 @@ let endpoint = await EyePopSdk.endpoint({
97
102
  ## Usage Examples
98
103
  ### Uploading and processing one single image
99
104
  ```typescript
100
- import { EyePopSdk } from '@eyepop.ai/eyepop'
105
+ import { EyePop } from '@eyepop.ai/eyepop'
101
106
 
102
107
  const example_image_path = 'examples/example.jpg';
103
108
 
104
109
  (async() => {
105
- const endpoint = await EyePopSdk.endpoint().connect()
110
+ const endpoint = await EyePop.endpoint().connect()
106
111
  try {
107
112
  let results = await endpoint.process({path: example_image_path})
108
113
  for await (let result of results) {
@@ -111,9 +116,9 @@ const example_image_path = 'examples/example.jpg';
111
116
  } finally {
112
117
  await endpoint.disconnect()
113
118
  }
114
- })
119
+ })();
115
120
  ```
116
- 1. `EyePopSdk.endpoint()` returns a local endpoint object, that will authenticate with the Api Key found in
121
+ 1. `EyePop.endpoint()` returns a local endpoint object, that will authenticate with the Api Key found in
117
122
  EYEPOP_SECRET_KEY and load the worker configuration for the Pop identified by EYEPOP_POP_ID.
118
123
  2. Call `endpoint.connect()` before any job is submitted and `endpoint.disconnect()` to release all resources.
119
124
  3. `endpoint.process({path:'examples/example.jpg'})` initiates the upload to the local file to the worker service.
@@ -132,54 +137,19 @@ until the entire file has been processed.
132
137
  // ...
133
138
  ```
134
139
  ### Visualizing Results
135
- The EyePop SDK includes helper classes to visualize the predictions for images using `canvas.CanvasRenderingContext2D`.
136
- ```typescript
137
- import {createCanvas, loadImage} from "canvas"
138
- import {open} from 'openurl'
139
- import { mkdtempSync, writeFileSync } from 'node:fs'
140
- import { join } from 'node:path'
141
- import { tmpdir } from 'node:os'
142
- import { EyePopSdk } from '@eyepop.ai/eyepop'
143
-
144
- const example_image_path = 'examples/example.jpg';
145
-
146
- (async() => {
147
- const image = await loadImage(example_image_path)
148
- const canvas = createCanvas(image.width, image.height)
149
- const context = canvas.getContext("2d")
150
- context.drawImage(image, 0, 0)
151
-
152
- const endpoint = await EyePopSdk.endpoint().connect()
153
- try {
154
- let results = await endpoint.process({path: example_image_path})
155
- for await (let result of results) {
156
- EyePopSdk.plot(context).prediction(result)
157
- }
158
- } finally {
159
- await endpoint.disconnect()
160
- }
161
-
162
- const tmp_dir = mkdtempSync(join(tmpdir(), 'ep-demo-'))
163
- const temp_file = join(tmp_dir, 'out.png')
164
- console.log(`creating temp file: ${temp_file}`)
165
-
166
- const buffer = canvas.toBuffer('image/png')
167
- writeFileSync(temp_file, buffer)
168
-
169
- open(`file://${temp_file}`)
170
- })
171
- ```
140
+ Visualization components are provided as separate modules. Please refer to the module's documentation for usage examples.
141
+ * [EyePop Render 2d](../eyepop-render-2d/README.md)
172
142
  ### Asynchronous uploading and processing of images
173
143
  The above _synchronous_ way, process() then iterate all results, is great for individual images or reasonable
174
144
  sized batches. For larger batch sizes, or continuous stream of images, don't `await` the results but instead
175
145
  use `then()` on the returned promise.
176
146
  ```typescript
177
- import { EyePopSdk } from '@eyepop.ai/eyepop'
147
+ import { EyePop } from '@eyepop.ai/eyepop';
178
148
 
179
149
  const example_image_path = 'examples/example.jpg';
180
150
 
181
151
  (async() => {
182
- const endpoint = await EyePopSdk.endpoint().connect()
152
+ const endpoint = await EyePop.endpoint().connect()
183
153
  try {
184
154
  for (let i = 0; i < 100; i++) {
185
155
  endpoint.process({path: example_image_path}).then(async (results) => {
@@ -191,7 +161,7 @@ const example_image_path = 'examples/example.jpg';
191
161
  } finally {
192
162
  await endpoint.disconnect()
193
163
  }
194
- })
164
+ })();
195
165
  ```
196
166
  This will result in a most efficient processing, i.e. uploads will be processed in parallel (up to five HTTP
197
167
  connections per endpoint) and results will be processed by your code as soon as they are available.
@@ -201,12 +171,12 @@ Alternatively to uploading files, you can also submit a publicly accessible URL
201
171
  * RTSP (live-streaming)
202
172
  * RTMP (live-streaming)
203
173
  ```typescript
204
- import { EyePopSdk } from '@eyepop.ai/eyepop'
174
+ import { EyePop } from '@eyepop.ai/eyepop';
205
175
 
206
176
  const example_image_url = 'https://farm2.staticflickr.com/1080/1301049949_532835a8b5_z.jpg';
207
177
 
208
178
  (async() => {
209
- const endpoint = await EyePopSdk.endpoint().connect()
179
+ const endpoint = await EyePop.endpoint().connect()
210
180
  try {
211
181
  let results = await endpoint.process({url: example_image_url})
212
182
  for await (let result of results) {
@@ -215,19 +185,19 @@ const example_image_url = 'https://farm2.staticflickr.com/1080/1301049949_532835
215
185
  } finally {
216
186
  await endpoint.disconnect()
217
187
  }
218
- })
188
+ })();
219
189
  ```
220
190
  ### Processing Videos
221
191
  You can process videos via upload or public URLs. This example shows how to process all video frames of a file
222
192
  retrieved from a public URL.
223
193
 
224
194
  ```typescript
225
- import { EyePopSdk } from '@eyepop.ai/eyepop'
195
+ import { EyePop } from '@eyepop.ai/eyepop'
226
196
 
227
197
  const example_video_url = 'https://demo-eyepop-videos.s3.amazonaws.com/test1_vlog.mp4';
228
198
 
229
199
  (async() => {
230
- const endpoint = await EyePopSdk.endpoint().connect()
200
+ const endpoint = await EyePop.endpoint().connect()
231
201
  try {
232
202
  let results = await endpoint.process({url: example_image_url})
233
203
  for await (let result of results) {
@@ -236,18 +206,18 @@ const example_video_url = 'https://demo-eyepop-videos.s3.amazonaws.com/test1_vlo
236
206
  } finally {
237
207
  await endpoint.disconnect()
238
208
  }
239
- })
209
+ })();
240
210
  ```
241
211
  ### Canceling Jobs
242
212
  Any job that has been queued or is in-progress can be cancelled. E.g. stop the video processing after
243
213
  predictions have been processed for 10 seconds duration of the video.
244
214
  ```typescript
245
- import { EyePopSdk } from '@eyepop.ai/eyepop'
215
+ import { EyePop } from '@eyepop.ai/eyepop'
246
216
 
247
217
  const example_video_url = 'https://demo-eyepop-videos.s3.amazonaws.com/test1_vlog.mp4';
248
218
 
249
219
  (async() => {
250
- const endpoint = EyePopSdk.endpoint().connect()
220
+ const endpoint = EyePop.endpoint().connect()
251
221
  try {
252
222
  let results = await endpoint.process({url: example_image_url})
253
223
  for await (let result of results) {
@@ -259,16 +229,17 @@ const example_video_url = 'https://demo-eyepop-videos.s3.amazonaws.com/test1_vlo
259
229
  } finally {
260
230
  await endpoint.disconnect()
261
231
  }
262
- })
232
+ })();
263
233
  ```
264
234
  ## Other Usage Options
265
235
  #### Auto start workers
266
- By default, `EyePopSdk.endpoint().connect()` will start a worker if none is running yet. To disable this behavior
267
- create an endpoint with `EyePopSdk.endpoint({autoStart: false})`.
236
+ By default, `EyePop.endpoint().connect()` will start a worker if none is running yet. To disable this behavior
237
+ create an endpoint with `EyePop.endpoint({autoStart: false})`.
268
238
  #### Stop pending jobs
269
- By default, `EyePopSdk.endpoint().connect()` will cancel all currently running or queued jobs on the worker.
239
+ By default, `EyePop.endpoint().connect()` will cancel all currently running or queued jobs on the worker.
270
240
  It is assumed that the caller _takes full control_ of that worker. To disable this behavior create an endpoint with
271
- `EyePopSdk.endpoint({stopJobs: false})`.
241
+ `EyePop.endpoint({stopJobs: false})`.
242
+
272
243
 
273
244
 
274
245
 
@@ -1,5 +1,4 @@
1
1
  import { Logger } from 'pino';
2
- import { CanvasRenderingContext2D } from 'canvas';
3
2
 
4
3
  interface Session {
5
4
  readonly eyepopUrl: string;
@@ -62,6 +61,7 @@ interface PredictedClass {
62
61
  id: number;
63
62
  confidence: number;
64
63
  classLabel: string;
64
+ category: string;
65
65
  }
66
66
  interface PredictedObject extends PredictedClass {
67
67
  traceId: number | undefined;
@@ -82,6 +82,7 @@ interface Point2d {
82
82
  y: number;
83
83
  }
84
84
  interface PredictedMesh {
85
+ category: string;
85
86
  id: number;
86
87
  confidence: number;
87
88
  points: Array<Point3d>;
@@ -90,6 +91,7 @@ interface Point3d extends Point2d {
90
91
  z: number | undefined;
91
92
  }
92
93
  interface PredictedKeyPoints {
94
+ category: string;
93
95
  type: string;
94
96
  points: Array<PredictedKeyPoint>;
95
97
  }
@@ -186,30 +188,8 @@ declare class Endpoint {
186
188
  private currentAccessToken;
187
189
  }
188
190
 
189
- declare class EyePopPlot {
190
- private _context;
191
- private _font;
192
- constructor(context: CanvasRenderingContext2D);
193
- static colors: {
194
- primary_color: string;
195
- secondary_color: string;
196
- right_color: string;
197
- left_color: string;
198
- opacity_color: string;
199
- white: string;
200
- black: string;
201
- blank_color: string;
202
- };
203
- prediction(p: Prediction): void;
204
- object(obj: PredictedObject, x_scale?: number, y_scale?: number): void;
205
- static toTitleCase(str: string): string;
191
+ declare namespace EyePop {
192
+ function endpoint(opts?: Options): Endpoint;
206
193
  }
207
194
 
208
- declare class EyePopSdk {
209
- private static readonly envSecretKey;
210
- static defaultAuth: SecretKeyAuth | undefined;
211
- static endpoint(opts?: Options): Endpoint;
212
- static plot(context: CanvasRenderingContext2D): EyePopPlot;
213
- }
214
-
215
- export { EndpointState, EyePopSdk, type FileSource, type IngressEvent, type LiveMedia, type LiveSource, type PathSource, type Point2d, type Point3d, type PredictedClass, type PredictedKeyPoint, type PredictedKeyPoints, type PredictedMesh, type PredictedObject, type Prediction, type ResultStream, type Session, type Source, type StreamSource, type UrlSource, EyePopSdk as default };
195
+ export { EndpointState, EyePop, type FileSource, type IngressEvent, type LiveMedia, type LiveSource, type PathSource, type Point2d, type Point3d, type PredictedClass, type PredictedKeyPoint, type PredictedKeyPoints, type PredictedMesh, type PredictedObject, type Prediction, type ResultStream, type Session, type Source, type StreamSource, type UrlSource, EyePop as default };
@@ -1,5 +1,4 @@
1
1
  import { Logger } from 'pino';
2
- import { CanvasRenderingContext2D } from 'canvas';
3
2
 
4
3
  interface Session {
5
4
  readonly eyepopUrl: string;
@@ -62,6 +61,7 @@ interface PredictedClass {
62
61
  id: number;
63
62
  confidence: number;
64
63
  classLabel: string;
64
+ category: string;
65
65
  }
66
66
  interface PredictedObject extends PredictedClass {
67
67
  traceId: number | undefined;
@@ -82,6 +82,7 @@ interface Point2d {
82
82
  y: number;
83
83
  }
84
84
  interface PredictedMesh {
85
+ category: string;
85
86
  id: number;
86
87
  confidence: number;
87
88
  points: Array<Point3d>;
@@ -90,6 +91,7 @@ interface Point3d extends Point2d {
90
91
  z: number | undefined;
91
92
  }
92
93
  interface PredictedKeyPoints {
94
+ category: string;
93
95
  type: string;
94
96
  points: Array<PredictedKeyPoint>;
95
97
  }
@@ -186,30 +188,8 @@ declare class Endpoint {
186
188
  private currentAccessToken;
187
189
  }
188
190
 
189
- declare class EyePopPlot {
190
- private _context;
191
- private _font;
192
- constructor(context: CanvasRenderingContext2D);
193
- static colors: {
194
- primary_color: string;
195
- secondary_color: string;
196
- right_color: string;
197
- left_color: string;
198
- opacity_color: string;
199
- white: string;
200
- black: string;
201
- blank_color: string;
202
- };
203
- prediction(p: Prediction): void;
204
- object(obj: PredictedObject, x_scale?: number, y_scale?: number): void;
205
- static toTitleCase(str: string): string;
191
+ declare namespace EyePop {
192
+ function endpoint(opts?: Options): Endpoint;
206
193
  }
207
194
 
208
- declare class EyePopSdk {
209
- private static readonly envSecretKey;
210
- static defaultAuth: SecretKeyAuth | undefined;
211
- static endpoint(opts?: Options): Endpoint;
212
- static plot(context: CanvasRenderingContext2D): EyePopPlot;
213
- }
214
-
215
- export { EndpointState, EyePopSdk, type FileSource, type IngressEvent, type LiveMedia, type LiveSource, type PathSource, type Point2d, type Point3d, type PredictedClass, type PredictedKeyPoint, type PredictedKeyPoints, type PredictedMesh, type PredictedObject, type Prediction, type ResultStream, type Session, type Source, type StreamSource, type UrlSource, EyePopSdk as default };
195
+ export { EndpointState, EyePop, type FileSource, type IngressEvent, type LiveMedia, type LiveSource, type PathSource, type Point2d, type Point3d, type PredictedClass, type PredictedKeyPoint, type PredictedKeyPoints, type PredictedMesh, type PredictedObject, type Prediction, type ResultStream, type Session, type Source, type StreamSource, type UrlSource, EyePop as default };