Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ACTION] Break Runware action into individual actions #14600

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
},
jcortes marked this conversation as resolved.
Show resolved Hide resolved
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),
jcortes marked this conversation as resolved.
Show resolved Hide resolved
postProcessMask,
returnOnlyMask,
alphaMatting,
alphaMattingForegroundThreshold,
alphaMattingBackgroundThreshold,
alphaMattingErodeSize,
},
],
});

$.export("$summary", `Successfully requested image background removal task with UUID \`${response.data[0].taskUUID}\`.`);
return response;
},
jcortes marked this conversation as resolved.
Show resolved Hide resolved
};
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;
},
jcortes marked this conversation as resolved.
Show resolved Hide resolved
};
jcortes marked this conversation as resolved.
Show resolved Hide resolved
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",
],
},
jcortes marked this conversation as resolved.
Show resolved Hide resolved
jcortes marked this conversation as resolved.
Show resolved Hide resolved
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,
},
jcortes marked this conversation as resolved.
Show resolved Hide resolved
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;
},
jcortes marked this conversation as resolved.
Show resolved Hide resolved
};
Loading
Loading