mulmocast 0.0.1 → 0.0.3
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 +129 -15
- package/assets/font/NotoSansJP-Regular.ttf +0 -0
- package/assets/html/chart.html +38 -0
- package/assets/html/mermaid.html +51 -0
- package/assets/templates/business.json +57 -14
- package/assets/templates/children_book.json +1 -3
- package/assets/templates/coding.json +140 -0
- package/lib/actions/audio.d.ts +2 -2
- package/lib/actions/audio.js +88 -101
- package/lib/actions/images.d.ts +1 -1
- package/lib/actions/images.js +50 -88
- package/lib/actions/index.d.ts +5 -0
- package/lib/actions/index.js +5 -0
- package/lib/actions/movie.d.ts +9 -1
- package/lib/actions/movie.js +124 -65
- package/lib/actions/pdf.d.ts +2 -0
- package/lib/actions/pdf.js +211 -0
- package/lib/actions/pdf2.d.ts +2 -0
- package/lib/actions/pdf2.js +203 -0
- package/lib/actions/translate.d.ts +1 -1
- package/lib/actions/translate.js +38 -61
- package/lib/agents/add_bgm_agent.d.ts +1 -1
- package/lib/agents/add_bgm_agent.js +10 -14
- package/lib/agents/anthropic_agent.d.ts +23 -0
- package/lib/agents/anthropic_agent.js +162 -0
- package/lib/agents/combine_audio_files_agent.d.ts +1 -1
- package/lib/agents/combine_audio_files_agent.js +33 -32
- package/lib/agents/image_google_agent.d.ts +1 -1
- package/lib/agents/image_google_agent.js +8 -11
- package/lib/agents/image_openai_agent.js +7 -14
- package/lib/agents/index.d.ts +8 -8
- package/lib/agents/index.js +13 -30
- package/lib/agents/mulmo_prompts_agent.d.ts +1 -1
- package/lib/agents/mulmo_prompts_agent.js +7 -11
- package/lib/agents/nested_agent.d.ts +9 -0
- package/lib/agents/nested_agent.js +138 -0
- package/lib/agents/prompts_data.js +1 -4
- package/lib/agents/tts_nijivoice_agent.d.ts +1 -1
- package/lib/agents/tts_nijivoice_agent.js +8 -12
- package/lib/agents/tts_openai_agent.js +9 -16
- package/lib/agents/validate_mulmo_script_agent.d.ts +1 -1
- package/lib/agents/validate_mulmo_script_agent.js +6 -10
- package/lib/cli/args.d.ts +5 -2
- package/lib/cli/args.js +52 -35
- package/lib/cli/cli.d.ts +14 -0
- package/lib/cli/cli.js +74 -57
- package/lib/cli/common.js +1 -5
- package/lib/cli/tool-args.d.ts +4 -1
- package/lib/cli/tool-args.js +29 -18
- package/lib/cli/tool-cli.js +34 -51
- package/lib/methods/index.d.ts +4 -3
- package/lib/methods/index.js +4 -19
- package/lib/methods/mulmo_media_source.d.ts +4 -0
- package/lib/methods/mulmo_media_source.js +21 -0
- package/lib/methods/mulmo_script.d.ts +6 -5
- package/lib/methods/mulmo_script.js +29 -16
- package/lib/methods/mulmo_script_template.d.ts +1 -1
- package/lib/methods/mulmo_script_template.js +4 -10
- package/lib/methods/mulmo_studio_context.d.ts +1 -1
- package/lib/methods/mulmo_studio_context.js +3 -9
- package/lib/tools/create_mulmo_script_from_url.d.ts +3 -0
- package/lib/tools/create_mulmo_script_from_url.js +152 -0
- package/lib/tools/create_mulmo_script_interactively.d.ts +3 -0
- package/lib/tools/create_mulmo_script_interactively.js +258 -0
- package/lib/tools/dump_prompt.js +5 -8
- package/lib/tools/prompt.js +9 -11
- package/lib/tools/seed_from_url2.d.ts +3 -0
- package/lib/tools/seed_from_url2.js +154 -0
- package/lib/types/index.d.ts +2 -1
- package/lib/types/index.js +2 -17
- package/lib/types/schema.d.ts +3624 -2798
- package/lib/types/schema.js +172 -123
- package/lib/types/type.d.ts +34 -3
- package/lib/types/type.js +1 -2
- package/lib/utils/const.d.ts +4 -1
- package/lib/utils/const.js +6 -6
- package/lib/utils/file.d.ts +22 -4
- package/lib/utils/file.js +100 -79
- package/lib/utils/filters.d.ts +1 -0
- package/lib/utils/filters.js +47 -26
- package/lib/utils/image_plugins/chart.d.ts +3 -0
- package/lib/utils/image_plugins/chart.js +18 -0
- package/lib/utils/image_plugins/image.d.ts +2 -0
- package/lib/utils/image_plugins/image.js +3 -0
- package/lib/utils/image_plugins/index.d.ts +7 -0
- package/lib/utils/image_plugins/index.js +7 -0
- package/lib/utils/image_plugins/markdown.d.ts +3 -0
- package/lib/utils/image_plugins/markdown.js +11 -0
- package/lib/utils/image_plugins/mermaid.d.ts +3 -0
- package/lib/utils/image_plugins/mermaid.js +21 -0
- package/lib/utils/image_plugins/movie.d.ts +2 -0
- package/lib/utils/image_plugins/movie.js +3 -0
- package/lib/utils/image_plugins/source.d.ts +4 -0
- package/lib/utils/image_plugins/source.js +15 -0
- package/lib/utils/image_plugins/text_slide.d.ts +3 -0
- package/lib/utils/image_plugins/text_slide.js +12 -0
- package/lib/utils/image_plugins/type_guards.d.ts +6 -0
- package/lib/utils/image_plugins/type_guards.js +21 -0
- package/lib/utils/image_preprocess.d.ts +14 -0
- package/lib/utils/image_preprocess.js +52 -0
- package/lib/utils/inquirer.d.ts +2 -0
- package/lib/utils/inquirer.js +33 -0
- package/lib/utils/markdown.d.ts +3 -1
- package/lib/utils/markdown.js +20 -19
- package/lib/utils/pdf.d.ts +8 -0
- package/lib/utils/pdf.js +75 -0
- package/lib/utils/plugins.d.ts +5 -0
- package/lib/utils/plugins.js +11 -0
- package/lib/utils/preprocess.d.ts +70 -123
- package/lib/utils/preprocess.js +37 -43
- package/lib/utils/string.js +4 -10
- package/lib/utils/text_hash.js +2 -39
- package/lib/utils/utils.d.ts +12 -0
- package/lib/utils/utils.js +34 -0
- package/package.json +23 -8
package/lib/actions/audio.js
CHANGED
|
@@ -1,88 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { GraphAI } from "graphai";
|
|
3
|
+
import * as agents from "@graphai/vanilla";
|
|
4
|
+
import ttsNijivoiceAgent from "../agents/tts_nijivoice_agent.js";
|
|
5
|
+
import addBGMAgent from "../agents/add_bgm_agent.js";
|
|
6
|
+
import combineAudioFilesAgent from "../agents/combine_audio_files_agent.js";
|
|
7
|
+
import ttsOpenaiAgent from "../agents/tts_openai_agent.js";
|
|
8
|
+
import { fileWriteAgent } from "@graphai/vanilla_node_agents";
|
|
9
|
+
import { MulmoScriptMethods } from "../methods/index.js";
|
|
10
|
+
import { fileCacheAgentFilter } from "../utils/filters.js";
|
|
11
|
+
import { getAudioArtifactFilePath, getAudioSegmentDirPath, getAudioCombinedFilePath, getOutputStudioFilePath, defaultBGMPath, mkdir, writingMessage, getAudioSegmentFilePath, resolveMediaSource, } from "../utils/file.js";
|
|
12
|
+
import { text2hash } from "../utils/utils.js";
|
|
13
|
+
const { default: __, ...vanillaAgents } = agents;
|
|
14
|
+
// const rion_takanashi_voice = "b9277ce3-ba1c-4f6f-9a65-c05ca102ded0"; // たかなし りおん
|
|
15
|
+
// const ben_carter_voice = "bc06c63f-fef6-43b6-92f7-67f919bd5dae"; // ベン・カーター
|
|
16
|
+
const provider_to_agent = {
|
|
17
|
+
nijivoice: "ttsNijivoiceAgent",
|
|
18
|
+
openai: "ttsOpenaiAgent",
|
|
19
|
+
};
|
|
20
|
+
const getAudioPath = (context, beat, audioFile, audioDirPath) => {
|
|
21
|
+
if (beat.audio?.type === "audio") {
|
|
22
|
+
const path = resolveMediaSource(beat.audio.source, context);
|
|
23
|
+
if (path) {
|
|
24
|
+
return path;
|
|
25
|
+
}
|
|
26
|
+
throw new Error("Invalid audio source");
|
|
7
27
|
}
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
28
|
+
return getAudioSegmentFilePath(audioDirPath, context.studio.filename, audioFile);
|
|
29
|
+
};
|
|
30
|
+
const preprocessor = (namedInputs) => {
|
|
31
|
+
const { beat, index, context, audioDirPath } = namedInputs;
|
|
32
|
+
const studioBeat = context.studio.beats[index];
|
|
33
|
+
const voiceId = context.studio.script.speechParams.speakers[beat.speaker].voiceId;
|
|
34
|
+
const speechOptions = MulmoScriptMethods.getSpeechOptions(context.studio.script, beat);
|
|
35
|
+
const hash_string = `${beat.text}${voiceId}${speechOptions?.instruction ?? ""}${speechOptions?.speed ?? 1.0}`;
|
|
36
|
+
const audioFile = `${context.studio.filename}_${index}_${text2hash(hash_string)}`;
|
|
37
|
+
const audioPath = getAudioPath(context, beat, audioFile, audioDirPath);
|
|
38
|
+
studioBeat.audioFile = audioPath;
|
|
39
|
+
return {
|
|
40
|
+
ttsAgent: provider_to_agent[context.studio.script.speechParams.provider],
|
|
41
|
+
studioBeat,
|
|
42
|
+
voiceId,
|
|
43
|
+
speechOptions,
|
|
44
|
+
audioPath,
|
|
33
45
|
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
46
|
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.audio = void 0;
|
|
40
|
-
require("dotenv/config");
|
|
41
|
-
const graphai_1 = require("graphai");
|
|
42
|
-
const agents = __importStar(require("@graphai/vanilla"));
|
|
43
|
-
const tts_nijivoice_agent_1 = __importDefault(require("../agents/tts_nijivoice_agent"));
|
|
44
|
-
const add_bgm_agent_1 = __importDefault(require("../agents/add_bgm_agent"));
|
|
45
|
-
const combine_audio_files_agent_1 = __importDefault(require("../agents/combine_audio_files_agent"));
|
|
46
|
-
const tts_openai_agent_1 = __importDefault(require("../agents/tts_openai_agent"));
|
|
47
|
-
const vanilla_node_agents_1 = require("@graphai/vanilla_node_agents");
|
|
48
|
-
const methods_1 = require("../methods");
|
|
49
|
-
const filters_1 = require("../utils/filters");
|
|
50
|
-
const file_1 = require("../utils/file");
|
|
51
|
-
// const rion_takanashi_voice = "b9277ce3-ba1c-4f6f-9a65-c05ca102ded0"; // たかなし りおん
|
|
52
|
-
// const ben_carter_voice = "bc06c63f-fef6-43b6-92f7-67f919bd5dae"; // ベン・カーター
|
|
53
47
|
const graph_tts = {
|
|
54
48
|
nodes: {
|
|
55
49
|
preprocessor: {
|
|
56
|
-
agent:
|
|
57
|
-
const { beat, script, speakers } = namedInputs;
|
|
58
|
-
return {
|
|
59
|
-
voiceId: speakers[beat.speaker].voiceId,
|
|
60
|
-
speechOptions: methods_1.MulmoScriptMethods.getSpeechOptions(script, beat),
|
|
61
|
-
};
|
|
62
|
-
},
|
|
50
|
+
agent: preprocessor,
|
|
63
51
|
inputs: {
|
|
64
52
|
beat: ":beat",
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
},
|
|
69
|
-
ttsAgent: {
|
|
70
|
-
agent: (namedInputs) => {
|
|
71
|
-
if (namedInputs.provider === "nijivoice") {
|
|
72
|
-
return "ttsNijivoiceAgent";
|
|
73
|
-
}
|
|
74
|
-
return "ttsOpenaiAgent";
|
|
75
|
-
},
|
|
76
|
-
inputs: {
|
|
77
|
-
provider: ":script.speechParams.provider",
|
|
53
|
+
index: ":__mapIndex",
|
|
54
|
+
context: ":context",
|
|
55
|
+
audioDirPath: ":audioDirPath",
|
|
78
56
|
},
|
|
79
57
|
},
|
|
80
58
|
tts: {
|
|
81
59
|
unless: ":beat.audio",
|
|
82
|
-
agent: ":ttsAgent",
|
|
60
|
+
agent: ":preprocessor.ttsAgent",
|
|
83
61
|
inputs: {
|
|
84
62
|
text: ":beat.text",
|
|
85
|
-
file: "
|
|
63
|
+
file: ":preprocessor.audioPath",
|
|
64
|
+
force: ":context.force",
|
|
86
65
|
},
|
|
87
66
|
params: {
|
|
88
67
|
voice: ":preprocessor.voiceId",
|
|
@@ -97,13 +76,20 @@ const graph_data = {
|
|
|
97
76
|
concurrency: 8,
|
|
98
77
|
nodes: {
|
|
99
78
|
context: {},
|
|
100
|
-
|
|
101
|
-
|
|
79
|
+
audioArtifactFilePath: {},
|
|
80
|
+
audioCombinedFilePath: {},
|
|
102
81
|
outputStudioFilePath: {},
|
|
103
|
-
|
|
82
|
+
audioDirPath: {},
|
|
83
|
+
audioSegmentDirPath: {},
|
|
104
84
|
map: {
|
|
105
85
|
agent: "mapAgent",
|
|
106
|
-
inputs: {
|
|
86
|
+
inputs: {
|
|
87
|
+
rows: ":context.studio.script.beats",
|
|
88
|
+
studio: ":context.studio",
|
|
89
|
+
audioDirPath: ":audioDirPath",
|
|
90
|
+
audioSegmentDirPath: ":audioSegmentDirPath",
|
|
91
|
+
context: ":context",
|
|
92
|
+
},
|
|
107
93
|
params: {
|
|
108
94
|
rowKey: "beat",
|
|
109
95
|
},
|
|
@@ -114,8 +100,8 @@ const graph_data = {
|
|
|
114
100
|
inputs: {
|
|
115
101
|
map: ":map",
|
|
116
102
|
context: ":context",
|
|
117
|
-
combinedFileName: ":
|
|
118
|
-
|
|
103
|
+
combinedFileName: ":audioCombinedFilePath",
|
|
104
|
+
audioDirPath: ":audioDirPath",
|
|
119
105
|
},
|
|
120
106
|
isResult: true,
|
|
121
107
|
},
|
|
@@ -129,12 +115,12 @@ const graph_data = {
|
|
|
129
115
|
addBGM: {
|
|
130
116
|
agent: "addBGMAgent",
|
|
131
117
|
params: {
|
|
132
|
-
musicFile: process.env.PATH_BGM ??
|
|
118
|
+
musicFile: process.env.PATH_BGM ?? defaultBGMPath,
|
|
133
119
|
},
|
|
134
120
|
inputs: {
|
|
135
121
|
wait: ":combineFiles",
|
|
136
|
-
voiceFile: ":
|
|
137
|
-
outputFile: ":
|
|
122
|
+
voiceFile: ":audioCombinedFilePath",
|
|
123
|
+
outputFile: ":audioArtifactFilePath",
|
|
138
124
|
script: ":context.studio.script",
|
|
139
125
|
},
|
|
140
126
|
isResult: true,
|
|
@@ -154,33 +140,34 @@ const graph_data = {
|
|
|
154
140
|
const agentFilters = [
|
|
155
141
|
{
|
|
156
142
|
name: "fileCacheAgentFilter",
|
|
157
|
-
agent:
|
|
143
|
+
agent: fileCacheAgentFilter,
|
|
158
144
|
nodeIds: ["tts"],
|
|
159
145
|
},
|
|
160
146
|
];
|
|
161
|
-
const audio = async (context
|
|
147
|
+
export const audio = async (context) => {
|
|
162
148
|
const { studio, fileDirs } = context;
|
|
163
|
-
const { outDirPath,
|
|
164
|
-
const
|
|
165
|
-
const
|
|
166
|
-
const
|
|
167
|
-
(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
149
|
+
const { outDirPath, audioDirPath } = fileDirs;
|
|
150
|
+
const audioArtifactFilePath = getAudioArtifactFilePath(outDirPath, studio.filename);
|
|
151
|
+
const audioSegmentDirPath = getAudioSegmentDirPath(audioDirPath, studio.filename);
|
|
152
|
+
const audioCombinedFilePath = getAudioCombinedFilePath(audioDirPath, studio.filename);
|
|
153
|
+
const outputStudioFilePath = getOutputStudioFilePath(outDirPath, studio.filename);
|
|
154
|
+
mkdir(outDirPath);
|
|
155
|
+
mkdir(audioSegmentDirPath);
|
|
156
|
+
graph_data.concurrency = MulmoScriptMethods.getSpeechProvider(studio.script) === "nijivoice" ? 1 : 8;
|
|
157
|
+
const graph = new GraphAI(graph_data, {
|
|
158
|
+
...vanillaAgents,
|
|
159
|
+
fileWriteAgent,
|
|
160
|
+
ttsOpenaiAgent,
|
|
161
|
+
ttsNijivoiceAgent,
|
|
162
|
+
addBGMAgent,
|
|
163
|
+
combineAudioFilesAgent,
|
|
177
164
|
}, { agentFilters });
|
|
178
165
|
graph.injectValue("context", context);
|
|
179
|
-
graph.injectValue("
|
|
180
|
-
graph.injectValue("
|
|
166
|
+
graph.injectValue("audioArtifactFilePath", audioArtifactFilePath);
|
|
167
|
+
graph.injectValue("audioCombinedFilePath", audioCombinedFilePath);
|
|
181
168
|
graph.injectValue("outputStudioFilePath", outputStudioFilePath);
|
|
182
|
-
graph.injectValue("
|
|
169
|
+
graph.injectValue("audioSegmentDirPath", audioSegmentDirPath);
|
|
170
|
+
graph.injectValue("audioDirPath", audioDirPath);
|
|
183
171
|
await graph.run();
|
|
184
|
-
|
|
172
|
+
writingMessage(audioCombinedFilePath);
|
|
185
173
|
};
|
|
186
|
-
exports.audio = audio;
|
package/lib/actions/images.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { MulmoStudioContext } from "../types";
|
|
1
|
+
import { MulmoStudioContext } from "../types/index.js";
|
|
2
2
|
export declare const images: (context: MulmoStudioContext) => Promise<void>;
|
package/lib/actions/images.js
CHANGED
|
@@ -1,83 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
1
|
+
import dotenv from "dotenv";
|
|
2
|
+
import { GraphAI, GraphAILogger } from "graphai";
|
|
3
|
+
import * as agents from "@graphai/vanilla";
|
|
4
|
+
import { fileWriteAgent } from "@graphai/vanilla_node_agents";
|
|
5
|
+
import { getOutputStudioFilePath, mkdir } from "../utils/file.js";
|
|
6
|
+
import { fileCacheAgentFilter } from "../utils/filters.js";
|
|
7
|
+
import imageGoogleAgent from "../agents/image_google_agent.js";
|
|
8
|
+
import imageOpenaiAgent from "../agents/image_openai_agent.js";
|
|
9
|
+
import { MulmoScriptMethods } from "../methods/index.js";
|
|
10
|
+
import { imagePlugins } from "../utils/image_plugins/index.js";
|
|
11
|
+
const { default: __, ...vanillaAgents } = agents;
|
|
12
|
+
dotenv.config();
|
|
13
|
+
// const openai = new OpenAI();
|
|
14
|
+
import { GoogleAuth } from "google-auth-library";
|
|
15
|
+
const htmlStyle = (script, beat) => {
|
|
16
|
+
return {
|
|
17
|
+
canvasSize: MulmoScriptMethods.getCanvasSize(script),
|
|
18
|
+
textSlideStyle: MulmoScriptMethods.getTextSlideStyle(script, beat),
|
|
33
19
|
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
20
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
const graphai_1 = require("graphai");
|
|
42
|
-
const agents = __importStar(require("@graphai/vanilla"));
|
|
43
|
-
const vanilla_node_agents_1 = require("@graphai/vanilla_node_agents");
|
|
44
|
-
const file_1 = require("../utils/file");
|
|
45
|
-
const filters_1 = require("../utils/filters");
|
|
46
|
-
const markdown_1 = require("../utils/markdown");
|
|
47
|
-
const image_google_agent_1 = __importDefault(require("../agents/image_google_agent"));
|
|
48
|
-
const image_openai_agent_1 = __importDefault(require("../agents/image_openai_agent"));
|
|
49
|
-
const methods_1 = require("../methods");
|
|
50
|
-
dotenv_1.default.config();
|
|
51
|
-
// const openai = new OpenAI();
|
|
52
|
-
const google_auth_library_1 = require("google-auth-library");
|
|
53
|
-
const preprocess_agent = async (namedInputs) => {
|
|
54
|
-
const { context, beat, index, suffix, imageDirPath } = namedInputs;
|
|
55
|
-
const imageParams = { ...context.studio.script.imageParams, ...beat.imageParams };
|
|
56
|
-
const prompt = (beat.imagePrompt || beat.text) + "\n" + (imageParams.style || "");
|
|
21
|
+
const imagePreprocessAgent = async (namedInputs) => {
|
|
22
|
+
const { context, beat, index, suffix, imageDirPath, imageAgentInfo } = namedInputs;
|
|
23
|
+
const imageParams = { ...imageAgentInfo.imageParams, ...beat.imageParams };
|
|
57
24
|
const imagePath = `${imageDirPath}/${context.studio.filename}/${index}${suffix}.png`;
|
|
58
|
-
const
|
|
25
|
+
const returnValue = {
|
|
26
|
+
aspectRatio: MulmoScriptMethods.getAspectRatio(context.studio.script),
|
|
27
|
+
imageParams,
|
|
28
|
+
};
|
|
59
29
|
if (beat.image) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const markdown = Array.isArray(beat.image.markdown) ? beat.image.markdown.join("\n") : beat.image.markdown;
|
|
67
|
-
await (0, markdown_1.convertMarkdownToImage)(markdown, methods_1.MulmoScriptMethods.getTextSlideStyle(context.studio.script, beat), imagePath);
|
|
68
|
-
}
|
|
69
|
-
else if (beat.image.type === "image") {
|
|
70
|
-
if (beat.image.source.kind === "url") {
|
|
71
|
-
// undefined prompt indicates "no need to generate image"
|
|
72
|
-
return { path: beat.image.source.url, prompt: undefined, imageParams, aspectRatio };
|
|
73
|
-
}
|
|
74
|
-
else if (beat.image.source.kind === "path") {
|
|
75
|
-
const path = methods_1.MulmoStudioContextMethods.resolveAssetPath(context, beat.image.source.path);
|
|
76
|
-
return { path, prompt: undefined, imageParams, aspectRatio };
|
|
77
|
-
}
|
|
30
|
+
const plugin = imagePlugins.find((plugin) => plugin.imageType === beat?.image?.type);
|
|
31
|
+
if (plugin) {
|
|
32
|
+
const processorParams = { beat, context, imagePath, ...htmlStyle(context.studio.script, beat) };
|
|
33
|
+
const path = await plugin.process(processorParams);
|
|
34
|
+
// undefined prompt indicates that image generation is not needed
|
|
35
|
+
return { path, ...returnValue };
|
|
78
36
|
}
|
|
79
37
|
}
|
|
80
|
-
|
|
38
|
+
const prompt = (beat.imagePrompt || beat.text) + "\n" + (imageParams.style || "");
|
|
39
|
+
return { path: imagePath, prompt, ...returnValue };
|
|
81
40
|
};
|
|
82
41
|
const graph_data = {
|
|
83
42
|
version: 0.5,
|
|
@@ -85,11 +44,11 @@ const graph_data = {
|
|
|
85
44
|
nodes: {
|
|
86
45
|
context: {},
|
|
87
46
|
imageDirPath: {},
|
|
88
|
-
|
|
47
|
+
imageAgentInfo: {},
|
|
89
48
|
outputStudioFilePath: {},
|
|
90
49
|
map: {
|
|
91
50
|
agent: "mapAgent",
|
|
92
|
-
inputs: { rows: ":context.studio.beats", context: ":context",
|
|
51
|
+
inputs: { rows: ":context.studio.script.beats", context: ":context", imageAgentInfo: ":imageAgentInfo", imageDirPath: ":imageDirPath" },
|
|
93
52
|
isResult: true,
|
|
94
53
|
params: {
|
|
95
54
|
rowKey: "beat",
|
|
@@ -98,18 +57,19 @@ const graph_data = {
|
|
|
98
57
|
graph: {
|
|
99
58
|
nodes: {
|
|
100
59
|
preprocessor: {
|
|
101
|
-
agent:
|
|
60
|
+
agent: imagePreprocessAgent,
|
|
102
61
|
inputs: {
|
|
103
62
|
context: ":context",
|
|
104
63
|
beat: ":beat",
|
|
105
64
|
index: ":__mapIndex",
|
|
106
65
|
suffix: "p",
|
|
107
66
|
imageDirPath: ":imageDirPath",
|
|
67
|
+
imageAgentInfo: ":imageAgentInfo",
|
|
108
68
|
},
|
|
109
69
|
},
|
|
110
70
|
imageGenerator: {
|
|
111
71
|
if: ":preprocessor.prompt",
|
|
112
|
-
agent: ":
|
|
72
|
+
agent: ":imageAgentInfo.agent",
|
|
113
73
|
params: {
|
|
114
74
|
model: ":preprocessor.imageParams.model",
|
|
115
75
|
size: ":preprocessor.imageParams.size",
|
|
@@ -120,6 +80,7 @@ const graph_data = {
|
|
|
120
80
|
prompt: ":preprocessor.prompt",
|
|
121
81
|
file: ":preprocessor.path", // only for fileCacheAgentFilter
|
|
122
82
|
text: ":preprocessor.prompt", // only for fileCacheAgentFilter
|
|
83
|
+
force: ":context.force",
|
|
123
84
|
},
|
|
124
85
|
defaultValue: {},
|
|
125
86
|
},
|
|
@@ -164,30 +125,31 @@ const graph_data = {
|
|
|
164
125
|
},
|
|
165
126
|
};
|
|
166
127
|
const googleAuth = async () => {
|
|
167
|
-
const auth = new
|
|
128
|
+
const auth = new GoogleAuth({
|
|
168
129
|
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
|
169
130
|
});
|
|
170
131
|
const client = await auth.getClient();
|
|
171
132
|
const accessToken = await client.getAccessToken();
|
|
172
133
|
return accessToken.token;
|
|
173
134
|
};
|
|
174
|
-
const images = async (context) => {
|
|
135
|
+
export const images = async (context) => {
|
|
175
136
|
const { studio, fileDirs } = context;
|
|
176
137
|
const { outDirPath, imageDirPath } = fileDirs;
|
|
177
|
-
|
|
138
|
+
mkdir(`${imageDirPath}/${studio.filename}`);
|
|
178
139
|
const agentFilters = [
|
|
179
140
|
{
|
|
180
141
|
name: "fileCacheAgentFilter",
|
|
181
|
-
agent:
|
|
142
|
+
agent: fileCacheAgentFilter,
|
|
182
143
|
nodeIds: ["imageGenerator"],
|
|
183
144
|
},
|
|
184
145
|
];
|
|
185
146
|
const options = {
|
|
186
147
|
agentFilters,
|
|
187
148
|
};
|
|
149
|
+
const imageAgentInfo = MulmoScriptMethods.getImageAgentInfo(studio.script);
|
|
188
150
|
// We need to get google's auth token only if the google is the text2image provider.
|
|
189
|
-
if (
|
|
190
|
-
|
|
151
|
+
if (imageAgentInfo.provider === "google") {
|
|
152
|
+
GraphAILogger.log("google was specified as text2image engine");
|
|
191
153
|
const token = await googleAuth();
|
|
192
154
|
options.config = {
|
|
193
155
|
imageGoogleAgent: {
|
|
@@ -196,16 +158,16 @@ const images = async (context) => {
|
|
|
196
158
|
},
|
|
197
159
|
};
|
|
198
160
|
}
|
|
161
|
+
GraphAILogger.info(`text2image: provider=${imageAgentInfo.provider} model=${imageAgentInfo.imageParams.model}`);
|
|
199
162
|
const injections = {
|
|
200
163
|
context,
|
|
201
|
-
|
|
202
|
-
outputStudioFilePath:
|
|
164
|
+
imageAgentInfo,
|
|
165
|
+
outputStudioFilePath: getOutputStudioFilePath(outDirPath, studio.filename),
|
|
203
166
|
imageDirPath,
|
|
204
167
|
};
|
|
205
|
-
const graph = new
|
|
168
|
+
const graph = new GraphAI(graph_data, { ...vanillaAgents, imageGoogleAgent, imageOpenaiAgent, fileWriteAgent }, options);
|
|
206
169
|
Object.keys(injections).forEach((key) => {
|
|
207
170
|
graph.injectValue(key, injections[key]);
|
|
208
171
|
});
|
|
209
172
|
await graph.run();
|
|
210
173
|
};
|
|
211
|
-
exports.images = images;
|
package/lib/actions/movie.d.ts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
import { MulmoStudioContext } from "../types";
|
|
1
|
+
import { MulmoStudioContext, MulmoCanvasDimension, BeatMediaType } from "../types/index.js";
|
|
2
|
+
export declare const getVideoPart: (inputIndex: number, mediaType: BeatMediaType, duration: number, canvasInfo: MulmoCanvasDimension) => {
|
|
3
|
+
videoId: string;
|
|
4
|
+
videoPart: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const getAudioPart: (inputIndex: number, duration: number, delay: number) => {
|
|
7
|
+
audioId: string;
|
|
8
|
+
audioPart: string;
|
|
9
|
+
};
|
|
2
10
|
export declare const movie: (context: MulmoStudioContext) => Promise<void>;
|