@eyepop.ai/eyepop 0.11.0 → 0.12.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
@@ -11,11 +11,34 @@ 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:
15
22
  ```typescript
16
23
  import { EyePopSdk } from '@eyepop.ai/eyepop'
17
24
  (async() => {
18
- const endpoint = await EyePopSdk.endpoint().connect()
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:
37
+ ```typescript
38
+ import { EyePopSdk } from '@eyepop.ai/eyepop'
39
+ (async() => {
40
+ const endpoint = EyePopSdk.endpoint()
41
+ await endpoint.connect()
19
42
  // do work ....
20
43
  await endpoint.disconnect()
21
44
  })
@@ -38,7 +61,7 @@ server.listen(8080, '127.0.0.1');
38
61
  import { EyePopSdk } from '@eyepop.ai/eyepop'
39
62
  (async() => {
40
63
  const session = await (await fetch("http://127.0.0.1:8080")).json();
41
- const endpoint = await EyePopSdk.endpoint({ session: session }).connect();
64
+ const endpoint = await EyePopSdk.endpoint({ auth: { session: session } }).connect();
42
65
  // do work ....
43
66
  await endpoint.disconnect();
44
67
  });
@@ -61,12 +84,6 @@ import { EyePopSdk } from '@eyepop.ai/eyepop'
61
84
  </script>
62
85
  </body>
63
86
  ```
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`
70
87
  ## Usage Examples
71
88
  ### Uploading and processing one single image
72
89
  ```typescript
@@ -77,7 +94,7 @@ const example_image_path = 'examples/example.jpg';
77
94
  (async() => {
78
95
  const endpoint = await EyePopSdk.endpoint().connect()
79
96
  try {
80
- let results = await endpoint.upload({filePath: example_image_path})
97
+ let results = await endpoint.process({path: example_image_path})
81
98
  for await (let result of results) {
82
99
  console.log(result)
83
100
  }
@@ -89,7 +106,7 @@ const example_image_path = 'examples/example.jpg';
89
106
  1. `EyePopSdk.endpoint()` returns a local endpoint object, that will authenticate with the Api Key found in
90
107
  EYEPOP_SECRET_KEY and load the worker configuration for the Pop identified by EYEPOP_POP_ID.
91
108
  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.
109
+ 3. `endpoint.process({path:'examples/example.jpg'})` initiates the upload to the local file to the worker service.
93
110
  The image will be queued and processed immediately when the worker becomes available.
94
111
  The result of endpoint.upload() implements `AsyncIterable<Prediction>` which can be iterated fir 'for await' as
95
112
  shown in the example above. Predictions will become available when the submitted file becomes processed by the worker
@@ -97,7 +114,7 @@ and results are efficiently streamed back to the calling client. If the uploaded
97
114
  e.g. 'video/mp4' or image container format e.g. 'image/gif', the client will receive one prediction per image frame
98
115
  until the entire file has been processed.
99
116
 
100
- 4. Alternatively to `filePath` upload() also accepts a readable stream with a mandatory mime-type:
117
+ 4. Alternatively to `path` process() also accepts a readable stream with a mandatory mime-type:
101
118
  ```typescript
102
119
  // ...
103
120
  let stream = fs.createReadStream(example_image_path)
@@ -121,13 +138,12 @@ const example_image_path = 'examples/example.jpg';
121
138
  const canvas = createCanvas(image.width, image.height)
122
139
  const context = canvas.getContext("2d")
123
140
  context.drawImage(image, 0, 0)
124
- const plot = EyePopSdk.plot(context)
125
141
 
126
142
  const endpoint = await EyePopSdk.endpoint().connect()
127
143
  try {
128
- let results = await endpoint.upload({filePath: example_image_path})
144
+ let results = await endpoint.process({path: example_image_path})
129
145
  for await (let result of results) {
130
- plot.prediction(result)
146
+ EyePopSdk.plot(context).prediction(result)
131
147
  }
132
148
  } finally {
133
149
  await endpoint.disconnect()
@@ -144,7 +160,7 @@ const example_image_path = 'examples/example.jpg';
144
160
  })
145
161
  ```
146
162
  ### Asynchronous uploading and processing of images
147
- The above _synchronous_ way, upload() then iterate all results, is great for individual images or reasonable
163
+ The above _synchronous_ way, process() then iterate all results, is great for individual images or reasonable
148
164
  sized batches. For larger batch sizes, or continuous stream of images, don't `await` the results but instead
149
165
  use `then()` on the returned promise.
150
166
  ```typescript
@@ -156,12 +172,10 @@ const example_image_path = 'examples/example.jpg';
156
172
  const endpoint = await EyePopSdk.endpoint().connect()
157
173
  try {
158
174
  for (let i = 0; i < 100; i++) {
159
- endpoint.upload({filePath: example_image_path}).then(async (results) => {
175
+ endpoint.process({path: example_image_path}).then(async (results) => {
160
176
  for await (let result of results) {
161
177
  console.log(`result for #${i}`, result)
162
178
  }
163
- }).catch((reason) => {
164
- throw reason
165
179
  })
166
180
  }
167
181
  } finally {
@@ -184,7 +198,7 @@ const example_image_url = 'https://farm2.staticflickr.com/1080/1301049949_532835
184
198
  (async() => {
185
199
  const endpoint = await EyePopSdk.endpoint().connect()
186
200
  try {
187
- let results = await endpoint.loadFrom(example_image_url)
201
+ let results = await endpoint.process({url: example_image_url})
188
202
  for await (let result of results) {
189
203
  console.log(result)
190
204
  }
@@ -205,7 +219,7 @@ const example_video_url = 'https://demo-eyepop-videos.s3.amazonaws.com/test1_vlo
205
219
  (async() => {
206
220
  const endpoint = await EyePopSdk.endpoint().connect()
207
221
  try {
208
- let results = await endpoint.loadFrom(example_image_url)
222
+ let results = await endpoint.process({url: example_image_url})
209
223
  for await (let result of results) {
210
224
  console.log(result)
211
225
  }
@@ -225,7 +239,7 @@ const example_video_url = 'https://demo-eyepop-videos.s3.amazonaws.com/test1_vlo
225
239
  (async() => {
226
240
  const endpoint = EyePopSdk.endpoint().connect()
227
241
  try {
228
- let results = await endpoint.loadFrom(example_image_url)
242
+ let results = await endpoint.process({url: example_image_url})
229
243
  for await (let result of results) {
230
244
  console.log(result)
231
245
  if (result['seconds'] >= 10.0) {