-
Notifications
You must be signed in to change notification settings - Fork 5.6k
[ACTION] Break Runware action into individual actions #14600
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
Merged
jcortes
merged 1 commit into
PipedreamHQ:master
from
jcortes:runware-individual-actions-endpoint
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
141 changes: 141 additions & 0 deletions
141
components/runware/actions/image-background-removal/image-background-removal.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
| import { v4 as uuid } from "uuid"; | ||
| import app from "../../runware.app.mjs"; | ||
| import constants from "../../common/constants.mjs"; | ||
| import utils from "../../common/utils.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", | ||
| ], | ||
| }, | ||
| rgb: { | ||
| type: "string[]", | ||
| label: "RGB", | ||
| description: "An array representing the `[red, green, blue]` values that define the color of the removed background. Eg. `[255, 255, 255]`.", | ||
| 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, | ||
| }, | ||
| }, | ||
| methods: { | ||
| getRGBA(rgb, alpha = 0) { | ||
| if (rgb) { | ||
| const parsed = utils.parseArray(rgb).map((value) => parseInt(value, 10)); | ||
| return parsed.concat(alpha); | ||
| } | ||
| }, | ||
| }, | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| async run({ $ }) { | ||
| const { | ||
| app, | ||
| getRGBA, | ||
| inputImage, | ||
| outputType, | ||
| outputFormat, | ||
| includeCost, | ||
| rgb, | ||
| postProcessMask, | ||
| returnOnlyMask, | ||
| alphaMatting, | ||
| alphaMattingForegroundThreshold, | ||
| alphaMattingBackgroundThreshold, | ||
| alphaMattingErodeSize, | ||
| } = this; | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (rgb && utils.parseArray(rgb).length !== 3) { | ||
| throw new ConfigurationError("The **RGB** array must contain exactly 3 integer numbers. Eg. `[255, 255, 255]`."); | ||
| } | ||
|
|
||
| const response = await app.post({ | ||
| $, | ||
| data: [ | ||
| { | ||
| taskType: constants.TASK_TYPE.IMAGE_BACKGROUND_REMOVAL.value, | ||
| taskUUID: uuid(), | ||
| inputImage, | ||
| outputType, | ||
| outputFormat, | ||
| includeCost, | ||
| rgba: getRGBA(rgb), | ||
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; | ||
| }, | ||
| }; | ||
48 changes: 48 additions & 0 deletions
48
components/runware/actions/image-caption/image-caption.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
|
||
126 changes: 126 additions & 0 deletions
126
components/runware/actions/image-control-net-preprocess/image-control-net-preprocess.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
|
||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.