-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - deepimage #14352
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
Merged
New Components - deepimage #14352
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
30 changes: 30 additions & 0 deletions
30
components/deepimage/actions/auto-enhance/auto-enhance.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,30 @@ | ||
| import { getUrlOrFile } from "../../common/utils.mjs"; | ||
| import deepimage from "../../deepimage.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "deepimage-auto-enhance", | ||
| name: "Auto Enhance Image", | ||
| description: "Improves the provided image. [See the documentation](https://documentation.deep-image.ai/image-processing/auto-enhance)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| deepimage, | ||
| image: { | ||
| propDefinition: [ | ||
| deepimage, | ||
| "image", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.deepimage.makeRequest({ | ||
| data: { | ||
| url: getUrlOrFile(this.image), | ||
| preset: "auto_enhance", | ||
| }, | ||
| }); | ||
|
|
||
| $.export("$summary", "Successfully enhanced the image."); | ||
| return response; | ||
| }, | ||
| }; |
55 changes: 55 additions & 0 deletions
55
components/deepimage/actions/remove-background/remove-background.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,55 @@ | ||
| import { | ||
| BACKGROUND_COLOR_OPTIONS, CROP_TYPE_OPTIONS, | ||
| } from "../../common/constants.mjs"; | ||
| import { getUrlOrFile } from "../../common/utils.mjs"; | ||
| import deepimage from "../../deepimage.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "deepimage-remove-background", | ||
| name: "Remove Background", | ||
| description: "Removes the background from the provided image using DeepImage. [See the documentation](https://documentation.deep-image.ai/image-processing/background-processing)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| deepimage, | ||
| image: { | ||
| propDefinition: [ | ||
| deepimage, | ||
| "image", | ||
| ], | ||
| }, | ||
| backgroundColor: { | ||
| type: "string", | ||
| label: "Background Color", | ||
| description: "The background color for the image.", | ||
| options: BACKGROUND_COLOR_OPTIONS, | ||
| }, | ||
| cropType: { | ||
| type: "string", | ||
| label: "Crop Type", | ||
| description: "The crop type for background removal.", | ||
| optional: true, | ||
| options: CROP_TYPE_OPTIONS, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.deepimage.makeRequest({ | ||
| $, | ||
| data: { | ||
| url: getUrlOrFile(this.image), | ||
| background: { | ||
| remove: "auto", | ||
| color: this.backgroundColor, | ||
| }, | ||
| fit: this.cropType | ||
| ? { | ||
| crop: this.cropType, | ||
| } | ||
| : {}, | ||
| }, | ||
| }); | ||
|
|
||
| $.export("$summary", "Background removal successful"); | ||
| return response; | ||
| }, | ||
| }; |
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,44 @@ | ||
| import { getUrlOrFile } from "../../common/utils.mjs"; | ||
| import deepimage from "../../deepimage.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "deepimage-upscale", | ||
| name: "Upscale Image", | ||
| description: "Upscales the provided image using Deep Image. [See the documentation](https://documentation.deep-image.ai/image-processing/resize-and-padding)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| deepimage, | ||
| image: { | ||
| propDefinition: [ | ||
| deepimage, | ||
| "image", | ||
| ], | ||
| }, | ||
| upscaleMultiplier: { | ||
| type: "integer", | ||
| label: "Upscale Multiplier", | ||
| description: "The factor by which to upscale the image in %.", | ||
| }, | ||
| generativeUpscale: { | ||
| type: "boolean", | ||
| label: "Generative Upscale", | ||
| description: "Whether to use generative upscale.", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.deepimage.makeRequest({ | ||
| $, | ||
| data: { | ||
| url: getUrlOrFile(this.image), | ||
| width: `${this.upscaleMultiplier}%`, | ||
| height: `${this.upscaleMultiplier}%`, | ||
| generative_upscale: this.generativeUpscale, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| $.export("$summary", "Successfully upscaled the image"); | ||
| return response; | ||
| }, | ||
| }; | ||
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,37 @@ | ||
| export const BACKGROUND_COLOR_OPTIONS = [ | ||
| { | ||
| label: "White", | ||
| value: "#FFFFFF", | ||
| }, | ||
| { | ||
| label: "Transparent", | ||
| value: "transparent", | ||
| }, | ||
| ]; | ||
|
|
||
| export const CROP_TYPE_OPTIONS = [ | ||
| { | ||
| label: "Crop center", | ||
| value: "center", | ||
| }, | ||
| { | ||
| label: "Crop item", | ||
| value: "item", | ||
| }, | ||
| { | ||
| label: "Crop content", | ||
| value: "content", | ||
| }, | ||
| { | ||
| label: "Cover", | ||
| value: "cover", | ||
| }, | ||
| { | ||
| label: "Canvas", | ||
| value: "canvas", | ||
| }, | ||
| { | ||
| label: "Bounds", | ||
| value: "bounds", | ||
| }, | ||
| ]; |
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,27 @@ | ||
| import fs from "fs"; | ||
|
|
||
| export const isValidUrl = (urlString) => { | ||
| var urlPattern = new RegExp("^(https?:\\/\\/)?" + // validate protocol | ||
| "((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|" + // validate domain name | ||
| "((\\d{1,3}\\.){3}\\d{1,3}))" + // validate OR ip (v4) address | ||
| "(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*" + // validate port and path | ||
| "(\\?[;&a-z\\d%_.~+=-]*)?" + // validate query string | ||
| "(\\#[-a-z\\d_]*)?$", "i"); // validate fragment locator | ||
| return !!urlPattern.test(urlString); | ||
| }; | ||
|
|
||
| export const checkTmp = (filename) => { | ||
| if (filename.indexOf("/tmp") === -1) { | ||
| return `/tmp/${filename}`; | ||
| } | ||
| return filename; | ||
| }; | ||
|
|
||
| export const getUrlOrFile = (url) => { | ||
| if (!isValidUrl(url)) { | ||
| const data = fs.readFileSync(checkTmp(url)); | ||
| const base64Image = Buffer.from(data, "binary").toString("base64"); | ||
| return `base64,${base64Image}`; | ||
| } | ||
| return url; | ||
| }; | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 |
|---|---|---|
| @@ -1,11 +1,34 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "deepimage", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| image: { | ||
| type: "string", | ||
| label: "Image", | ||
| description: "The URL of the image or the path to the file saved to the `/tmp` directory (e.g. `/tmp/example.jpg`) to process. [See the documentation](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory).", | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return "https://deep-image.ai/rest_api/process_result"; | ||
| }, | ||
| _headers() { | ||
| return { | ||
| "content-type": "application/json", | ||
| "x-api-key": `${this.$auth.api_key}`, | ||
| }; | ||
| }, | ||
| makeRequest({ | ||
| $ = this, ...opts | ||
| }) { | ||
| return axios($, { | ||
| method: "POST", | ||
| url: this._baseUrl(), | ||
| headers: this._headers(), | ||
| ...opts, | ||
| }); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }, | ||
| }; | ||
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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@pipedream/deepimage", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream DeepImage Components", | ||
| "main": "deepimage.app.mjs", | ||
| "keywords": [ | ||
|
|
@@ -11,5 +11,9 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.0.3", | ||
| "fs": "^0.0.1-security" | ||
michelle0927 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.