pinokiod 1.2.43 → 1.2.44
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/kernel/api/gradio/index.js +2 -52
- package/kernel/api/script/index.js +17 -8
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@ class Gradio {
|
|
|
7
7
|
"params": {
|
|
8
8
|
uri: <uri>,
|
|
9
9
|
path: "/answer_question_1"
|
|
10
|
+
//on: "{{payload.data.translation}}"
|
|
10
11
|
params: [
|
|
11
12
|
{ image: <filepath> },
|
|
12
13
|
{ video: <uri> },
|
|
@@ -16,59 +17,8 @@ class Gradio {
|
|
|
16
17
|
}
|
|
17
18
|
*/
|
|
18
19
|
async predict(req, ondata, kernel) {
|
|
19
|
-
|
|
20
|
-
//const gradio_path = path.resolve(__dirname, '../../../node_modules/node-gradio-client/dist')
|
|
21
|
-
//const gradio_path = path.resolve(__dirname, '../../../node_modules/node-gradio-client/dist/index.mjs')
|
|
22
|
-
//const gradio_path = path.resolve(__dirname, '../../../node_modules/node-gradio-client')
|
|
23
|
-
//const gradio_path = "node-gradio-client"
|
|
24
|
-
//const gradio_path = path.resolve(__dirname, 'node-gradio-client')
|
|
25
|
-
//const gradio_path = path.resolve(__dirname, 'node-gradio-client')
|
|
26
|
-
//const gradio_path = path.resolve(__dirname, '../../../node_modules/node-gradio-client/dist/index.js')
|
|
27
|
-
//console.log("gradio_path", gradio_path)
|
|
28
|
-
//const gradio_path = 'node-gradio-client'
|
|
29
|
-
//const dynamic = new Function('modulePath', 'return import(modulePath)');
|
|
30
|
-
//const { client } = await dynamic(gradio_path)
|
|
31
|
-
// const { client } = await import(gradio_path)
|
|
32
|
-
//const { client } = require(gradio_path)
|
|
33
|
-
console.log("Client", client)
|
|
34
|
-
//const { client } = await dynamic('@gradio/client');
|
|
35
|
-
this.client = client
|
|
36
|
-
}
|
|
37
|
-
const app = await this.client(req.params.uri)
|
|
38
|
-
// console.log("PREDICT", client)
|
|
39
|
-
//const app = await client(req.params.uri)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// params parsing
|
|
43
|
-
// let args = []
|
|
44
|
-
// for(let param of req.params.params) {
|
|
45
|
-
// if (typeof param === 'object') {
|
|
46
|
-
// let key = Object.keys(param)[0]
|
|
47
|
-
// let val = param[key]
|
|
48
|
-
//
|
|
49
|
-
// if (val.startsWith("http")) {
|
|
50
|
-
// // http url
|
|
51
|
-
// const response = await fetch(param.uri)
|
|
52
|
-
// const blob = await response.blob();
|
|
53
|
-
// args.push(blob)
|
|
54
|
-
// } else {
|
|
55
|
-
// // file path
|
|
56
|
-
// const buffer = await fs.promises.readFile(param.file)
|
|
57
|
-
// args.push(buffer)
|
|
58
|
-
// }
|
|
59
|
-
//
|
|
60
|
-
// if (param.file) {
|
|
61
|
-
// // open file
|
|
62
|
-
// } else if (param.uri) {
|
|
63
|
-
// // fetch uri
|
|
64
|
-
// }
|
|
65
|
-
// } else {
|
|
66
|
-
// args.push(param)
|
|
67
|
-
// }
|
|
68
|
-
// }
|
|
69
|
-
|
|
20
|
+
const app = await client(req.params.uri)
|
|
70
21
|
let args = req.params.params
|
|
71
|
-
console.log("Args", args)
|
|
72
22
|
let res = await app.predict(req.params.path, args)
|
|
73
23
|
return res
|
|
74
24
|
}
|
|
@@ -5,15 +5,24 @@ class Script {
|
|
|
5
5
|
return res
|
|
6
6
|
}
|
|
7
7
|
async stop(req, ondata, kernel) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
console.log("script.stop", req)
|
|
9
|
+
/*
|
|
10
|
+
{
|
|
11
|
+
"method": "script.run",
|
|
12
|
+
"params": {
|
|
13
|
+
"uri": <string>|<array>
|
|
14
|
+
}
|
|
12
15
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
*/
|
|
17
|
+
// stop the script
|
|
18
|
+
let uris = req.params.uri
|
|
19
|
+
if (!Array.isArray(uris)) {
|
|
20
|
+
uris = [uris]
|
|
21
|
+
}
|
|
22
|
+
for(let uri of uris) {
|
|
23
|
+
kernel.api.stop({ params: { uri } })
|
|
24
|
+
ondata({ raw: `\r\nStopped ${req.params.uri}\r\n` })
|
|
25
|
+
}
|
|
17
26
|
}
|
|
18
27
|
async run(req, ondata, kernel) {
|
|
19
28
|
/*
|