Skip to content
This repository has been archived by the owner on Nov 23, 2023. It is now read-only.

Commit

Permalink
Merge branch 'backend/graph-interpreter' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Rec1dite committed Jul 30, 2023
2 parents 7e66b5b + 6360f5e commit c08b5e3
Show file tree
Hide file tree
Showing 44 changed files with 1,220 additions and 321 deletions.
61 changes: 46 additions & 15 deletions blix-plugins/hello-plugin/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,59 @@ const nodes = {
nodeBuilder = context.instantiate("hello-plugin","hello");
nodeBuilder.setTitle("Gloria");
nodeBuilder.setDescription("Provides a test slider and button and label for testing purposes, taking two string inputs and returning one string output");
nodeBuilder.define(() => {
console.log("konnichi~wa");

nodeBuilder.define((anchorInputs, uiInputs, requiredOutputs) => {
// console.log(
// "------------------",
// "\nANCHOR INPUTS", anchorInputs,
// "\nUI INPUTS", uiInputs,
// "\nREQUIRED OUTPUTS", requiredOutputs
// );

// Doing it this way allows us to only compute the outputs that are required
const computers = {
"out1": () => anchorInputs["in1"] + anchorInputs["in2"],
"out2": () => anchorInputs["in3"],
"out3": () => uiInputs["slideAlong"]
};

let res = {};
for (const output of requiredOutputs) {
res = { ...res, [output]: computers[output]() }
}

// console.log("RETURNING", res);
return res;
});

const ui = nodeBuilder.createUIBuilder();
ui.addButton("Execute order 66","return 66;")
.addSlider("Slide along",0,100,0.1,50)
.addColorPicker("Massacre", "red")
.addKnob("Knob",0,100,0.1,50)
.addDropdown("Orphanage",nodeBuilder.createUIBuilder()
.addLabel("Label1"));
ui.addButton({},"return 66;")
.addSlider(
{
componentId: "slideAlong",
label: "Slide Along",
defaultValue: 0,
updateBackend: true,
},
{ min: 0, max: 100, set: 0.1 }
);

// .addColorPicker("massacre", "red")
// .addKnob("yourAKnob",0,100,0.1,50)
// .addDropdown("orphanage",nodeBuilder.createUIBuilder()
// .addLabel("Label1"));

nodeBuilder.setUI(ui);

nodeBuilder.addInput("string", "in1", "In1");
nodeBuilder.addInput("string", "in2", "In2");
nodeBuilder.addInput("Number","In3", 2);

nodeBuilder.addOutput("string", "out1", "Out1");
// addInput(type: string, identifier: string, displayName: string)
nodeBuilder.addInput("string", "in1", "In 1");
nodeBuilder.addInput("string", "in2", "In 2");
nodeBuilder.addInput("Number", "in3", "In 3");

nodeBuilder.addOutput("Number","Out1", 3);
nodeBuilder.addOutput("Number","Out2", 4);
// addOutput(type: string, identifier: string, displayName: string)
nodeBuilder.addOutput("string", "out1", "Concat");
nodeBuilder.addOutput("Number", "out2", "Passthrough");
nodeBuilder.addOutput("Number", "out3", "Slider");
}
,"Jake": (context) => {
nodeBuilder = context.instantiate("hello-plugin","Jake");
Expand Down
9 changes: 5 additions & 4 deletions blix-plugins/input-plugin/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const nodes ={
nodeBuilder.setTitle("Input number");
nodeBuilder.setDescription("Provides a number input and returns a single number output");

nodeBuilder.define((num1) => {
return 3;
nodeBuilder.define((input, uiInput, from) => {
return {"res": 3};
});
nodeBuilder.addOutput("Number", "res", "Result");

Expand All @@ -18,8 +18,9 @@ const nodes ={
nodeBuilder.setTitle("Input image");
nodeBuilder.setDescription("Provides an image input and returns a single image output");

nodeBuilder.define((image) => {
return image;
nodeBuilder.define(async (input, uiInput, from) => {

return { "res": "/home/klairgo/Desktop/AI-Photo-Editor/assets/image.png"};
});
nodeBuilder.addOutput("Sharp", "res", "Result");

Expand Down
112 changes: 61 additions & 51 deletions blix-plugins/math-plugin/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,47 @@ const nodes ={
nodeBuilder.setTitle("Unary");
nodeBuilder.setDescription("Performs Unary math operations taking one number input and returning one number output");

nodeBuilder.define((num1, state) => {
let result;

switch (state) {
case 0:
// squared
result = Math.pow(num1, 2);
break;

case 1:
// square root
result = Math.sqrt(num1);
break;
case 2:
// absolute value
result = Math.abs(num1);
break;
case 3:
// factorial
result = factorial(num1);
break;
case 4:
// negative
result = -num1;
break;
case 5:
// sine
result = Math.sin(num1);
break;

case 6:
// cosine
result = Math.cos(num1);
break;

case 7:
// tangent
result = Math.tan(num1);
break;

default:
result = "Invalid state";
}

return result;
});

nodeBuilder.addInput("Number", "num","Num");
nodeBuilder.addOutput("Number", "res","Result");
// (anchorInputs: { [key: AnchorId]: any }, uiInputs: { [key: UIComponentId]: any }) => { [key: AnchorId]: any }
nodeBuilder.define((anchorInputs, uiInputs) => {
state = uiInputs?.state ?? 0;
switch (state) {
case 0: return { res: Math.pow(anchorInputs.num, 2) };
case 1: return { res: Math.sqrt(anchorInputs.num) };
case 2: return { res: Math.abs(anchorInputs.num) };
case 3: return { res: factorial(anchorInputs.num) };
case 4: return { res: -anchorInputs.num };
case 5: return { res: Math.sin(anchorInputs.num) };
case 6: return { res: Math.cos(anchorInputs.num) };
case 7: return { res: Math.tan(anchorInputs.num) };
}
return { res: "Invalid state" };
});

const ui = nodeBuilder.createUIBuilder();
ui.addDropdown({
componentId: "state",
label: "State",
defaultValue: 0,
updateBackend: true,
}, {
"Square": 0,
"Square Root": 1,
"Absolute": 2,
"Factorial": 3,
"Negate": 4,
"Sine": 5,
"Cosine": 6,
"Tangent": 7
});

nodeBuilder.setUI(ui);

// UI params are passed directly to the defined function
// Optionally, you can specify to disable certain UI params when
// an edge is connected to a specific anchor

nodeBuilder.addInput("Number", "num","Num");
nodeBuilder.addOutput("Number", "res","Result");
},
"binary": (context) => {
const nodeBuilder = context.instantiate("math-plugin", "binary");
Expand Down Expand Up @@ -115,8 +107,26 @@ const nodes ={
nodeBuilder.addOutput("Number", "res1", "Result");
},

// // Testing nodes
// "add": (context) => {
// Testing nodes
"add": (context) => {
nodeBuilder = context.instantiate("math-plugin","add");
nodeBuilder.setTitle("Add");
nodeBuilder.setDescription("Performs Unary math operations taking one number input and returning one number output");

nodeBuilder.define((input, uiInput, from) => {
console.log(input);
return {
"res": input["num1"] + input["num2"],
};

});

nodeBuilder.addInput("Number", "num1","Num");
nodeBuilder.addInput("Number", "num2","Num");
nodeBuilder.addOutput("Number", "res","Result");
},
// TO BE DEVELOPED
// "ternary": (context) => {
// nodeBuilder = context.instantiate("math-plugin","add");
// nodeBuilder.setTitle("Add");
// nodeBuilder.setDescription("Performs Unary math operations taking one number input and returning one number output");
Expand Down
58 changes: 53 additions & 5 deletions blix-plugins/sharp-plugin/src/main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
const sharp = require('sharp');

const nodes ={
"brightness": (context) => {
nodeBuilder = context.instantiate("sharp-plugin","brightness");
nodeBuilder.setTitle("Brightness");
nodeBuilder.setDescription("Adjusts the brighness of an image taking one image as input and returning one image as output");

nodeBuilder.define(() => {
nodeBuilder.define(async (input, uiInput, from) => {
return {
"res": await input["img"].modulate({
brightness: 2
}),
}
//TODO: implement
});

Expand All @@ -16,7 +23,12 @@ const nodes ={
nodeBuilder.setTitle("Saturation");
nodeBuilder.setDescription("Adjusts the saturation of an image taking one image as input and returning one image as output");

nodeBuilder.define(() => {
nodeBuilder.define((input, uiInput, from) => {
return {
"res": input["img"].modulate({
saturation: 0.5
}),
}
//TODO: implement
});

Expand All @@ -28,8 +40,13 @@ const nodes ={
nodeBuilder.setTitle("Hue");
nodeBuilder.setDescription("Adjusts the hue of an image taking one image as input and returning one image as output");

nodeBuilder.define(() => {
nodeBuilder.define((input, uiInput, from) => {
//TODO: implement
return {
"res": input["img"].modulate({
hue: 90
}),
}
});

nodeBuilder.addInput("Sharp", "img","Img");
Expand All @@ -40,8 +57,11 @@ const nodes ={
nodeBuilder.setTitle("Rotate");
nodeBuilder.setDescription("Rotates an image by an explicit angle taking one image as input and returning one image as output");

nodeBuilder.define(() => {
nodeBuilder.define((input, uiInput, from) => {
//TODO: implement
return {
"res": input["img"].rotate(90),
}
});

nodeBuilder.addInput("Sharp", "img","Img");
Expand All @@ -52,7 +72,7 @@ const nodes ={
nodeBuilder.setTitle("sharpen");
nodeBuilder.setDescription("Sharpens an image taking one image as input and returning one image as output");

nodeBuilder.define(() => {
nodeBuilder.define((input, uiInput, from) => {
//TODO: implement
});

Expand All @@ -70,7 +90,35 @@ const nodes ={

nodeBuilder.addInput("Sharp", "img","Img");
nodeBuilder.addOutput("Sharp", "res","Result");
},
"toImage": (context) => {
const nodeBuilder = context.instantiate("sharp-plugin", "toImage");
nodeBuilder.setTitle("To Image");
nodeBuilder.setDescription("Converts the sharp object to an image");

nodeBuilder.define(async (input, uiInput, from ) => {
//TODO: implement
const img = await input["img"].toBuffer();
return {"res": "data:image/png;base64, " + img.toString('base64')};
});

nodeBuilder.addInput("Sharp", "img","Img");
nodeBuilder.addOutput("Image", "res","Result");
},
"toSharp": (context) => {
const nodeBuilder = context.instantiate("sharp-plugin", "toSharp");
nodeBuilder.setTitle("To Sharp");
nodeBuilder.setDescription("Converts an image path to a sharp object");

nodeBuilder.define(async (input, uiInput, from ) => {
//TODO: implement
return {"res": sharp(input["img"])};
});

nodeBuilder.addInput("Image", "img","Img");
nodeBuilder.addOutput("Sharp", "res","Result");
}

}


Expand Down
Loading

0 comments on commit c08b5e3

Please sign in to comment.