Skip to content
Merged
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
42 changes: 7 additions & 35 deletions Runware/Runware-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1111,23 +1111,9 @@ export class RunwareBase {
* @since 1.2.0
* @returns {Promise<IImage>} If called with `inputs.image` or `inputs.video`, returns an object with `mediaUUID` and `mediaURL`. If called with `inputImage`, returns an object with `imageUUID` and `imageURL` (not guaranteed).
*/
upscaleGan = async ({
inputImage,
inputs,
model,
upscaleFactor,
outputType,
outputFormat,
includeCost,
outputQuality,
customTaskUUID,
taskUUID: _taskUUID,
retry,
includeGenerationTime,
includePayload,
skipResponse,
deliveryMethod,
}: IUpscaleGan): Promise<IImage> => {
upscaleGan = async (payload: IUpscaleGan): Promise<IImage> => {
const { inputImage, skipResponse, deliveryMethod = "sync", ...rest } = payload;

try {
let imageUploaded;

Expand All @@ -1137,35 +1123,21 @@ export class RunwareBase {
imageUploaded = await this.uploadImage(inputImage as File | string);
}

const taskUUID = _taskUUID || customTaskUUID || getUUID();
const payload = {
taskUUID,
inputImage: imageUploaded?.imageUUID,
taskType: ETaskType.UPSCALE,
inputs,
model,
upscaleFactor,
...evaluateNonTrue({ key: "includeCost", value: includeCost }),
...(outputType ? { outputType } : {}),
...(outputQuality ? { outputQuality } : {}),
...(outputFormat ? { outputFormat } : {}),
includePayload,
includeGenerationTime,
retry,
deliveryMethod,
};

const request = await this.baseSingleRequest<IImage>({
payload: {
...payload,
...rest,
...(imageUploaded?.imageUUID ? { inputImage: imageUploaded.imageUUID } : {}),
taskType: ETaskType.UPSCALE,
deliveryMethod,
},
debugKey: "upscale",
});

if (skipResponse) {
return request;
}


if (deliveryMethod === "async") {
const taskUUID = request?.taskUUID;
Expand Down
4 changes: 3 additions & 1 deletion Runware/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ export interface IEnhancedPrompt extends IImageToText {}

export interface IUpscaleGan extends IAdditionalResponsePayload {
inputImage?: File | string;
upscaleFactor: number;
upscaleFactor?: number;
outputType?: IOutputType;
outputFormat?: IOutputFormat | "MP4" | "WEBM" | "MOV";
includeCost?: boolean;
Expand All @@ -531,6 +531,8 @@ export interface IUpscaleGan extends IAdditionalResponsePayload {

skipResponse?: boolean;
deliveryMethod?: string;

[key: string]: any;
}

export type ReconnectingWebsocketProps = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@runware/sdk-js",
"version": "1.2.5",
"version": "1.2.6",
"description": "The SDK is used to run image inference with the Runware API, powered by the RunWare inference platform. It can be used to generate imaged with text-to-image and image-to-image. It also allows the use of an existing gallery of models or selecting any model or LoRA from the CivitAI gallery. The API also supports upscaling, background removal, inpainting and outpainting, and a series of other ControlNet models.",
"main": "dist/index.js",
"module": "dist/index.js",
Expand Down
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,11 @@ export type TImageMaskingResponse = {

## Changelog

### - v1.2.6

- Update upscale() to accept open-ended payload


### - v1.2.5

- Fix JS SDK error race condition
Expand Down
21 changes: 6 additions & 15 deletions tests/Runware/remove-image-background.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import {
expect,
test,
beforeAll,
vi,
describe,
afterEach,
beforeEach,
} from "vitest";
import { mockTaskUUID, mockUploadFile, testExamples } from "../test-utils";
import { mockTaskUUID, mockUploadFile } from "../test-utils";
import { startMockServer } from "../mockServer";
import { ETaskType } from "../../Runware";

Expand All @@ -32,23 +31,15 @@ describe("When user request to remove image background", async () => {
mockServer.stop();
});

beforeAll(async () => {
vi.spyOn(runware as any, "uploadImage").mockReturnValue(
testExamples.imageUploadRes
);
});

test("it should remove an image background", async () => {
const imageUploadSpy = vi.spyOn(runware as any, "uploadImage");
const globalListenerSpy = vi.spyOn(runware as any, "globalListener");
const sendSpy = vi.spyOn(runware as any, "send");

await runware.removeImageBackground({ inputImage: mockUploadFile });

expect(imageUploadSpy).toHaveBeenCalled();
await runware.removeImageBackground({ inputImage: mockUploadFile, model: "runware:110@1" });

expect(sendSpy).toHaveBeenCalledWith({
inputImage: testExamples.imageUploadRes.imageUUID,
inputImage: mockUploadFile,
model: "runware:110@1",
taskUUID: mockTaskUUID,
taskType: ETaskType.REMOVE_BACKGROUND,
});
Expand All @@ -58,7 +49,7 @@ describe("When user request to remove image background", async () => {
});

test("removeBackground delegates to removeImageBackground", async () => {
const result = await runware.removeBackground({ inputImage: mockUploadFile });
expect(result).toEqual(await runware.removeImageBackground({ inputImage: mockUploadFile }));
const result = await runware.removeBackground({ inputImage: mockUploadFile, model: "runware:110@1" });
expect(result).toEqual(await runware.removeImageBackground({ inputImage: mockUploadFile, model: "runware:110@1" }));
});
});
1 change: 1 addition & 0 deletions tests/Runware/upscale-gan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ describe("When user request to upscale gan", async () => {
taskUUID: mockTaskUUID,
upscaleFactor: 2,
taskType: ETaskType.UPSCALE,
deliveryMethod: "sync",
});
expect(globalListenerSpy).toHaveBeenCalledWith({
taskUUID: mockTaskUUID,
Expand Down
Loading