Skip to content

Commit a7b1c4e

Browse files
authored
[ACTION] Break Runware action into individual actions (#14600)
1 parent ebe92f3 commit a7b1c4e

File tree

11 files changed

+948
-247
lines changed

11 files changed

+948
-247
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import { v4 as uuid } from "uuid";
3+
import app from "../../runware.app.mjs";
4+
import constants from "../../common/constants.mjs";
5+
import utils from "../../common/utils.mjs";
6+
7+
export default {
8+
key: "runware-image-background-removal",
9+
name: "Image Background Removal",
10+
description: "Request an image background removal task to be processed by the Runware API. [See the documentation](https://docs.runware.ai/en/image-editing/background-removal).",
11+
version: "0.0.1",
12+
type: "action",
13+
props: {
14+
app,
15+
inputImage: {
16+
propDefinition: [
17+
app,
18+
"inputImage",
19+
],
20+
},
21+
outputType: {
22+
propDefinition: [
23+
app,
24+
"outputType",
25+
],
26+
},
27+
outputFormat: {
28+
propDefinition: [
29+
app,
30+
"outputFormat",
31+
],
32+
},
33+
includeCost: {
34+
propDefinition: [
35+
app,
36+
"includeCost",
37+
],
38+
},
39+
rgb: {
40+
type: "string[]",
41+
label: "RGB",
42+
description: "An array representing the `[red, green, blue]` values that define the color of the removed background. Eg. `[255, 255, 255]`.",
43+
optional: true,
44+
},
45+
postProcessMask: {
46+
type: "boolean",
47+
label: "Post-Process Mask",
48+
description: "Flag indicating whether to post-process the mask. Controls whether the mask should undergo additional post-processing. This step can improve the accuracy and quality of the background removal mask.",
49+
optional: true,
50+
},
51+
returnOnlyMask: {
52+
type: "boolean",
53+
label: "Return Only Mask",
54+
description: "Flag indicating whether to return only the mask. The mask is the opposite of the image background removal.",
55+
optional: true,
56+
},
57+
alphaMatting: {
58+
type: "boolean",
59+
label: "Alpha Matting",
60+
description: "Flag indicating whether to use alpha matting. Alpha matting is a post-processing technique that enhances the quality of the output by refining the edges of the foreground object.",
61+
optional: true,
62+
},
63+
alphaMattingForegroundThreshold: {
64+
type: "integer",
65+
label: "Alpha Matting Foreground Threshold",
66+
description: "Threshold value used in alpha matting to distinguish the foreground from the background. Adjusting this parameter affects the sharpness and accuracy of the foreground object edges. Eg. `240`.",
67+
optional: true,
68+
min: 1,
69+
max: 255,
70+
},
71+
alphaMattingBackgroundThreshold: {
72+
type: "integer",
73+
label: "Alpha Matting Background Threshold",
74+
description: "Threshold value used in alpha matting to refine the background areas. It influences how aggressively the algorithm removes the background while preserving image details. The higher the value, the more computation is needed and therefore the more expensive the operation is. Eg. `10`.",
75+
optional: true,
76+
min: 1,
77+
max: 255,
78+
},
79+
alphaMattingErodeSize: {
80+
type: "integer",
81+
label: "Alpha Matting Erode Size",
82+
description: "Specifies the size of the erosion operation used in alpha matting. Erosion helps in smoothing the edges of the foreground object for a cleaner removal of the background. Eg. `10`.",
83+
optional: true,
84+
min: 1,
85+
max: 255,
86+
},
87+
},
88+
methods: {
89+
getRGBA(rgb, alpha = 0) {
90+
if (rgb) {
91+
const parsed = utils.parseArray(rgb).map((value) => parseInt(value, 10));
92+
return parsed.concat(alpha);
93+
}
94+
},
95+
},
96+
async run({ $ }) {
97+
const {
98+
app,
99+
getRGBA,
100+
inputImage,
101+
outputType,
102+
outputFormat,
103+
includeCost,
104+
rgb,
105+
postProcessMask,
106+
returnOnlyMask,
107+
alphaMatting,
108+
alphaMattingForegroundThreshold,
109+
alphaMattingBackgroundThreshold,
110+
alphaMattingErodeSize,
111+
} = this;
112+
113+
if (rgb && utils.parseArray(rgb).length !== 3) {
114+
throw new ConfigurationError("The **RGB** array must contain exactly 3 integer numbers. Eg. `[255, 255, 255]`.");
115+
}
116+
117+
const response = await app.post({
118+
$,
119+
data: [
120+
{
121+
taskType: constants.TASK_TYPE.IMAGE_BACKGROUND_REMOVAL.value,
122+
taskUUID: uuid(),
123+
inputImage,
124+
outputType,
125+
outputFormat,
126+
includeCost,
127+
rgba: getRGBA(rgb),
128+
postProcessMask,
129+
returnOnlyMask,
130+
alphaMatting,
131+
alphaMattingForegroundThreshold,
132+
alphaMattingBackgroundThreshold,
133+
alphaMattingErodeSize,
134+
},
135+
],
136+
});
137+
138+
$.export("$summary", `Successfully requested image background removal task with UUID \`${response.data[0].taskUUID}\`.`);
139+
return response;
140+
},
141+
};
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { v4 as uuid } from "uuid";
2+
import app from "../../runware.app.mjs";
3+
import constants from "../../common/constants.mjs";
4+
5+
export default {
6+
key: "runware-image-caption",
7+
name: "Image Caption",
8+
description: "Request an image caption task to be processed by the Runware API. [See the documentation](https://docs.runware.ai/en/utilities/image-to-text).",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
app,
13+
inputImage: {
14+
propDefinition: [
15+
app,
16+
"inputImage",
17+
],
18+
},
19+
includeCost: {
20+
propDefinition: [
21+
app,
22+
"includeCost",
23+
],
24+
},
25+
},
26+
async run({ $ }) {
27+
const {
28+
app,
29+
inputImage,
30+
includeCost,
31+
} = this;
32+
33+
const response = await app.post({
34+
$,
35+
data: [
36+
{
37+
taskType: constants.TASK_TYPE.IMAGE_CAPTION.value,
38+
taskUUID: uuid(),
39+
inputImage,
40+
includeCost,
41+
},
42+
],
43+
});
44+
45+
$.export("$summary", `Successfully requested image caption task with UUID \`${response.data[0].taskUUID}\`.`);
46+
return response;
47+
},
48+
};
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import { v4 as uuid } from "uuid";
2+
import app from "../../runware.app.mjs";
3+
import constants from "../../common/constants.mjs";
4+
5+
export default {
6+
key: "runware-image-control-net-preprocess",
7+
name: "Image Control Net Preprocess",
8+
description: "Request an image control net preprocess task to be processed by the Runware API. [See the documentation](https://docs.runware.ai/en/image-editing/controlnet-tools).",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
app,
13+
inputImage: {
14+
propDefinition: [
15+
app,
16+
"inputImage",
17+
],
18+
},
19+
outputType: {
20+
propDefinition: [
21+
app,
22+
"outputType",
23+
],
24+
},
25+
outputFormat: {
26+
propDefinition: [
27+
app,
28+
"outputFormat",
29+
],
30+
},
31+
includeCost: {
32+
propDefinition: [
33+
app,
34+
"includeCost",
35+
],
36+
},
37+
preProcessorType: {
38+
type: "string",
39+
label: "Preprocessor Type",
40+
description: "The preprocessor to be used.",
41+
optional: true,
42+
options: [
43+
"canny",
44+
"depth",
45+
"mlsd",
46+
"normalbae",
47+
"openpose",
48+
"tile",
49+
"seg",
50+
"lineart",
51+
"lineart_anime",
52+
"shuffle",
53+
"scribble",
54+
"softedge",
55+
],
56+
},
57+
height: {
58+
propDefinition: [
59+
app,
60+
"height",
61+
],
62+
},
63+
width: {
64+
propDefinition: [
65+
app,
66+
"width",
67+
],
68+
},
69+
lowThresholdCanny: {
70+
type: "integer",
71+
label: "Low Threshold Canny",
72+
description: "Defines the lower threshold when using the Canny edge detection preprocessor. The recommended value is `100`.",
73+
optional: true,
74+
},
75+
highThresholdCanny: {
76+
type: "integer",
77+
label: "High Threshold Canny",
78+
description: "Defines the high threshold when using the Canny edge detection preprocessor. The recommended value is `200`.",
79+
optional: true,
80+
},
81+
includeHandsAndFaceOpenPose: {
82+
type: "boolean",
83+
label: "Include Hands and Face OpenPose",
84+
description: "Include the hands and face in the pose outline when using the OpenPose preprocessor.",
85+
optional: true,
86+
},
87+
},
88+
async run({ $ }) {
89+
const {
90+
app,
91+
outputType,
92+
outputFormat,
93+
includeCost,
94+
inputImage,
95+
preProcessorType,
96+
height,
97+
width,
98+
lowThresholdCanny,
99+
highThresholdCanny,
100+
includeHandsAndFaceOpenPose,
101+
} = this;
102+
103+
const response = await app.post({
104+
$,
105+
data: [
106+
{
107+
taskType: constants.TASK_TYPE.IMAGE_CONTROL_NET_PREPROCESS.value,
108+
taskUUID: uuid(),
109+
outputType,
110+
outputFormat,
111+
inputImage,
112+
includeCost,
113+
height,
114+
width,
115+
preProcessorType,
116+
lowThresholdCanny,
117+
highThresholdCanny,
118+
includeHandsAndFaceOpenPose,
119+
},
120+
],
121+
});
122+
123+
$.export("$summary", `Successfully requested image control net preprocess task with UUID \`${response.data[0].taskUUID}\`.`);
124+
return response;
125+
},
126+
};

0 commit comments

Comments
 (0)