@eyepop.ai/eyepop 0.10.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 +78 -23
- package/dist/eyepop.min.js +1 -1
- package/dist/eyepop.min.js.LICENSE.txt +18 -0
- package/dist/index.d.mts +40 -12
- package/dist/index.d.ts +40 -12
- package/dist/index.js +590 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +580 -60
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -6,26 +6,84 @@ TypeScript or JavaScript language.
|
|
|
6
6
|
npm install --save eyepop
|
|
7
7
|
```
|
|
8
8
|
## Configuration
|
|
9
|
-
The EyePop SDK needs to be configured with the __Pop Id__ and your
|
|
9
|
+
The EyePop SDK needs to be configured with the __Pop Id__ and your __Authentication Credentials__. Credentials can
|
|
10
|
+
be provided as:
|
|
11
|
+
1. __Api Key__, server side only because this key must be kept secret
|
|
12
|
+
2. __Session generated from Api Key__, server side generated session transported to client over trusted channel
|
|
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`
|
|
20
|
+
### Authentication with Api Key
|
|
21
|
+
Configuration and authorization with explicit defaults:
|
|
10
22
|
```typescript
|
|
11
23
|
import { EyePopSdk } from '@eyepop.ai/eyepop'
|
|
12
24
|
(async() => {
|
|
13
|
-
const endpoint = EyePopSdk.endpoint(
|
|
25
|
+
const endpoint = EyePopSdk.endpoint({
|
|
14
26
|
// This is the default and can be omitted
|
|
15
|
-
|
|
27
|
+
popId: process.env['EYEPOP_POP_ID'],
|
|
16
28
|
// This is the default and can be omitted
|
|
17
|
-
|
|
18
|
-
)
|
|
29
|
+
auth : {secretKey: process.env['EYEPOP_SECRET_KEY']},
|
|
30
|
+
})
|
|
19
31
|
await endpoint.connect()
|
|
20
32
|
// do work ....
|
|
21
33
|
await endpoint.disconnect()
|
|
22
34
|
})
|
|
23
35
|
```
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
36
|
+
Equivalent, but shorter:
|
|
37
|
+
```typescript
|
|
38
|
+
import { EyePopSdk } from '@eyepop.ai/eyepop'
|
|
39
|
+
(async() => {
|
|
40
|
+
const endpoint = EyePopSdk.endpoint()
|
|
41
|
+
await endpoint.connect()
|
|
42
|
+
// do work ....
|
|
43
|
+
await endpoint.disconnect()
|
|
44
|
+
})
|
|
45
|
+
```
|
|
46
|
+
### Authentication with session generated from Api Key
|
|
47
|
+
#### Server Side
|
|
48
|
+
```javascript
|
|
49
|
+
import { EyePopSdk } from '@eyepop.ai/eyepop'
|
|
50
|
+
const getSession = async function (req, res) {
|
|
51
|
+
const endpoint = await EyePopSdk.endpoint().connect();
|
|
52
|
+
res.setHeader("Content-Type", "application/json");
|
|
53
|
+
res.writeHead(200);
|
|
54
|
+
res.end(JSON.stringify(await endpoint.session()));
|
|
55
|
+
};
|
|
56
|
+
const server = http.createServer(getSession);
|
|
57
|
+
server.listen(8080, '127.0.0.1');
|
|
58
|
+
```
|
|
59
|
+
#### Client Side
|
|
60
|
+
```javascript
|
|
61
|
+
import { EyePopSdk } from '@eyepop.ai/eyepop'
|
|
62
|
+
(async() => {
|
|
63
|
+
const session = await (await fetch("http://127.0.0.1:8080")).json();
|
|
64
|
+
const endpoint = await EyePopSdk.endpoint({ auth: { session: session } }).connect();
|
|
65
|
+
// do work ....
|
|
66
|
+
await endpoint.disconnect();
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
### Authentication with Current Browser Session
|
|
70
|
+
```html
|
|
71
|
+
<!DOCTYPE html>
|
|
72
|
+
<html lang="en">
|
|
73
|
+
<head>
|
|
74
|
+
<meta charset="UTF-8">
|
|
75
|
+
<script src="https://cdn.jsdelivr.net/npm/@eyepop.ai/eyepop/dist/eyepop.min.js"></script>
|
|
76
|
+
</head>
|
|
77
|
+
<body>
|
|
78
|
+
<script>
|
|
79
|
+
document.addEventListener("DOMContentLoaded", async (event) => {
|
|
80
|
+
let endpoint = await EyePopSdk.endpoint({ auth: { oAuth: true }, popId: '< Pop Id>' }).connect();
|
|
81
|
+
// do work ....
|
|
82
|
+
await endpoint.disconnect();
|
|
83
|
+
});
|
|
84
|
+
</script>
|
|
85
|
+
</body>
|
|
86
|
+
```
|
|
29
87
|
## Usage Examples
|
|
30
88
|
### Uploading and processing one single image
|
|
31
89
|
```typescript
|
|
@@ -36,7 +94,7 @@ const example_image_path = 'examples/example.jpg';
|
|
|
36
94
|
(async() => {
|
|
37
95
|
const endpoint = await EyePopSdk.endpoint().connect()
|
|
38
96
|
try {
|
|
39
|
-
let results = await endpoint.
|
|
97
|
+
let results = await endpoint.process({path: example_image_path})
|
|
40
98
|
for await (let result of results) {
|
|
41
99
|
console.log(result)
|
|
42
100
|
}
|
|
@@ -48,7 +106,7 @@ const example_image_path = 'examples/example.jpg';
|
|
|
48
106
|
1. `EyePopSdk.endpoint()` returns a local endpoint object, that will authenticate with the Api Key found in
|
|
49
107
|
EYEPOP_SECRET_KEY and load the worker configuration for the Pop identified by EYEPOP_POP_ID.
|
|
50
108
|
2. Call `endpoint.connect()` before any job is submitted and `endpoint.disconnect()` to release all resources.
|
|
51
|
-
3. `endpoint.
|
|
109
|
+
3. `endpoint.process({path:'examples/example.jpg'})` initiates the upload to the local file to the worker service.
|
|
52
110
|
The image will be queued and processed immediately when the worker becomes available.
|
|
53
111
|
The result of endpoint.upload() implements `AsyncIterable<Prediction>` which can be iterated fir 'for await' as
|
|
54
112
|
shown in the example above. Predictions will become available when the submitted file becomes processed by the worker
|
|
@@ -56,7 +114,7 @@ and results are efficiently streamed back to the calling client. If the uploaded
|
|
|
56
114
|
e.g. 'video/mp4' or image container format e.g. 'image/gif', the client will receive one prediction per image frame
|
|
57
115
|
until the entire file has been processed.
|
|
58
116
|
|
|
59
|
-
4. Alternatively to `
|
|
117
|
+
4. Alternatively to `path` process() also accepts a readable stream with a mandatory mime-type:
|
|
60
118
|
```typescript
|
|
61
119
|
// ...
|
|
62
120
|
let stream = fs.createReadStream(example_image_path)
|
|
@@ -80,13 +138,12 @@ const example_image_path = 'examples/example.jpg';
|
|
|
80
138
|
const canvas = createCanvas(image.width, image.height)
|
|
81
139
|
const context = canvas.getContext("2d")
|
|
82
140
|
context.drawImage(image, 0, 0)
|
|
83
|
-
const plot = EyePopSdk.plot(context)
|
|
84
141
|
|
|
85
142
|
const endpoint = await EyePopSdk.endpoint().connect()
|
|
86
143
|
try {
|
|
87
|
-
let results = await endpoint.
|
|
144
|
+
let results = await endpoint.process({path: example_image_path})
|
|
88
145
|
for await (let result of results) {
|
|
89
|
-
plot.prediction(result)
|
|
146
|
+
EyePopSdk.plot(context).prediction(result)
|
|
90
147
|
}
|
|
91
148
|
} finally {
|
|
92
149
|
await endpoint.disconnect()
|
|
@@ -103,7 +160,7 @@ const example_image_path = 'examples/example.jpg';
|
|
|
103
160
|
})
|
|
104
161
|
```
|
|
105
162
|
### Asynchronous uploading and processing of images
|
|
106
|
-
The above _synchronous_ way,
|
|
163
|
+
The above _synchronous_ way, process() then iterate all results, is great for individual images or reasonable
|
|
107
164
|
sized batches. For larger batch sizes, or continuous stream of images, don't `await` the results but instead
|
|
108
165
|
use `then()` on the returned promise.
|
|
109
166
|
```typescript
|
|
@@ -115,12 +172,10 @@ const example_image_path = 'examples/example.jpg';
|
|
|
115
172
|
const endpoint = await EyePopSdk.endpoint().connect()
|
|
116
173
|
try {
|
|
117
174
|
for (let i = 0; i < 100; i++) {
|
|
118
|
-
endpoint.
|
|
175
|
+
endpoint.process({path: example_image_path}).then(async (results) => {
|
|
119
176
|
for await (let result of results) {
|
|
120
177
|
console.log(`result for #${i}`, result)
|
|
121
178
|
}
|
|
122
|
-
}).catch((reason) => {
|
|
123
|
-
throw reason
|
|
124
179
|
})
|
|
125
180
|
}
|
|
126
181
|
} finally {
|
|
@@ -143,7 +198,7 @@ const example_image_url = 'https://farm2.staticflickr.com/1080/1301049949_532835
|
|
|
143
198
|
(async() => {
|
|
144
199
|
const endpoint = await EyePopSdk.endpoint().connect()
|
|
145
200
|
try {
|
|
146
|
-
let results = await endpoint.
|
|
201
|
+
let results = await endpoint.process({url: example_image_url})
|
|
147
202
|
for await (let result of results) {
|
|
148
203
|
console.log(result)
|
|
149
204
|
}
|
|
@@ -164,7 +219,7 @@ const example_video_url = 'https://demo-eyepop-videos.s3.amazonaws.com/test1_vlo
|
|
|
164
219
|
(async() => {
|
|
165
220
|
const endpoint = await EyePopSdk.endpoint().connect()
|
|
166
221
|
try {
|
|
167
|
-
let results = await endpoint.
|
|
222
|
+
let results = await endpoint.process({url: example_image_url})
|
|
168
223
|
for await (let result of results) {
|
|
169
224
|
console.log(result)
|
|
170
225
|
}
|
|
@@ -184,7 +239,7 @@ const example_video_url = 'https://demo-eyepop-videos.s3.amazonaws.com/test1_vlo
|
|
|
184
239
|
(async() => {
|
|
185
240
|
const endpoint = EyePopSdk.endpoint().connect()
|
|
186
241
|
try {
|
|
187
|
-
let results = await endpoint.
|
|
242
|
+
let results = await endpoint.process({url: example_image_url})
|
|
188
243
|
for await (let result of results) {
|
|
189
244
|
console.log(result)
|
|
190
245
|
if (result['seconds'] >= 10.0) {
|