@rohitaryal/whisk-api 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/Project.d.ts +7 -0
- package/dist/Project.js +88 -0
- package/dist/Whisk.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -191,7 +191,7 @@ Options:
|
|
|
191
191
|
video.save("./videos");
|
|
192
192
|
```
|
|
193
193
|
|
|
194
|
-
More examples are at: [/examples](https://github.com/rohitaryal/
|
|
194
|
+
More examples are at: [/examples](https://github.com/rohitaryal/whisk-api/tree/main/examples)
|
|
195
195
|
</details>
|
|
196
196
|
|
|
197
197
|
## Help
|
package/dist/Project.d.ts
CHANGED
|
@@ -4,8 +4,15 @@ import { Account } from "./Whisk.js";
|
|
|
4
4
|
export declare class Project {
|
|
5
5
|
readonly account: Account;
|
|
6
6
|
readonly projectId: string;
|
|
7
|
+
readonly subjects: Media[];
|
|
8
|
+
readonly scenes: Media[];
|
|
9
|
+
readonly styles: Media[];
|
|
7
10
|
constructor(projectId: string, account: Account);
|
|
8
11
|
generateImage(input: string | PromptConfig): Promise<Media>;
|
|
12
|
+
/**
|
|
13
|
+
* Generate image but with subject, scene, style attached
|
|
14
|
+
*/
|
|
15
|
+
generateImageWithReferences(input: string | PromptConfig): Promise<Media>;
|
|
9
16
|
/**
|
|
10
17
|
* Deletes the project, clearance of your slop from the existance
|
|
11
18
|
*/
|
package/dist/Project.js
CHANGED
|
@@ -5,6 +5,9 @@ import { Account } from "./Whisk.js";
|
|
|
5
5
|
export class Project {
|
|
6
6
|
account;
|
|
7
7
|
projectId;
|
|
8
|
+
subjects;
|
|
9
|
+
scenes;
|
|
10
|
+
styles;
|
|
8
11
|
constructor(projectId, account) {
|
|
9
12
|
if (typeof projectId !== "string" || !projectId.trim()) {
|
|
10
13
|
throw new Error("project id is either invalid or missing");
|
|
@@ -14,6 +17,9 @@ export class Project {
|
|
|
14
17
|
}
|
|
15
18
|
this.projectId = projectId;
|
|
16
19
|
this.account = account;
|
|
20
|
+
this.subjects = [];
|
|
21
|
+
this.scenes = [];
|
|
22
|
+
this.styles = [];
|
|
17
23
|
}
|
|
18
24
|
async generateImage(input) {
|
|
19
25
|
if (typeof input === "string") {
|
|
@@ -63,6 +69,88 @@ export class Project {
|
|
|
63
69
|
account: this.account
|
|
64
70
|
});
|
|
65
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Generate image but with subject, scene, style attached
|
|
74
|
+
*/
|
|
75
|
+
async generateImageWithReferences(input) {
|
|
76
|
+
if (typeof input === "string") {
|
|
77
|
+
input = {
|
|
78
|
+
seed: 0,
|
|
79
|
+
prompt: input,
|
|
80
|
+
model: "IMAGEN_3_5",
|
|
81
|
+
aspectRatio: "IMAGE_ASPECT_RATIO_LANDSCAPE"
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (!input.seed)
|
|
85
|
+
input.seed = 0;
|
|
86
|
+
if (!input.model)
|
|
87
|
+
input.model = "IMAGEN_3_5";
|
|
88
|
+
if (!input.aspectRatio)
|
|
89
|
+
input.aspectRatio = "IMAGE_ASPECT_RATIO_LANDSCAPE";
|
|
90
|
+
if (!input.prompt?.trim?.())
|
|
91
|
+
throw new Error("prompt is required");
|
|
92
|
+
// Check if the model selected is for image generation
|
|
93
|
+
if (!Object.values(ImageGenerationModel).includes(input.model)) {
|
|
94
|
+
throw new Error(`'${input.model}': invalid image generation model provided`);
|
|
95
|
+
}
|
|
96
|
+
const generationResponse = await request("https://aisandbox-pa.googleapis.com/v1/whisk:runImageRecipe", {
|
|
97
|
+
headers: { authorization: `Bearer ${await this.account.getToken()}` },
|
|
98
|
+
body: JSON.stringify({
|
|
99
|
+
"clientContext": {
|
|
100
|
+
"workflowId": this.projectId,
|
|
101
|
+
"tool": "BACKBONE",
|
|
102
|
+
},
|
|
103
|
+
"seed": input.seed,
|
|
104
|
+
"imageModelSettings": {
|
|
105
|
+
"imageModel": "GEM_PIX", // TODO: Lets experiment with this for now
|
|
106
|
+
"aspectRatio": input.aspectRatio
|
|
107
|
+
},
|
|
108
|
+
"userInstruction": input.prompt,
|
|
109
|
+
// Attach during image generation
|
|
110
|
+
"recipeMediaInputs": [
|
|
111
|
+
...this.subjects.map(item => {
|
|
112
|
+
return {
|
|
113
|
+
"caption": item.prompt,
|
|
114
|
+
"mediaInput": {
|
|
115
|
+
"mediaCategory": "MEDIA_CATEGORY_SUBJECT",
|
|
116
|
+
"mediaGenerationId": item.mediaGenerationId
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}),
|
|
120
|
+
...this.scenes.map(item => {
|
|
121
|
+
return {
|
|
122
|
+
"caption": item.prompt,
|
|
123
|
+
"mediaInput": {
|
|
124
|
+
"mediaCategory": "MEDIA_CATEGORY_SCENE",
|
|
125
|
+
"mediaGenerationId": item.mediaGenerationId
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}),
|
|
129
|
+
...this.styles.map(item => {
|
|
130
|
+
return {
|
|
131
|
+
"caption": item.prompt,
|
|
132
|
+
"mediaInput": {
|
|
133
|
+
"mediaCategory": "MEDIA_CATEGORY_STYLE",
|
|
134
|
+
"mediaGenerationId": item.mediaGenerationId
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
})
|
|
138
|
+
]
|
|
139
|
+
})
|
|
140
|
+
});
|
|
141
|
+
const img = generationResponse.imagePanels[0].generatedImages[0];
|
|
142
|
+
return new Media({
|
|
143
|
+
seed: img.seed,
|
|
144
|
+
prompt: img.prompt,
|
|
145
|
+
workflowId: img.workflowId ?? generationResponse.workflowId,
|
|
146
|
+
encodedMedia: img.encodedImage,
|
|
147
|
+
mediaGenerationId: img.mediaGenerationId,
|
|
148
|
+
aspectRatio: img.aspectRatio,
|
|
149
|
+
mediaType: "IMAGE",
|
|
150
|
+
model: img.imageModel,
|
|
151
|
+
account: this.account
|
|
152
|
+
});
|
|
153
|
+
}
|
|
66
154
|
/**
|
|
67
155
|
* Deletes the project, clearance of your slop from the existance
|
|
68
156
|
*/
|
package/dist/Whisk.d.ts
CHANGED
|
@@ -48,5 +48,5 @@ export declare class Whisk {
|
|
|
48
48
|
* Uses imagefx's api to generate image.
|
|
49
49
|
* Advantage here is it can generate multiple images in single request
|
|
50
50
|
*/
|
|
51
|
-
generateImage(input: string | PromptConfig, count?: number): Promise<Media>;
|
|
51
|
+
generateImage(input: string | PromptConfig, count?: number): Promise<Media[]>;
|
|
52
52
|
}
|