Support StabilityAi Image Edit Api#1344
Open
inpink wants to merge 1 commit intospring-projects:mainfrom
Open
Conversation
This was referenced Sep 11, 2024
- Add StabilityAiEditApi that implements the Background-Remove endpoint. - Add ITs
83a153f to
bfb0fbc
Compare
Member
|
wow,thanks, getting to the PRs now, a nice addition! will merge soon. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Hello, this PR implements StabilityAi Image Edit - Remove Background API's client.
[The result of the execution]
[Background]
StabilityAI provides various features for editing images via API requests.
Currently, Spring AI supports image generation using text, but lacks functionality for image editing.
This PR adds the StabilitAiEditApi class, which implements the Remove Background API from StabilityAI at the raw level.
The latest version of StabilityAI is V2 Beta, and for the API, please refer to StabilityAi Image Edit - Remove Background API.
[PR contents]
StabilityAiEditApi.RemoveBackgroundRequest recordStabilityAiEditApi.ImageEditHeaders recordStabilityAiEditApi.StructuredResponse record,byte[])removeBackground methodin StabilityAiEditApi ClassStabilityAiEditApiIT Classimagebyte[]output_formatOutputFormat EnumUsers can submit an image as byte[] in formats such as png or webp.
Raw binary image data can be submitted using multipart form data.
An HTTP request is sent using RestClient.
Using
ImageEditHeaders, users can add headers. Headers added at the constructor level are included in the RestClient builder, while those added in the HTTP request sending methodremoveBackgroundare applied only to that specific request.StructuredResponsebyte[]StructuredResponse Classb64ImageStringfinishReasonString- SUCCESS
- CONTENT_FILTERED
seedStringThe response type can be set using the Accept header in the request.
Depending on the requested response type, it returns either a base64-encoded image or raw binary image data.
If a base64-encoded image is requested, the JSON object is mapped to the
StructuredResponseclass. If a raw binary image is requested, it is mapped tobyte[]. Java Generics are used to dynamically determine the response type, which the user specifies in the responseType parameter when calling theremoveBackgroundmethod.Both tests ensure the functionality of the API in handling different response types (byte[] and StructuredResponse) and confirm that the data is processed and returned as expected.
test.png) is submitted inbyte[]format.removeBackground methodbyte[].null.test.png) is submitted with the output formatWEBP.removeBackgroundmethodStructuredResponseclass, containing a base64-encoded image."SUCCESS".WEBPfile for further validation.[Related Issue]
I’m pleased to submit this PR to Spring AI.
Please let me know if any revisions are needed, and I will address them promptly.
I would be happy to assist with future maintenance as well, if necessary.