@dataclouder/nest-vertex 0.0.25 → 0.0.27
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/comfyui/controllers/comfy-ui.controller.js +5 -14
- package/comfyui/dto/video-generation.dto.d.ts +6 -0
- package/comfyui/dto/video-generation.dto.js +11 -0
- package/comfyui/services/comfy-connection.service.js +14 -14
- package/comfyui/services/comfy-video.service.d.ts +5 -0
- package/comfyui/services/comfy-video.service.js +24 -0
- package/models/generated-asset.entity.d.ts +1 -0
- package/models/generated-asset.entity.js +5 -0
- package/models/generated-asset.model.d.ts +1 -0
- package/package.json +1 -1
|
@@ -104,20 +104,11 @@ let ComfyUiController = ComfyUiController_1 = class ComfyUiController {
|
|
|
104
104
|
const newAsset = await this.generatedAssetService.save({
|
|
105
105
|
assets: { firstFrame: { url } },
|
|
106
106
|
});
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const response = await this.httpService.axiosRef.get(imageUrl, { responseType: 'arraybuffer' });
|
|
113
|
-
const imageBuffer = Buffer.from(response.data, 'binary');
|
|
114
|
-
const videoRequest = {
|
|
115
|
-
workflowPath: path.resolve('./comfy_workflows/video-15_seconds.json'),
|
|
116
|
-
inputImage: imageBuffer,
|
|
117
|
-
positivePrompt: positivePrompt || 'Faces are smiling',
|
|
118
|
-
negativePrompt: negativePrompt || 'low quality, blurry, static',
|
|
119
|
-
};
|
|
120
|
-
const videoResponse = await this.comfyVideoService.runVideoGenerationFromWorkflow(videoRequest, newAsset.id);
|
|
107
|
+
const videoResponse = await this.comfyVideoService.runVideoGenerationForAssetId({
|
|
108
|
+
assetId: newAsset.id,
|
|
109
|
+
positivePrompt,
|
|
110
|
+
negativePrompt,
|
|
111
|
+
});
|
|
121
112
|
this.logger.log(`ComfyUI video generation started. Response: ${JSON.stringify(videoResponse)}`);
|
|
122
113
|
return videoResponse;
|
|
123
114
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RunVideoGenerationForAssetIdDto = void 0;
|
|
4
|
+
class RunVideoGenerationForAssetIdDto {
|
|
5
|
+
assetId;
|
|
6
|
+
positivePrompt;
|
|
7
|
+
negativePrompt;
|
|
8
|
+
metadata;
|
|
9
|
+
}
|
|
10
|
+
exports.RunVideoGenerationForAssetIdDto = RunVideoGenerationForAssetIdDto;
|
|
11
|
+
//# sourceMappingURL=video-generation.dto.js.map
|
|
@@ -122,8 +122,8 @@ let ComfyConnectionService = ComfyConnectionService_1 = class ComfyConnectionSer
|
|
|
122
122
|
this.logger.log(`Resolved pending promise for prompt ${prompt_id}.`);
|
|
123
123
|
return;
|
|
124
124
|
}
|
|
125
|
-
const
|
|
126
|
-
if (!
|
|
125
|
+
const generatedAsset = await this.generatedAssetService.findOneByOperationId(prompt_id);
|
|
126
|
+
if (!generatedAsset) {
|
|
127
127
|
this.logger.warn(`No asset found for prompt_id: ${prompt_id}`);
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
@@ -136,26 +136,26 @@ let ComfyConnectionService = ComfyConnectionService_1 = class ComfyConnectionSer
|
|
|
136
136
|
videoFilename = video.filename;
|
|
137
137
|
this.logger.log(`Found video output: ${videoFilename}`);
|
|
138
138
|
if (videoBuffer) {
|
|
139
|
-
const uploadResult = await this.cloudStorageService.uploadFileAndMakePublic(process.env.STORAGE_BUCKET, `generated-videos/${
|
|
139
|
+
const uploadResult = await this.cloudStorageService.uploadFileAndMakePublic(process.env.STORAGE_BUCKET, `generated-videos/${generatedAsset.id}.mp4`, videoBuffer, 'video/mp4');
|
|
140
140
|
this.logger.log(`Successfully uploaded video to: ${uploadResult.url}`);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
await this.generatedAssetService.update(
|
|
145
|
-
this.eventEmitter.emit('asset.updated',
|
|
141
|
+
generatedAsset.url = uploadResult.url;
|
|
142
|
+
generatedAsset.result = uploadResult;
|
|
143
|
+
generatedAsset.status = 'completed';
|
|
144
|
+
await this.generatedAssetService.update(generatedAsset.id, generatedAsset);
|
|
145
|
+
this.eventEmitter.emit('asset.updated', generatedAsset);
|
|
146
146
|
}
|
|
147
147
|
else {
|
|
148
148
|
this.logger.error(`No video found in the output for prompt ${prompt_id}.`);
|
|
149
|
-
|
|
150
|
-
await this.generatedAssetService.update(
|
|
151
|
-
this.eventEmitter.emit('asset.updated',
|
|
149
|
+
generatedAsset.status = 'failed';
|
|
150
|
+
await this.generatedAssetService.update(generatedAsset.id, generatedAsset);
|
|
151
|
+
this.eventEmitter.emit('asset.updated', generatedAsset);
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
catch (error) {
|
|
155
155
|
this.logger.error(`Failed to process output for prompt ${prompt_id}:`, error);
|
|
156
|
-
|
|
157
|
-
await this.generatedAssetService.update(
|
|
158
|
-
this.eventEmitter.emit('asset.updated',
|
|
156
|
+
generatedAsset.status = 'failed';
|
|
157
|
+
await this.generatedAssetService.update(generatedAsset.id, generatedAsset);
|
|
158
|
+
this.eventEmitter.emit('asset.updated', generatedAsset);
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
getClient() {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RunVideoGenerationForAssetIdDto } from '../dto/video-generation.dto';
|
|
1
2
|
import { ComfyConnectionService } from './comfy-connection.service';
|
|
2
3
|
import { VideoGenRequest } from '../models/comfy.models';
|
|
3
4
|
import { HttpService } from '@nestjs/axios';
|
|
@@ -15,4 +16,8 @@ export declare class ComfyVideoService {
|
|
|
15
16
|
message: string;
|
|
16
17
|
asset: GeneratedAsset;
|
|
17
18
|
}>;
|
|
19
|
+
runVideoGenerationForAssetId({ assetId, positivePrompt, negativePrompt, metadata, }: RunVideoGenerationForAssetIdDto): Promise<{
|
|
20
|
+
message: string;
|
|
21
|
+
asset: GeneratedAsset;
|
|
22
|
+
}>;
|
|
18
23
|
}
|
|
@@ -13,6 +13,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
13
13
|
exports.ComfyVideoService = void 0;
|
|
14
14
|
const common_1 = require("@nestjs/common");
|
|
15
15
|
const fs = require("fs/promises");
|
|
16
|
+
const path = require("path");
|
|
16
17
|
const comfy_connection_service_1 = require("./comfy-connection.service");
|
|
17
18
|
const axios_1 = require("@nestjs/axios");
|
|
18
19
|
const generated_asset_service_1 = require("../../services/generated-asset.service");
|
|
@@ -80,6 +81,29 @@ let ComfyVideoService = ComfyVideoService_1 = class ComfyVideoService {
|
|
|
80
81
|
throw new common_1.InternalServerErrorException(`Failed to run video generation workflow: ${error.message}`);
|
|
81
82
|
}
|
|
82
83
|
}
|
|
84
|
+
async runVideoGenerationForAssetId({ assetId, positivePrompt, negativePrompt, metadata, }) {
|
|
85
|
+
this.logger.log(`Starting video generation for asset id: ${assetId}`);
|
|
86
|
+
const asset = await this.generatedAssetService.findOne(assetId);
|
|
87
|
+
if (!asset || !asset.assets?.firstFrame?.url) {
|
|
88
|
+
console.log('No puede generar video si no hay una imagen...');
|
|
89
|
+
throw new common_1.NotFoundException(`Asset with id ${assetId} not found or does not have a valid image url.`);
|
|
90
|
+
}
|
|
91
|
+
if (metadata) {
|
|
92
|
+
asset.metadata = metadata;
|
|
93
|
+
console.log('actualizando asset con metadata', metadata);
|
|
94
|
+
await this.generatedAssetService.partialUpdate(asset.id, { metadata });
|
|
95
|
+
}
|
|
96
|
+
const imageUrl = asset.assets.firstFrame.url;
|
|
97
|
+
const response = await this.httpService.axiosRef.get(imageUrl, { responseType: 'arraybuffer' });
|
|
98
|
+
const imageBuffer = Buffer.from(response.data, 'binary');
|
|
99
|
+
const videoRequest = {
|
|
100
|
+
workflowPath: path.resolve('./comfy_workflows/video-15_seconds.json'),
|
|
101
|
+
inputImage: imageBuffer,
|
|
102
|
+
positivePrompt: positivePrompt || 'Faces are smiling',
|
|
103
|
+
negativePrompt: negativePrompt || 'low quality, blurry, static',
|
|
104
|
+
};
|
|
105
|
+
return this.runVideoGenerationFromWorkflow(videoRequest, assetId);
|
|
106
|
+
}
|
|
83
107
|
};
|
|
84
108
|
exports.ComfyVideoService = ComfyVideoService;
|
|
85
109
|
exports.ComfyVideoService = ComfyVideoService = ComfyVideoService_1 = __decorate([
|
|
@@ -19,6 +19,7 @@ export declare class GeneratedAsset implements IGeneratedAsset {
|
|
|
19
19
|
result: CloudFileStorage;
|
|
20
20
|
name: string;
|
|
21
21
|
description: string;
|
|
22
|
+
metadata: any;
|
|
22
23
|
}
|
|
23
24
|
export declare const GeneratedAssetSchema: import("mongoose").Schema<GeneratedAsset, import("mongoose").Model<GeneratedAsset, any, any, any, Document<unknown, any, GeneratedAsset, any> & GeneratedAsset & Required<{
|
|
24
25
|
_id: string;
|
|
@@ -29,6 +29,7 @@ let GeneratedAsset = class GeneratedAsset {
|
|
|
29
29
|
result;
|
|
30
30
|
name;
|
|
31
31
|
description;
|
|
32
|
+
metadata;
|
|
32
33
|
};
|
|
33
34
|
exports.GeneratedAsset = GeneratedAsset;
|
|
34
35
|
__decorate([
|
|
@@ -91,6 +92,10 @@ __decorate([
|
|
|
91
92
|
(0, mongoose_1.Prop)({ required: false }),
|
|
92
93
|
__metadata("design:type", String)
|
|
93
94
|
], GeneratedAsset.prototype, "description", void 0);
|
|
95
|
+
__decorate([
|
|
96
|
+
(0, mongoose_1.Prop)({ required: false, type: Object }),
|
|
97
|
+
__metadata("design:type", Object)
|
|
98
|
+
], GeneratedAsset.prototype, "metadata", void 0);
|
|
94
99
|
exports.GeneratedAsset = GeneratedAsset = __decorate([
|
|
95
100
|
(0, mongoose_1.Schema)({ collection: 'generated_assets' })
|
|
96
101
|
], GeneratedAsset);
|