pinokiod 1.2.31 → 1.2.33

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.
@@ -8,8 +8,17 @@ module.exports = async (req, ondata, kernel) => {
8
8
  }
9
9
  }
10
10
  */
11
- if (req.params && typeof req.params.index !== "undefined") {
11
+ if (req.params.hasOwnProperty("index")) {
12
12
  req.next = req.params.index
13
- return req.params.input
13
+ } else if (req.params.hasOwnProperty("id")) {
14
+ // find the req.next
15
+ let run = req.parent.body.run
16
+ for(let i=0; i<run.length; i++) {
17
+ let step = run[i]
18
+ if (step && step.id === req.params.id) {
19
+ req.next = i
20
+ }
21
+ }
14
22
  }
23
+ return req.params.input
15
24
  }
@@ -0,0 +1,60 @@
1
+ class Gradio {
2
+ /*
3
+ {
4
+ "method": "gradio.predict",
5
+ "params": {
6
+ uri: <uri>,
7
+ path: "/answer_question_1"
8
+ params: [
9
+ { image: <filepath> },
10
+ { video: <uri> },
11
+ <str>
12
+ ]
13
+ }
14
+ }
15
+ */
16
+ async predict(req, ondata, kernel) {
17
+ if (!this.client) {
18
+ const dynamic = new Function('modulePath', 'return import(modulePath)');
19
+ const { client } = await dynamic('node-gradio-client');
20
+ //const { client } = await dynamic('@gradio/client');
21
+ this.client = client
22
+ }
23
+ const app = await this.client(req.params.uri)
24
+
25
+
26
+ // params parsing
27
+ // let args = []
28
+ // for(let param of req.params.params) {
29
+ // if (typeof param === 'object') {
30
+ // let key = Object.keys(param)[0]
31
+ // let val = param[key]
32
+ //
33
+ // if (val.startsWith("http")) {
34
+ // // http url
35
+ // const response = await fetch(param.uri)
36
+ // const blob = await response.blob();
37
+ // args.push(blob)
38
+ // } else {
39
+ // // file path
40
+ // const buffer = await fs.promises.readFile(param.file)
41
+ // args.push(buffer)
42
+ // }
43
+ //
44
+ // if (param.file) {
45
+ // // open file
46
+ // } else if (param.uri) {
47
+ // // fetch uri
48
+ // }
49
+ // } else {
50
+ // args.push(param)
51
+ // }
52
+ // }
53
+
54
+ let args = req.params.params
55
+ console.log("args", args)
56
+ let res = await app.predict(req.params.path, args)
57
+ return res
58
+ }
59
+ }
60
+ module.exports = Gradio
@@ -0,0 +1,14 @@
1
+ module.exports = async (req, ondata, kernel) => {
2
+ /*
3
+ req := {
4
+ "method": "import",
5
+ "params": {
6
+ <name>: <uri>|<relative_filepath>|<absolute_filepath>,
7
+ <name>: <uri>|<relative_filepath>|<absolute_filepath>,
8
+ }
9
+ }
10
+ */
11
+ let imported = kernel.import(req.params, req.cwd)
12
+ console.log("IMPORTED", imported)
13
+ return imported
14
+ }
@@ -488,7 +488,7 @@ class Api {
488
488
  }
489
489
  async step (request, rawrpc, input, i, total, args) {
490
490
 
491
- await this.kernel.api.init()
491
+ await this.init()
492
492
 
493
493
  // clear global regular expression object RegExp.lastMatch (memory leak prevention)
494
494
  let r = /\s*/g.exec("");
@@ -518,6 +518,8 @@ class Api {
518
518
  this.executing = request
519
519
 
520
520
 
521
+ console.log("memory", memory)
522
+
521
523
  // render until `{{ }}` pattern does not exist
522
524
  // 1. render once
523
525
  let rpc = rawrpc
@@ -540,6 +542,8 @@ class Api {
540
542
  // replace {{{ }}} with {{ }}
541
543
  rpc = this.kernel.template.flatten(rpc)
542
544
 
545
+ console.log("rpc", rpc)
546
+
543
547
  // 6. rpc must have method names
544
548
  if (rpc.method) {
545
549
 
@@ -1,6 +1,30 @@
1
1
  const set = require("../set")
2
2
  const rm = require("../rm")
3
3
  class Local {
4
+ async import(req, ondata, kernel) {
5
+ /*
6
+ req := {
7
+ "method": "local.import",
8
+ "params": {
9
+ <name>: <uri>|<relative_filepath>|<absolute_filepath>,
10
+ <name>: <uri>|<relative_filepath>|<absolute_filepath>,
11
+ }
12
+ }
13
+ */
14
+ let imported = kernel.import("local", req.params, req.cwd)
15
+ console.log("IMPORTED", imported)
16
+
17
+ let converted = Object.assign({}, req, {
18
+ params: {
19
+ local: imported
20
+ }
21
+ })
22
+ console.log("converted", converted)
23
+ let res = await set(converted, ondata, kernel)
24
+
25
+ console.log("memory", JSON.stringify(kernel.memory, null, 2))
26
+ return res
27
+ }
4
28
  async set(req, ondata, kernel) {
5
29
  /*
6
30
  req := {
@@ -1,5 +1,20 @@
1
1
  const path = require('path')
2
2
  class Script {
3
+ async start(req, ondata, kernel) {
4
+ let res = await this.run(req, ondata, kernel)
5
+ return res
6
+ }
7
+ async stop(req, ondata, kernel) {
8
+ // stop the script
9
+ kernel.api.stop({
10
+ params: {
11
+ uri: req.params.uri
12
+ }
13
+ })
14
+ ondata({
15
+ raw: `\r\nStopped ${req.params.uri}\r\n`
16
+ })
17
+ }
3
18
  async run(req, ondata, kernel) {
4
19
  /*
5
20
  {
@@ -40,6 +40,7 @@ class Self {
40
40
  self: req.params
41
41
  }
42
42
  })
43
+ console.log({ req, converted })
43
44
  let res = await set(converted, ondata, kernel)
44
45
  return res
45
46
  }
package/kernel/index.js CHANGED
@@ -45,6 +45,19 @@ class Kernel {
45
45
  this.procs[uri] = undefined
46
46
  }
47
47
  }
48
+ import(type, params, cwd) {
49
+ /*
50
+ type := "local" | "global"
51
+ */
52
+ let o = {}
53
+ for(let key in params) {
54
+ // get memory for each uri
55
+ let uri = params[key]
56
+ let fpath = this.api.filePath(uri, cwd)
57
+ o[key] = this.memory[type][fpath]
58
+ }
59
+ return o
60
+ }
48
61
  local(...args) {
49
62
  // get local variables at path
50
63
  let filePath = this.api.filePath(path.resolve(...args))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "1.2.31",
3
+ "version": "1.2.33",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -43,6 +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.2",
46
47
  "node-pty-prebuilt-multiarch-cp": "^0.10.1-pre.48",
47
48
  "open": "8.4.2",
48
49
  "pdrive": "^0.0.23",