pinokiod 1.2.43 → 1.2.45

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.
@@ -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
- if (!this.client) {
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
  }
@@ -106,8 +106,24 @@ class Api {
106
106
  // 1. set the "stop" flag for the uri, so the next execution in the queue for the uri will NOT queue another task
107
107
  // 2. stream a message closing the socket
108
108
 
109
+
110
+
109
111
  let requestPath = this.filePath(req.params.uri)
110
112
 
113
+
114
+
115
+ let { cwd, script } = await this.resolveScript(requestPath)
116
+ console.log("script", script)
117
+ if (script.on) {
118
+ if (script.on.stop) {
119
+ console.log("BEFORE STOP")
120
+ await this.process(script.on.stop)
121
+ console.log("AFTER STOP")
122
+ }
123
+ }
124
+
125
+
126
+
111
127
  // stop all shell processes connected to the uri
112
128
  this.kernel.shell.kill({ group: requestPath })
113
129
 
@@ -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.43",
3
+ "version": "1.2.45",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {