@eyepop.ai/eyepop 0.11.0 → 0.13.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
@@ -3,7 +3,7 @@ The EyePop.ai Node SDK provides convenient access to the EyePop.ai's inference A
3
3
  TypeScript or JavaScript language.
4
4
  ## Installation
5
5
  ```shell
6
- npm install --save eyepop
6
+ npm install --save @eyepop.ai/eyepop
7
7
  ```
8
8
  ## Configuration
9
9
  The EyePop SDK needs to be configured with the __Pop Id__ and your __Authentication Credentials__. Credentials can
@@ -11,7 +11,29 @@ be provided as:
11
11
  1. __Api Key__, server side only because this key must be kept secret
12
12
  2. __Session generated from Api Key__, server side generated session transported to client over trusted channel
13
13
  3. __Current Browser Session__, for developer running client code in the same browser session loghed into their EyePop Dashboard.
14
+ ### Configuration via Environment (Server Side)
15
+ While you can provide a secret_key keyword argument, we recommend using dotenv to add EYEPOP_SECRET_KEY="My API Key"
16
+ to your .env file so that your API Key is not stored in source control. By default, the SDK will read the following environment variables:
17
+ * `EYEPOP_POP_ID`: The Pop Id to use as an endpoint. You can copy and paste this string from your EyePop Dashboard in the Pop -> Settings section.
18
+ * `EYEPOP_SECRET_KEY`: Your Secret Api Key. You can create Api Keys in the profile section of your EyePop dashboard.
19
+ * `EYEPOP_URL`: (Optional) URL of the EyePop API service, if you want to use any other endpoint than production `http://api.eyepop.ai`
14
20
  ### Authentication with Api Key
21
+ Configuration and authorization with explicit defaults:
22
+ ```typescript
23
+ import { EyePopSdk } from '@eyepop.ai/eyepop'
24
+ (async() => {
25
+ const endpoint = EyePopSdk.endpoint({
26
+ // This is the default and can be omitted
27
+ popId: process.env['EYEPOP_POP_ID'],
28
+ // This is the default and can be omitted
29
+ auth : {secretKey: process.env['EYEPOP_SECRET_KEY']},
30
+ })
31
+ await endpoint.connect()
32
+ // do work ....
33
+ await endpoint.disconnect()
34
+ })
35
+ ```
36
+ Equivalent, but shorter:
15
37
  ```typescript
16
38
  import { EyePopSdk } from '@eyepop.ai/eyepop'
17
39
  (async() => {
@@ -38,7 +60,7 @@ server.listen(8080, '127.0.0.1');
38
60
  import { EyePopSdk } from '@eyepop.ai/eyepop'
39
61
  (async() => {
40
62
  const session = await (await fetch("http://127.0.0.1:8080")).json();
41
- const endpoint = await EyePopSdk.endpoint({ session: session }).connect();
63
+ const endpoint = await EyePopSdk.endpoint({ auth: { session: session } }).connect();
42
64
  // do work ....
43
65
  await endpoint.disconnect();
44
66
  });
@@ -54,19 +76,24 @@ import { EyePopSdk } from '@eyepop.ai/eyepop'
54
76
  <body>
55
77
  <script>
56
78
  document.addEventListener("DOMContentLoaded", async (event) => {
57
- let endpoint = await EyePopSdk.endpoint({ auth: { oAuth: true }, popId: '< Pop Id>' }).connect();
79
+ let endpoint = await EyePopSdk.endpoint({ auth: { oAuth2: true }, popId: '< Pop Id>' }).connect();
58
80
  // do work ....
59
81
  await endpoint.disconnect();
60
82
  });
61
83
  </script>
62
84
  </body>
63
85
  ```
64
- ### Configuration via Environment (Server Side)
65
- While you can provide a secret_key keyword argument, we recommend using dotenv to add EYEPOP_SECRET_KEY="My API Key"
66
- to your .env file so that your API Key is not stored in source control. By default, the SDK will read the following environment variables:
67
- * `EYEPOP_POP_ID`: The Pop Id to use as an endpoint. You can copy and paste this string from your EyePop Dashboard in the Pop -> Settings section.
68
- * `EYEPOP_SECRET_KEY`: Your Secret Api Key. You can create Api Keys in the profile section of your EyePop dashboard.
69
- * `EYEPOP_URL`: (Optional) URL of the EyePop API service, if you want to use any other endpoint than production `http://api.eyepop.ai`
86
+ To use an alternative environment, e.g. STAGING vs PRODUCTION, pass in the adjusted Auth0 configuration:
87
+ ```javascript
88
+ // ...
89
+ let endpoint = await EyePopSdk.endpoint({
90
+ auth: { oAuth2: {
91
+ audience: "https://dev-app.eyepop.ai",
92
+ domain: "dev-eyepop.us.auth0.com",
93
+ clientId: "jktx3YO2UnbkNPvr05PQWf26t1kNTJyg"
94
+ } }, popId: '< Pop Id>' }).connect();
95
+ // ...
96
+ ```
70
97
  ## Usage Examples
71
98
  ### Uploading and processing one single image
