Skip to content

Commit

Permalink
[ACTION] Break Runware action into individual actions
Browse files Browse the repository at this point in the history
  • Loading branch information
jcortes committed Nov 7, 2024
1 parent cb22999 commit 29d5c52
Show file tree
Hide file tree
Showing 10 changed files with 905 additions and 247 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { v4 as uuid } from "uuid";
import app from "../../runware.app.mjs";
import constants from "../../common/constants.mjs";

export default {
key: "runware-image-background-removal",
name: "Image Background Removal",
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).",
version: "0.0.1",
type: "action",
props: {
app,
inputImage: {
propDefinition: [
app,
"inputImage",
],
},
outputType: {
propDefinition: [
app,
"outputType",
],
},
outputFormat: {
propDefinition: [
app,
"outputFormat",
],
},
includeCost: {
propDefinition: [
app,
"includeCost",
],
},
rgba: {
type: "string[]",
label: "RGBA",
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]`.",
optional: true,
},
postProcessMask: {
type: "boolean",
label: "Post-Process Mask",
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.",
optional: true,
},
returnOnlyMask: {
type: "boolean",
label: "Return Only Mask",
description: "Flag indicating whether to return only the mask. The mask is the opposite of the image background removal.",
optional: true,
},
alphaMatting: {
type: "boolean",
label: "Alpha Matting",
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.",
optional: true,
},
alphaMattingForegroundThreshold: {
type: "integer",
label: "Alpha Matting Foreground Threshold",
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`.",
optional: true,
min: 1,
max: 255,
},
alphaMattingBackgroundThreshold: {
type: "integer",
label: "Alpha Matting Background Threshold",
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`.",
optional: true,
min: 1,
max: 255,
},
alphaMattingErodeSize: {
type: "integer",
label: "Alpha Matting Erode Size",
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`.",
optional: true,
min: 1,
max: 255,
},
},
async run({ $ }) {
const {
app,
inputImage,
outputType,
outputFormat,
includeCost,
rgba,
postProcessMask,
returnOnlyMask,
alphaMatting,
alphaMattingForegroundThreshold,
alphaMattingBackgroundThreshold,
alphaMattingErodeSize,
} = this;

const response = await app.post({
$,
data: [
{
taskType: constants.TASK_TYPE.IMAGE_BACKGROUND_REMOVAL.value,
taskUUID: uuid(),
inputImage,
outputType,
outputFormat,
includeCost,
rgba: rgba?.map(parseFloat),
postProcessMask,
returnOnlyMask,
alphaMatting,
alphaMattingForegroundThreshold,
alphaMattingBackgroundThreshold,
alphaMattingErodeSize,
},
],
});

$.export("$summary", `Successfully requested image background removal task with UUID \`${response.data[0].taskUUID}\`.`);
return response;
},
};
48 changes: 48 additions & 0 deletions components/runware/actions/image-caption/image-caption.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { v4 as uuid } from "uuid";
import app from "../../runware.app.mjs";
import constants from "../../common/constants.mjs";

export default {
key: "runware-image-caption",
name: "Image Caption",
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).",
version: "0.0.1",
type: "action",
props: {
app,
inputImage: {
propDefinition: [
app,
"inputImage",
],
},
includeCost: {
propDefinition: [
app,
"includeCost",
],
},
},
async run({ $ }) {
const {
app,
inputImage,
includeCost,
} = this;

const response = await app.post({
$,
data: [
{
taskType: constants.TASK_TYPE.IMAGE_CAPTION.value,
taskUUID: uuid(),
inputImage,
includeCost,
},
],
});

$.export("$summary", `Successfully requested image caption task with UUID \`${response.data[0].taskUUID}\`.`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { v4 as uuid } from "uuid";
import app from "../../runware.app.mjs";
import constants from "../../common/constants.mjs";

export default {
key: "runware-image-control-net-preprocess",
name: "Image Control Net Preprocess",
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).",
version: "0.0.1",
type: "action",
props: {
app,
inputImage: {
propDefinition: [
app,
"inputImage",
],
},
outputType: {
propDefinition: [
app,
"outputType",
],
},
outputFormat: {
propDefinition: [
app,
"outputFormat",
],
},
includeCost: {
propDefinition: [
app,
"includeCost",
],
},
preProcessorType: {
type: "string",
label: "Preprocessor Type",
description: "The preprocessor to be used.",
optional: true,
options: [
"canny",
"depth",
"mlsd",
"normalbae",
"openpose",
"tile",
"seg",
"lineart",
"lineart_anime",
"shuffle",
"scribble",
"softedge",
],
},
height: {
propDefinition: [
app,
"height",
],
},
width: {
propDefinition: [
app,
"width",
],
},
lowThresholdCanny: {
type: "integer",
label: "Low Threshold Canny",
description: "Defines the lower threshold when using the Canny edge detection preprocessor. The recommended value is `100`.",
optional: true,
},
highThresholdCanny: {
type: "integer",
label: "High Threshold Canny",
description: "Defines the high threshold when using the Canny edge detection preprocessor. The recommended value is `200`.",
optional: true,
},
includeHandsAndFaceOpenPose: {
type: "boolean",
label: "Include Hands and Face OpenPose",
description: "Include the hands and face in the pose outline when using the OpenPose preprocessor.",
optional: true,
},
},
async run({ $ }) {
const {
app,
outputType,
outputFormat,
includeCost,
inputImage,
preProcessorType,
height,
width,
lowThresholdCanny,
highThresholdCanny,
includeHandsAndFaceOpenPose,
} = this;

const response = await app.post({
$,
data: [
{
taskType: constants.TASK_TYPE.IMAGE_CONTROL_NET_PREPROCESS.value,
taskUUID: uuid(),
outputType,
outputFormat,
inputImage,
includeCost,
height,
width,
preProcessorType,
lowThresholdCanny,
highThresholdCanny,
includeHandsAndFaceOpenPose,
},
],
});

$.export("$summary", `Successfully requested image control net preprocess task with UUID \`${response.data[0].taskUUID}\`.`);
return response;
},
};
Loading

0 comments on commit 29d5c52

Please sign in to comment.