Skip to content

Commit 29d5c52

Browse files
committed
[ACTION] Break Runware action into individual actions
1 parent cb22999 commit 29d5c52

File tree

10 files changed

+905
-247
lines changed

10 files changed

+905
-247
lines changed
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-background-removal",
7+
name: "Image Background Removal",
8+
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).",
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+
rgba: {
38+
type: "string[]",
39+
label: "RGBA",
40+
description: "An array representing the `[red, green, blue, alpha]` values that define the color of the removed background. The alpha channel controls transparency. Eg. `[255, 255, 255, 0]`.",
41+
optional: true,
42+
},
43+
postProcessMask: {
44+
type: "boolean",
45+
label: "Post-Process Mask",
46+
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.",
47+
optional: true,
48+
},
49+
returnOnlyMask: {
50+
type: "boolean",
51+
label: "Return Only Mask",
52+
description: "Flag indicating whether to return only the mask. The mask is the opposite of the image background removal.",
53+
optional: true,
54+
},
55+
alphaMatting: {
56+
type: "boolean",
57+
label: "Alpha Matting",
58+
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.",
59+
optional: true,
60+
},
61+
alphaMattingForegroundThreshold: {
62+
type: "integer",
63+
label: "Alpha Matting Foreground Threshold",
64+
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`.",
65+
optional: true,
66+
min: 1,
67+
max: 255,
68+
},
69+
alphaMattingBackgroundThreshold: {
70+
type: "integer",
71+
label: "Alpha Matting Background Threshold",
72+
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`.",
73+
optional: true,
74+
min: 1,
75+
max: 255,
76+
},
77+
alphaMattingErodeSize: {
78+
type: "integer",
79+
label: "Alpha Matting Erode Size",
80+
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`.",
81+
optional: true,
82+
min: 1,
83+
max: 255,
84+
},
85+
},
86+
async run({ $ }) {
87+
const {
88+
app,
89+
inputImage,
90+
outputType,
91+
outputFormat,
92+
includeCost,
93+
rgba,
94+
postProcessMask,
95+
returnOnlyMask,
96+
alphaMatting,
97+
alphaMattingForegroundThreshold,
98+
alphaMattingBackgroundThreshold,
99+
alphaMattingErodeSize,
100+
} = this;
101+
102+
const response = await app.post({
103+
$,
104+
data: [
105+
{
106+
taskType: constants.TASK_TYPE.IMAGE_BACKGROUND_REMOVAL.value,
107+
taskUUID: uuid(),
108+
inputImage,
109+
outputType,
110+
outputFormat,
111+
includeCost,
112+
rgba: rgba?.map(parseFloat),
113+
postProcessMask,
114+
returnOnlyMask,
115+
alphaMatting,
116+
alphaMattingForegroundThreshold,
117+
alphaMattingBackgroundThreshold,
118+
alphaMattingErodeSize,
119+
},
120+
],
121+
});
122+
123+
$.export("$summary", `Successfully requested image background removal task with UUID \`${response.data[0].taskUUID}\`.`);
124+
return response;
125+
},
126+
};
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)