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