72
99
  ```typescript
@@ -77,7 +104,7 @@ const example_image_path = 'examples/example.jpg';
77
104
  (async() => {
78
105
  const endpoint = await EyePopSdk.endpoint().connect()
79
106
  try {
80
- let results = await endpoint.upload({filePath: example_image_path})
107
+ let results = await endpoint.process({path: example_image_path})
81
108
  for await (let result of results) {
82
109
  console.log(result)
83
110
  }
@@ -89,15 +116,15 @@ const example_image_path = 'examples/example.jpg';
89
116
  1. `EyePopSdk.endpoint()` returns a local endpoint object, that will authenticate with the Api Key found in
90
117
  EYEPOP_SECRET_KEY and load the worker configuration for the Pop identified by EYEPOP_POP_ID.
91
118
  2. Call `endpoint.connect()` before any job is submitted and `endpoint.disconnect()` to release all resources.
92
- 3. `endpoint.upload({filePath:'examples/example.jpg'})` initiates the upload to the local file to the worker service.
119
+ 3. `endpoint.process({path:'examples/example.jpg'})` initiates the upload to the local file to the worker service.
93
120
  The image will be queued and processed immediately when the worker becomes available.
94
- The result of endpoint.upload() implements `AsyncIterable<Prediction>` which can be iterated fir 'for await' as
121
+ The result of endpoint.upload() implements `AsyncIterable<Prediction>` which can be iterated with 'for await' as
95
122
  shown in the example above. Predictions will become available when the submitted file becomes processed by the worker
96
123
  and results are efficiently streamed back to the calling client. If the uploaded file is a video
97
124
  e.g. 'video/mp4' or image container format e.g. 'image/gif', the client will receive one prediction per image frame
98
125
  until the entire file has been processed.
99
126
 
100
- 4. Alternatively to `filePath` upload() also accepts a readable stream with a mandatory mime-type:
127
+ 4. Alternatively to `path` process() also accepts a readable stream with a mandatory mime-type:
101
128
  ```typescript
102
129
  // ...
103
130
  let stream = fs.createReadStream(example_image_path)
@@ -121,13 +148,12 @@ const example_image_path = 'examples/example.jpg';
121
148
  const canvas = createCanvas(image.width, image.height)
122
149
  const context = canvas.getContext("2d")
123
150
  context.drawImage(image, 0, 0)
124
- const plot = EyePopSdk.plot(context)
125
151
 
126
152
  const endpoint = await EyePopSdk.endpoint().connect()
127
153
  try {
128
- let results = await endpoint.upload({filePath: example_image_path})
154
+ let results = await endpoint.process({path: example_image_path})
129
155
  for await (let result of results) {
130
- plot.prediction(result)
156
+ EyePopSdk.plot(context).prediction(result)
131
157
  }
132
158
  } finally {
133
159
  await endpoint.disconnect()
@@ -144,7 +170,7 @@ const example_image_path = 'examples/example.jpg';
144
170
  })
145
171
  ```
146
172
  ### Asynchronous uploading and processing of images
147
- The above _synchronous_ way, upload() then iterate all results, is great for individual images or reasonable
173
+ The above _synchronous_ way, process() then iterate all results, is great for individual images or reasonable
148
174
  sized batches. For larger batch sizes, or continuous stream of images, don't `await` the results but instead
149
175
  use `then()` on the returned promise.
150
176
  ```typescript
@@ -156,12 +182,10 @@ const example_image_path = 'examples/example.jpg';
156
182
  const endpoint = await EyePopSdk.endpoint().connect()
157
183
  try {
158
184
  for (let i = 0; i < 100; i++) {
159
- endpoint.upload({filePath: example_image_path}).then(async (results) => {
185
+ endpoint.process({path: example_image_path}).then(async (results) => {
160
186
  for await (let result of results) {
161
187
  console.log(`result for #${i}`, result)
162
188
  }
163
- }).catch((reason) => {
164
- throw reason
165
189
  })
166
190
  }
167
191
  } finally {
@@ -184,7 +208,7 @@ const example_image_url = 'https://farm2.staticflickr.com/1080/1301049949_532835
184
208
  (async() => {
185
209
  const endpoint = await EyePopSdk.endpoint().connect()
186
210
  try {
187
- let results = await endpoint.loadFrom(example_image_url)
211
+ let results = await endpoint.process({url: example_image_url})
188
212
  for await (let result of results) {
189
213
  console.log(result)
190
214
  }
@@ -205,7 +229,7 @@ const example_video_url = 'https://demo-eyepop-videos.s3.amazonaws.com/test1_vlo
205
229
  (async() => {
206
230
  const endpoint = await EyePopSdk.endpoint().connect()
207
231
  try {
208
- let results = await endpoint.loadFrom(example_image_url)
232
+ let results = await endpoint.process({url: example_image_url})
209
233
  for await (let result of results) {
210
234
  console.log(result)
211
235
  }
@@ -225,7 +249,7 @@ const example_video_url = 'https://demo-eyepop-videos.s3.amazonaws.com/test1_vlo
225
249
  (async() => {
226
250
  const endpoint = EyePopSdk.endpoint().connect()
227
251
  try {
228
- let results = await endpoint.loadFrom(example_image_url)
252
+ let results = await endpoint.process({url: example_image_url})
229
253
  for await (let result of results) {
230
254
  console.log(result)
231
255
  if (result['seconds'] >= 10.0) {