Skip to content

Commit 18e7669

Browse files
Chipped down Readme, implemented async options in gen motion
1 parent 1d35b09 commit 18e7669

File tree

3 files changed

+88
-86
lines changed

3 files changed

+88
-86
lines changed

components/leonardo_ai/README.md

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -2,91 +2,10 @@
22

33
[Leonardo AI](https://leonardo.ai) is an AI-powered image generation platform that allows you to create stunning images, videos, and 3D models using advanced machine learning models.
44

5-
## Actions
6-
7-
### Generate Image
8-
Creates new images from text prompts using Leonardo AI's image generation models.
9-
10-
**Key Features:**
11-
- Customizable image dimensions (256x256 to 1024x1024)
12-
- Multiple model support
13-
- Adjustable guidance scale and inference steps
14-
- Batch generation (1-4 images)
15-
- Seed support for reproducible results
16-
17-
### Generate Motion
18-
Creates motion videos from static images using Leonardo AI's SVD Motion Generation.
19-
20-
**Key Features:**
21-
- Converts static images to motion videos
22-
- Adjustable motion strength
23-
- Seed support for reproducible results
24-
25-
### Unzoom Image
26-
Creates unzoom variations of existing images, expanding the scene beyond the original frame.
27-
28-
**Key Features:**
29-
- Zoom out effect on existing images
30-
- Adjustable zoom level
31-
- Works with generated or uploaded images
32-
33-
### Upload Image
34-
Uploads images to Leonardo AI for use in generations and variations.
35-
36-
### Upscale Image
37-
Increases the resolution of images using Leonardo AI's Universal Upscaler.
38-
39-
**Key Features:**
40-
- Multiple upscaling modes (Universal Upscaler, Real-ESRGAN)
41-
- 2x and 4x scale factors
42-
- High-quality image enhancement
43-
44-
## Usage Examples
45-
46-
### Basic Image Generation
47-
```javascript
48-
// Generate a simple image
49-
{
50-
"prompt": "A beautiful sunset over mountains",
51-
"width": 512,
52-
"height": 512,
53-
"numImages": 1
54-
}
55-
```
56-
57-
### Advanced Image Generation
58-
```javascript
59-
// Generate with specific model and settings
60-
{
61-
"prompt": "A cyberpunk cityscape at night",
62-
"modelId": "6bef9f1b-29cb-40c7-b9df-32b51c1f67d3",
63-
"width": 1024,
64-
"height": 1024,
65-
"numImages": 2,
66-
"guidanceScale": "10",
67-
"numInferenceSteps": 30,
68-
"seed": 12345
69-
}
70-
```
71-
72-
### Motion Generation
73-
```javascript
74-
// Create motion from an image
75-
{
76-
"imageId": "generated-image-id-here",
77-
"motionStrength": "0.7",
78-
"seed": 54321
79-
}
80-
```
81-
825
## API Reference
836

847
For detailed information about Leonardo AI's API, visit the [official documentation](https://docs.leonardo.ai/reference).
858

86-
## Rate Limits
87-
88-
See the official Leonardo AI documentation for current limits.
89-
909
## Support
9110

9211
For support with this component or Leonardo AI's API, please refer to:

components/leonardo_ai/actions/generate-motion/generate-motion.mjs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,56 @@ export default {
1111
imageId: {
1212
type: "string",
1313
label: "Image ID",
14-
description: "The ID of the image to generate motion from. This should be a previously generated or uploaded image ID.",
14+
description: "The ID of the image to generate motion from. You can either select from previously generated images or manually enter the ID of an uploaded image.",
15+
async options({ prevContext }) {
16+
// Get user info to retrieve userId
17+
const userInfo = await this.app.getUserInfo({
18+
$: this,
19+
});
20+
// Extract userId from the response structure
21+
const userId = userInfo.user_details?.[0]?.user?.id || userInfo.id;
22+
23+
// Get generations with pagination
24+
const offset = prevContext?.offset || 0;
25+
const limit = 20;
26+
27+
const generations = await this.app.getGenerationsByUserId({
28+
$: this,
29+
userId,
30+
offset,
31+
limit,
32+
});
33+
34+
// Extract image IDs from generated_images array
35+
const options = [];
36+
if (generations.generations) {
37+
for (const generation of generations.generations) {
38+
if (generation.generated_images) {
39+
for (const image of generation.generated_images) {
40+
options.push({
41+
label: `Image ${image.id} (Generation ${generation.id})`,
42+
value: image.id,
43+
});
44+
}
45+
}
46+
}
47+
}
48+
49+
// Check if there are more pages
50+
const hasMore = generations.generations && generations.generations.length === limit;
51+
const nextOffset = hasMore
52+
? offset + limit
53+
: null;
54+
55+
return {
56+
options,
57+
context: nextOffset
58+
? {
59+
offset: nextOffset,
60+
}
61+
: {},
62+
};
63+
},
1564
},
1665
motionStrength: {
1766
type: "integer",

components/leonardo_ai/leonardo_ai.app.mjs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,30 @@ export default {
1919
$ = this,
2020
method = "GET",
2121
path,
22+
url, // Allow external URLs (e.g., presigned URLs)
2223
data,
2324
...opts
2425
}) {
2526
const {
2627
headers: userHeaders,
2728
...rest
2829
} = opts;
30+
31+
// Use provided URL or construct from base URL + path
32+
const requestUrl = url || `${this._baseUrl()}${path}`;
33+
34+
// For external URLs (like presigned URLs), don't add default headers
35+
// For internal API calls, add default headers
36+
const defaultHeaders = url
37+
? {}
38+
: this._getHeaders();
39+
2940
const config = {
3041
method,
3142
...rest,
32-
url: `${this._baseUrl()}${path}`,
43+
url: requestUrl,
3344
headers: {
34-
...this._getHeaders(),
45+
...defaultHeaders,
3546
...(userHeaders || {}),
3647
},
3748
data,
@@ -61,8 +72,9 @@ export default {
6172
async uploadFileToPresignedUrl({
6273
$, url, formData,
6374
}) {
64-
const response = await axios($, {
65-
url,
75+
const response = await this._makeRequest({
76+
$,
77+
url, // Use the presigned URL directly
6678
method: "POST",
6779
data: formData,
6880
headers: {
@@ -71,5 +83,27 @@ export default {
7183
});
7284
return response;
7385
},
86+
async getUserInfo({ $ }) {
87+
const data = await this._makeRequest({
88+
$,
89+
method: "GET",
90+
path: "/me",
91+
});
92+
return data;
93+
},
94+
async getGenerationsByUserId({
95+
$, userId, offset = 0, limit = 20,
96+
}) {
97+
const data = await this._makeRequest({
98+
$,
99+
method: "GET",
100+
path: `/generations/user/${userId}`,
101+
params: {
102+
offset,
103+
limit,
104+
},
105+
});
106+
return data;
107+
},
74108
},
75109
};

0 commit comments

Comments
 (0)