@makemidas/cli 0.1.0 → 0.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 +102 -16
- package/dist/api.js +112 -2
- package/dist/args.js +253 -1
- package/dist/cli.js +187 -24
- package/dist/commands.js +474 -23
- package/dist/config.js +1 -1
- package/dist/errors.js +28 -1
- package/package.json +11 -3
package/README.md
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
AI image and
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
# MakeMidas CLI: AI image and video generation for AI agents
|
|
2
|
+
|
|
3
|
+
An AI image, video and audio generation CLI for Claude Code, Cursor, Codex,
|
|
4
|
+
Gemini CLI, OpenClaw and people at a terminal. One command reaches Nano
|
|
5
|
+
Banana, GPT Image, Seedream, Flux, Seedance, Kling, Veo, Wan, Suno, Lyria,
|
|
6
|
+
Gemini TTS, Whisper and more through [MakeMidas](https://makemidas.com), paid
|
|
7
|
+
with your MakeMidas credits. It also transcribes audio, removes backgrounds,
|
|
8
|
+
upscales images and videos, and compares image models side by side. Coding
|
|
9
|
+
agents run it like any other command; the
|
|
10
|
+
[agent skill](https://github.com/makemidas-ai/skills) teaches them the
|
|
11
|
+
options, and the same account works in ChatGPT and Claude through the
|
|
12
|
+
[MakeMidas MCP server](https://makemidas.com/developers).
|
|
8
13
|
|
|
9
14
|
```bash
|
|
10
15
|
npm i -g @makemidas/cli # or: npx @makemidas/cli …
|
|
11
16
|
makemidas auth login # opens the browser once
|
|
12
17
|
makemidas image "a lighthouse at dawn, film photo" --aspect 16:9
|
|
13
18
|
makemidas video "the waves roll in" --ref lighthouse.png --duration 5
|
|
19
|
+
makemidas speech "Welcome back." --delivery "warm and unhurried"
|
|
20
|
+
makemidas transcribe interview.m4a --format srt
|
|
14
21
|
```
|
|
15
22
|
|
|
16
23
|
## Commands
|
|
@@ -22,30 +29,109 @@ makemidas video "the waves roll in" --ref lighthouse.png --duration 5
|
|
|
22
29
|
| `auth status` | Show the signed-in account |
|
|
23
30
|
| `image "<prompt>"` | Generate 1–4 images and save them (`./makemidas-<id>-<n>.png`) |
|
|
24
31
|
| `video "<prompt>"` | Generate a clip, wait for it and save it |
|
|
32
|
+
| `music "<prompt>"` | Generate a song or track (`--lyrics`, `--title`, `--instrumental`, `--duration`) |
|
|
33
|
+
| `sfx "<prompt>"` | Generate a sound effect (`--loop`, `--bpm`; the model sets the length) |
|
|
34
|
+
| `speech "<text>"` (alias `voiceover`) | Turn text into a voiceover (`--voice`; `--delivery` on Gemini TTS, `--speed`/`--stability` on ElevenLabs) |
|
|
35
|
+
| `transcribe <file\|url\|fileId>` | Upload audio or video, transcribe it and save the transcript (`--format txt\|srt\|vtt\|json`, `--title`) |
|
|
36
|
+
| `remove-bg <image>` | Remove the background; saves a transparent WebP |
|
|
37
|
+
| `upscale <image> [--scale 1\|2\|4\|8]` | Upscale an image (1 sharpens at the same size; default 2) |
|
|
38
|
+
| `upscale-video <video> [--resolution 1080P\|2K\|4K]` | Upscale an MP4 or MOV clip of up to 60 s (default 2K) |
|
|
39
|
+
| `compare "<prompt>" --models a,b[,c,d]` | One prompt on 2–4 image models, one image each |
|
|
25
40
|
| `get <id> [--wait]` | Fetch a generation and save its files |
|
|
26
41
|
| `list [--limit n] [--before t]` | Recent generations |
|
|
42
|
+
| `delete <id> [--yes]` | Delete a finished or failed generation and its files (no refund) |
|
|
27
43
|
| `credits` | Balance, plan, expiring credits |
|
|
28
|
-
| `
|
|
44
|
+
| `credits buy` (or `credits link`) | Links to buy a plan or credit pack, with prices; opens nothing |
|
|
45
|
+
| `models [image\|video\|audio\|transcription\|edit]` | Model ids, options and credit prices |
|
|
46
|
+
| `models <id>` | One model: options, defaults, voices, prices and an example request |
|
|
47
|
+
| `estimate <command> "<prompt>"\|<file>` | Price a request without charging; `<command>` is `image`, `video`, `music`, `sfx`, `speech`, `transcribe`, `remove-bg`, `upscale` or `upscale-video`, with that command's options |
|
|
48
|
+
| `feedback "<message>" [--kind bug\|feature\|praise\|other] [--generation <id>]` | Send feedback to the MakeMidas team |
|
|
29
49
|
|
|
30
50
|
Common options: `--model`, `--aspect`, `--resolution`, `--count`, `--ref`
|
|
31
51
|
(file or URL, repeatable), `--style`, `--enhance`, `--duration`, `--audio`,
|
|
32
|
-
`--frame-mode`, `--out <dir>`, `--no-download`, `--json`. Run
|
|
33
|
-
`makemidas --help` for all of them.
|
|
52
|
+
`--frame-mode`, `--out <dir>`, `--no-download`, `--no-wait`, `--json`. Run
|
|
53
|
+
`makemidas --help` for all of them. An option that belongs to another
|
|
54
|
+
command (say `--lyrics` on `sfx`) is a usage error.
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
makemidas music "lo-fi beat for studying" --instrumental
|
|
58
|
+
makemidas sfx "a wooden door creaks open"
|
|
59
|
+
makemidas voiceover "Thanks for watching." --voice Charon
|
|
60
|
+
makemidas transcribe https://example.com/talk.mp3 -o - # print the text
|
|
61
|
+
makemidas remove-bg product.jpg
|
|
62
|
+
makemidas upscale photo.png --scale 4
|
|
63
|
+
makemidas upscale-video clip.mp4 --resolution 4K
|
|
64
|
+
makemidas compare "a red fox in the snow" --models <id-a>,<id-b>
|
|
65
|
+
makemidas delete <id> --yes
|
|
66
|
+
makemidas feedback "The upscale kept the noise" --kind bug --generation <id>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Videos, audio, transcripts and edits run in the background: the CLI waits
|
|
70
|
+
for them (`--timeout <min>`, default 15) unless you pass `--no-wait`, which
|
|
71
|
+
prints the id and exits 7; fetch it later with `makemidas get <id> --wait`.
|
|
72
|
+
|
|
73
|
+
`transcribe` sends a local file as the upload body (MP3, WAV, M4A, AAC,
|
|
74
|
+
FLAC, OGG, Opus, WEBM, MP4 or MOV, up to 100 MB and 60 minutes) or passes a
|
|
75
|
+
link for the server to download, then saves the transcript in `--format`
|
|
76
|
+
(default `txt`); `-o -` prints it on stdout and `--no-download` prints its
|
|
77
|
+
link. The model defaults to `openai/whisper-large-v2`; `-m
|
|
78
|
+
nvidia/nemotron-3.5-transcribe` is faster and cheaper. `upscale-video`
|
|
79
|
+
uploads the same way. Uploaded files are deleted after 7 days; the `fileId`
|
|
80
|
+
an upload printed in `--json` can be passed instead of the file.
|
|
81
|
+
|
|
82
|
+
`compare` saves each model's image and prints `<model> <file>` per line.
|
|
83
|
+
Models that could not start are listed as warnings and cost nothing; it
|
|
84
|
+
exits 5 only when no model made an image.
|
|
85
|
+
|
|
86
|
+
`delete` asks before deleting on a terminal; in scripts and agents (stdin
|
|
87
|
+
not a terminal) it refuses with exit 2 unless you pass `--yes`.
|
|
34
88
|
|
|
35
89
|
Results go to stdout (file paths, or links with `--no-download`), progress to
|
|
36
90
|
stderr; `--json` gives the full generation as JSON.
|
|
37
91
|
|
|
38
|
-
Exit codes: 0 ok, 2 bad input
|
|
39
|
-
|
|
40
|
-
|
|
92
|
+
Exit codes: 0 ok, 2 bad input (including `delete` without `--yes` when
|
|
93
|
+
stdin is not a terminal), 3 not signed in, 4 not enough credits, a plan
|
|
94
|
+
limit or busy (also over `--max-credits`), 5 generation failed (credits
|
|
95
|
+
refunded), 6 network or server error, 7 still rendering.
|
|
41
96
|
|
|
42
97
|
## Credits
|
|
43
98
|
|
|
44
|
-
Every generation spends credits at the same prices as the website.
|
|
45
|
-
|
|
46
|
-
|
|
99
|
+
Every generation spends credits at the same prices as the website. There
|
|
100
|
+
are no free credits: credits come from a monthly plan or a one-time credit
|
|
101
|
+
pack (`makemidas credits buy` prints the links and prices). `makemidas
|
|
102
|
+
models` shows the prices;
|
|
47
103
|
`--quoted-credits <n>` refuses to charge anything else.
|
|
48
104
|
|
|
105
|
+
Check a price before spending, with the same options as the real command
|
|
106
|
+
(nothing is charged, and it exits 0 even when the balance is short):
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
makemidas estimate video "the waves roll in" --duration 5 --audio
|
|
110
|
+
makemidas models google/gemini-omni-flash # options, defaults, prices
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
makemidas estimate speech "Welcome back." --voice Kore
|
|
115
|
+
makemidas estimate transcribe interview.m4a
|
|
116
|
+
makemidas estimate upscale-video clip.mp4 --resolution 4K
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Or price and run in one step: `--max-credits <n>` on any generating command
|
|
120
|
+
(`image`, `video`, `music`, `sfx`, `speech`, `transcribe`, `remove-bg`,
|
|
121
|
+
`upscale`, `upscale-video`, `compare`) estimates first and stops (exit 4, nothing charged) when the request costs
|
|
122
|
+
more than `n` or more than your balance. Otherwise it sends the estimated
|
|
123
|
+
request back at exactly the quoted price, with reference images and files
|
|
124
|
+
uploaded once. `compare` prices each model and quotes the total:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
makemidas video "the waves roll in" --duration 5 --audio --max-credits 60
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
When the server can tell, errors end with a hint: try again later, change
|
|
131
|
+
the prompt (a safety filter refused it), or a cheaper `--model` that fits
|
|
132
|
+
your balance. With `--json` the same fields (`retryable`,
|
|
133
|
+
`requiresPromptRevision`, `suggestedModel`) stay in the error object.
|
|
134
|
+
|
|
49
135
|
## Sign-in and credentials
|
|
50
136
|
|
|
51
137
|
`auth login` opens MakeMidas in your browser, where you sign in and allow
|
package/dist/api.js
CHANGED
|
@@ -3,12 +3,45 @@ import { basename, extname } from 'node:path';
|
|
|
3
3
|
import { accessToken, envCredential } from "./auth.js";
|
|
4
4
|
import { USER_AGENT } from "./config.js";
|
|
5
5
|
import { CliError, EXIT, exitCodeFor } from "./errors.js";
|
|
6
|
+
export const KINDS = [
|
|
7
|
+
'image',
|
|
8
|
+
'video',
|
|
9
|
+
'audio',
|
|
10
|
+
'transcription',
|
|
11
|
+
'edit',
|
|
12
|
+
];
|
|
6
13
|
const CONTENT_TYPES = {
|
|
7
14
|
'.jpg': 'image/jpeg',
|
|
8
15
|
'.jpeg': 'image/jpeg',
|
|
9
16
|
'.png': 'image/png',
|
|
10
17
|
'.webp': 'image/webp',
|
|
11
18
|
};
|
|
19
|
+
/** What audio- and video-uploads accept, by file extension. */
|
|
20
|
+
const VIDEO_TYPES = {
|
|
21
|
+
'.mp4': 'video/mp4',
|
|
22
|
+
'.mov': 'video/quicktime',
|
|
23
|
+
};
|
|
24
|
+
const AUDIO_TYPES = {
|
|
25
|
+
'.mp3': 'audio/mpeg',
|
|
26
|
+
'.wav': 'audio/wav',
|
|
27
|
+
'.m4a': 'audio/mp4',
|
|
28
|
+
'.aac': 'audio/aac',
|
|
29
|
+
'.flac': 'audio/flac',
|
|
30
|
+
'.ogg': 'audio/ogg',
|
|
31
|
+
'.oga': 'audio/ogg',
|
|
32
|
+
'.opus': 'audio/opus',
|
|
33
|
+
'.webm': 'audio/webm',
|
|
34
|
+
...VIDEO_TYPES,
|
|
35
|
+
};
|
|
36
|
+
const MEDIA_UPLOADS = {
|
|
37
|
+
audio: {
|
|
38
|
+
path: '/audio-uploads',
|
|
39
|
+
types: AUDIO_TYPES,
|
|
40
|
+
what: 'MP3, WAV, M4A, AAC, FLAC, OGG, Opus, WEBM, MP4 or MOV',
|
|
41
|
+
},
|
|
42
|
+
video: { path: '/video-uploads', types: VIDEO_TYPES, what: 'MP4 or MOV' },
|
|
43
|
+
};
|
|
44
|
+
const isUrl = (source) => /^https?:\/\//i.test(source);
|
|
12
45
|
export class Api {
|
|
13
46
|
baseUrl;
|
|
14
47
|
/** Overridable in tests. */
|
|
@@ -32,8 +65,10 @@ export class Api {
|
|
|
32
65
|
...(opts.json !== undefined
|
|
33
66
|
? { 'Content-Type': 'application/json' }
|
|
34
67
|
: {}),
|
|
68
|
+
...opts.headers,
|
|
35
69
|
},
|
|
36
70
|
body: opts.form ??
|
|
71
|
+
opts.body ??
|
|
37
72
|
(opts.json !== undefined ? JSON.stringify(opts.json) : undefined),
|
|
38
73
|
});
|
|
39
74
|
}
|
|
@@ -53,17 +88,27 @@ export class Api {
|
|
|
53
88
|
let code = 'http_error';
|
|
54
89
|
let message = `${res.status} ${res.statusText}`;
|
|
55
90
|
let credits;
|
|
91
|
+
const details = {};
|
|
56
92
|
try {
|
|
57
93
|
const body = (await res.json());
|
|
58
94
|
code = body.error?.code ?? code;
|
|
59
95
|
message = body.error?.message ?? message;
|
|
60
96
|
credits = body.error?.credits;
|
|
97
|
+
if (typeof body.error?.retryable === 'boolean') {
|
|
98
|
+
details.retryable = body.error.retryable;
|
|
99
|
+
}
|
|
100
|
+
if (typeof body.error?.requiresPromptRevision === 'boolean') {
|
|
101
|
+
details.requiresPromptRevision = body.error.requiresPromptRevision;
|
|
102
|
+
}
|
|
103
|
+
if (typeof body.error?.suggestedModel === 'string') {
|
|
104
|
+
details.suggestedModel = body.error.suggestedModel;
|
|
105
|
+
}
|
|
61
106
|
}
|
|
62
107
|
catch { }
|
|
63
108
|
if (code === 'price_changed' && credits !== undefined) {
|
|
64
109
|
message = `The price is now ${credits} credits; nothing was charged. Run again with --quoted-credits ${credits}.`;
|
|
65
110
|
}
|
|
66
|
-
throw new CliError(message, exitCodeFor(code, res.status), code);
|
|
111
|
+
throw new CliError(message, exitCodeFor(code, res.status), code, details);
|
|
67
112
|
}
|
|
68
113
|
async json(path, opts = {}) {
|
|
69
114
|
return (await (await this.request(path, opts)).json());
|
|
@@ -78,12 +123,16 @@ export class Api {
|
|
|
78
123
|
return (await this.json('/models', { query: { kind } }))
|
|
79
124
|
.models;
|
|
80
125
|
}
|
|
126
|
+
/** One model; ids hold a slash, which is sent encoded. */
|
|
127
|
+
modelDetails(id) {
|
|
128
|
+
return this.json(`/models/${encodeURIComponent(id)}`);
|
|
129
|
+
}
|
|
81
130
|
/** Upload a local image (or one downloaded from a URL) as a reference. */
|
|
82
131
|
async upload(source) {
|
|
83
132
|
let bytes;
|
|
84
133
|
let type;
|
|
85
134
|
let name;
|
|
86
|
-
if (
|
|
135
|
+
if (isUrl(source)) {
|
|
87
136
|
const res = await this.fetchImpl(source).catch(() => null);
|
|
88
137
|
if (!res?.ok) {
|
|
89
138
|
throw new CliError(`Could not download ${source}`, EXIT.USAGE, 'invalid_file');
|
|
@@ -113,17 +162,78 @@ export class Api {
|
|
|
113
162
|
});
|
|
114
163
|
return id;
|
|
115
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Upload audio or video to transcribe (`audio`), or a video to upscale
|
|
167
|
+
* (`video`): a local file goes as the raw body, a link as `{ url }` for
|
|
168
|
+
* the server to download.
|
|
169
|
+
*/
|
|
170
|
+
async mediaUpload(kind, source) {
|
|
171
|
+
const { path, types, what } = MEDIA_UPLOADS[kind];
|
|
172
|
+
if (isUrl(source)) {
|
|
173
|
+
return this.json(path, {
|
|
174
|
+
method: 'POST',
|
|
175
|
+
json: { url: source },
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
const type = types[extname(source).toLowerCase()];
|
|
179
|
+
if (!type) {
|
|
180
|
+
throw new CliError(`${source}: upload ${what} files.`, EXIT.USAGE, 'invalid_file');
|
|
181
|
+
}
|
|
182
|
+
let bytes;
|
|
183
|
+
try {
|
|
184
|
+
bytes = new Uint8Array(await readFile(source));
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
throw new CliError(`Can't read ${source}`, EXIT.USAGE, 'invalid_file');
|
|
188
|
+
}
|
|
189
|
+
return this.json(path, {
|
|
190
|
+
method: 'POST',
|
|
191
|
+
body: bytes,
|
|
192
|
+
headers: {
|
|
193
|
+
'Content-Type': type,
|
|
194
|
+
'Content-Length': String(bytes.byteLength),
|
|
195
|
+
'X-File-Name': encodeURIComponent(basename(source)),
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
}
|
|
116
199
|
generate(input) {
|
|
117
200
|
return this.json('/generations', {
|
|
118
201
|
method: 'POST',
|
|
119
202
|
json: input,
|
|
120
203
|
});
|
|
121
204
|
}
|
|
205
|
+
/** Price a request without charging or creating anything. */
|
|
206
|
+
estimate(input) {
|
|
207
|
+
return this.json('/generations/estimate', {
|
|
208
|
+
method: 'POST',
|
|
209
|
+
json: input,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
122
212
|
generation(id, waitSeconds = 0) {
|
|
123
213
|
return this.json(`/generations/${encodeURIComponent(id)}`, {
|
|
124
214
|
query: { wait: waitSeconds || undefined },
|
|
125
215
|
});
|
|
126
216
|
}
|
|
217
|
+
/** Run one prompt on 2-4 image models at once. */
|
|
218
|
+
compare(input) {
|
|
219
|
+
return this.json('/generations/compare', {
|
|
220
|
+
method: 'POST',
|
|
221
|
+
json: input,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
/** Delete a finished or failed generation and its files. */
|
|
225
|
+
deleteGeneration(id) {
|
|
226
|
+
return this.json(`/generations/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
227
|
+
}
|
|
228
|
+
feedback(input) {
|
|
229
|
+
return this.json('/feedback', {
|
|
230
|
+
method: 'POST',
|
|
231
|
+
json: input,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
purchaseLink() {
|
|
235
|
+
return this.json('/credits/purchase-link');
|
|
236
|
+
}
|
|
127
237
|
async list(query) {
|
|
128
238
|
return (await this.json('/generations', { query })).generations;
|
|
129
239
|
}
|
package/dist/args.js
CHANGED
|
@@ -25,6 +25,7 @@ export function parse(argv) {
|
|
|
25
25
|
'frame-mode': { type: 'string' },
|
|
26
26
|
audio: { type: 'boolean', default: false },
|
|
27
27
|
'quoted-credits': { type: 'string' },
|
|
28
|
+
'max-credits': { type: 'string' },
|
|
28
29
|
out: { type: 'string', short: 'o', default: '.' },
|
|
29
30
|
'no-download': { type: 'boolean', default: false },
|
|
30
31
|
force: { type: 'boolean', default: false },
|
|
@@ -34,6 +35,21 @@ export function parse(argv) {
|
|
|
34
35
|
limit: { type: 'string', default: '20' },
|
|
35
36
|
before: { type: 'string' },
|
|
36
37
|
kind: { type: 'string' },
|
|
38
|
+
lyrics: { type: 'string' },
|
|
39
|
+
title: { type: 'string' },
|
|
40
|
+
instrumental: { type: 'boolean', default: false },
|
|
41
|
+
loop: { type: 'boolean', default: false },
|
|
42
|
+
bpm: { type: 'string' },
|
|
43
|
+
voice: { type: 'string' },
|
|
44
|
+
delivery: { type: 'string' },
|
|
45
|
+
speed: { type: 'string' },
|
|
46
|
+
stability: { type: 'string' },
|
|
47
|
+
language: { type: 'string' },
|
|
48
|
+
format: { type: 'string' },
|
|
49
|
+
scale: { type: 'string' },
|
|
50
|
+
models: { type: 'string' },
|
|
51
|
+
generation: { type: 'string' },
|
|
52
|
+
yes: { type: 'boolean', short: 'y', default: false },
|
|
37
53
|
},
|
|
38
54
|
});
|
|
39
55
|
}
|
|
@@ -50,6 +66,45 @@ export function intOption(value, name, min, max) {
|
|
|
50
66
|
}
|
|
51
67
|
return n;
|
|
52
68
|
}
|
|
69
|
+
export function numberOption(value, name, min, max) {
|
|
70
|
+
if (value === undefined)
|
|
71
|
+
return undefined;
|
|
72
|
+
const n = Number(value);
|
|
73
|
+
if (!value.trim() || !Number.isFinite(n) || n < min || n > max) {
|
|
74
|
+
throw usageError(`--${name} must be a number from ${min} to ${max}.`);
|
|
75
|
+
}
|
|
76
|
+
return n;
|
|
77
|
+
}
|
|
78
|
+
/** Options set on the command line, by name (booleans only when true). */
|
|
79
|
+
function given(v, names) {
|
|
80
|
+
return names.filter((name) => {
|
|
81
|
+
const value = v[name];
|
|
82
|
+
return Array.isArray(value) ? value.length > 0 : value !== undefined && value !== false;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/** Refuse options that belong to another command. */
|
|
86
|
+
function refuse(v, names, command) {
|
|
87
|
+
const wrong = given(v, names);
|
|
88
|
+
if (wrong.length) {
|
|
89
|
+
throw usageError(`${wrong.map((name) => `--${name}`).join(', ')} ${wrong.length === 1 ? 'is' : 'are'} not for \`${command}\`.`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const VISUAL_OPTIONS = [
|
|
93
|
+
'aspect',
|
|
94
|
+
'resolution',
|
|
95
|
+
'count',
|
|
96
|
+
'style',
|
|
97
|
+
'enhance',
|
|
98
|
+
'ref',
|
|
99
|
+
'frame-mode',
|
|
100
|
+
'audio',
|
|
101
|
+
];
|
|
102
|
+
const MUSIC_OPTIONS = ['lyrics', 'title', 'instrumental'];
|
|
103
|
+
const SFX_OPTIONS = ['loop', 'bpm'];
|
|
104
|
+
const SPEECH_OPTIONS = ['voice', 'delivery', 'speed', 'stability', 'language'];
|
|
105
|
+
function quotedCredits(v) {
|
|
106
|
+
return intOption(v['quoted-credits'], 'quoted-credits', 0, 1_000_000);
|
|
107
|
+
}
|
|
53
108
|
/** The generation request a `makemidas image|video` command line asks for. */
|
|
54
109
|
export function generationInput(kind, prompt, v) {
|
|
55
110
|
if (!prompt?.trim()) {
|
|
@@ -58,6 +113,7 @@ export function generationInput(kind, prompt, v) {
|
|
|
58
113
|
if (kind === 'image' && (v.duration || v.audio || v['frame-mode'])) {
|
|
59
114
|
throw usageError('--duration, --audio and --frame-mode are for videos.');
|
|
60
115
|
}
|
|
116
|
+
refuse(v, [...MUSIC_OPTIONS, ...SFX_OPTIONS, ...SPEECH_OPTIONS, 'scale', 'format'], kind);
|
|
61
117
|
const input = {
|
|
62
118
|
kind,
|
|
63
119
|
prompt: prompt.trim(),
|
|
@@ -70,7 +126,7 @@ export function generationInput(kind, prompt, v) {
|
|
|
70
126
|
const count = intOption(v.count, 'count', 1, 4);
|
|
71
127
|
if (count)
|
|
72
128
|
input.count = count;
|
|
73
|
-
const quoted =
|
|
129
|
+
const quoted = quotedCredits(v);
|
|
74
130
|
if (quoted !== undefined)
|
|
75
131
|
input.quotedCredits = quoted;
|
|
76
132
|
if (kind === 'video') {
|
|
@@ -88,3 +144,199 @@ export function generationInput(kind, prompt, v) {
|
|
|
88
144
|
}
|
|
89
145
|
return input;
|
|
90
146
|
}
|
|
147
|
+
/** The `makemidas music|sfx|speech` command each audio task is run with. */
|
|
148
|
+
export const AUDIO_COMMANDS = {
|
|
149
|
+
music: 'music',
|
|
150
|
+
sfx: 'sfx',
|
|
151
|
+
speech: 'speech',
|
|
152
|
+
};
|
|
153
|
+
/** A `makemidas music|sfx|speech` request: kind audio with its task. */
|
|
154
|
+
export function audioInput(task, prompt, v) {
|
|
155
|
+
const command = AUDIO_COMMANDS[task];
|
|
156
|
+
if (!prompt?.trim()) {
|
|
157
|
+
throw usageError(task === 'speech'
|
|
158
|
+
? 'Give the text to speak: `makemidas speech "Welcome back."`.'
|
|
159
|
+
: `Give a prompt: \`makemidas ${command} "${task === 'music' ? 'lo-fi beat for studying' : 'a door creaking open'}"\`.`);
|
|
160
|
+
}
|
|
161
|
+
const others = [...VISUAL_OPTIONS, 'scale', 'format'];
|
|
162
|
+
if (task !== 'music')
|
|
163
|
+
others.push(...MUSIC_OPTIONS);
|
|
164
|
+
if (task !== 'sfx')
|
|
165
|
+
others.push(...SFX_OPTIONS);
|
|
166
|
+
if (task !== 'speech')
|
|
167
|
+
others.push(...SPEECH_OPTIONS);
|
|
168
|
+
// Only music models list track lengths; sound effects set their own.
|
|
169
|
+
if (task !== 'music')
|
|
170
|
+
others.push('duration');
|
|
171
|
+
refuse(v, others, command);
|
|
172
|
+
const input = {
|
|
173
|
+
kind: 'audio',
|
|
174
|
+
task,
|
|
175
|
+
// A voiceover reads the text as written; prompts are trimmed.
|
|
176
|
+
prompt: task === 'speech' ? prompt : prompt.trim(),
|
|
177
|
+
...(v.model ? { model: v.model } : {}),
|
|
178
|
+
};
|
|
179
|
+
if (task === 'music') {
|
|
180
|
+
if (v.lyrics !== undefined)
|
|
181
|
+
input.lyrics = v.lyrics;
|
|
182
|
+
if (v.title !== undefined)
|
|
183
|
+
input.title = v.title;
|
|
184
|
+
if (v.instrumental)
|
|
185
|
+
input.instrumental = true;
|
|
186
|
+
if (v.lyrics !== undefined && v.instrumental) {
|
|
187
|
+
throw usageError('--lyrics and --instrumental do not go together.');
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (task === 'music') {
|
|
191
|
+
const seconds = intOption(v.duration, 'duration', 1, 240);
|
|
192
|
+
if (seconds)
|
|
193
|
+
input.durationSeconds = seconds;
|
|
194
|
+
}
|
|
195
|
+
if (task === 'sfx') {
|
|
196
|
+
if (v.loop)
|
|
197
|
+
input.loop = true;
|
|
198
|
+
const bpm = intOption(v.bpm, 'bpm', 40, 240);
|
|
199
|
+
if (bpm !== undefined)
|
|
200
|
+
input.bpm = bpm;
|
|
201
|
+
}
|
|
202
|
+
if (task === 'speech') {
|
|
203
|
+
if (v.delivery !== undefined && (v.speed !== undefined || v.stability !== undefined)) {
|
|
204
|
+
throw usageError('--delivery is for Gemini TTS models, --speed and --stability for ElevenLabs models; use one or the other.');
|
|
205
|
+
}
|
|
206
|
+
if (v.voice)
|
|
207
|
+
input.voice = v.voice;
|
|
208
|
+
if (v.delivery !== undefined)
|
|
209
|
+
input.delivery = v.delivery;
|
|
210
|
+
const speed = numberOption(v.speed, 'speed', 0.7, 1.2);
|
|
211
|
+
if (speed !== undefined)
|
|
212
|
+
input.speed = speed;
|
|
213
|
+
const stability = numberOption(v.stability, 'stability', 0, 1);
|
|
214
|
+
if (stability !== undefined)
|
|
215
|
+
input.stability = stability;
|
|
216
|
+
if (v.language)
|
|
217
|
+
input.language = v.language;
|
|
218
|
+
}
|
|
219
|
+
const quoted = quotedCredits(v);
|
|
220
|
+
if (quoted !== undefined)
|
|
221
|
+
input.quotedCredits = quoted;
|
|
222
|
+
return input;
|
|
223
|
+
}
|
|
224
|
+
export const DEFAULT_TRANSCRIPTION_MODEL = 'openai/whisper-large-v2';
|
|
225
|
+
const TRANSCRIPT_FORMATS = ['txt', 'srt', 'vtt', 'json'];
|
|
226
|
+
/** The one file or link a `transcribe`/`remove-bg`/`upscale…` command takes. */
|
|
227
|
+
export function sourceArg(rest, command, what) {
|
|
228
|
+
if (rest.length !== 1 || !rest[0].trim()) {
|
|
229
|
+
throw usageError(`Give one ${what}: \`makemidas ${command} <file-or-url>\`.`);
|
|
230
|
+
}
|
|
231
|
+
return rest[0];
|
|
232
|
+
}
|
|
233
|
+
/** A `makemidas transcribe` request, without the fileId the upload returns. */
|
|
234
|
+
export function transcriptionInput(v) {
|
|
235
|
+
refuse(v, [
|
|
236
|
+
...VISUAL_OPTIONS,
|
|
237
|
+
...MUSIC_OPTIONS.filter((name) => name !== 'title'),
|
|
238
|
+
...SFX_OPTIONS,
|
|
239
|
+
...SPEECH_OPTIONS,
|
|
240
|
+
'duration',
|
|
241
|
+
'scale',
|
|
242
|
+
], 'transcribe');
|
|
243
|
+
const format = (v.format ?? 'txt').toLowerCase();
|
|
244
|
+
if (!TRANSCRIPT_FORMATS.includes(format)) {
|
|
245
|
+
throw usageError('--format must be txt, srt, vtt or json.');
|
|
246
|
+
}
|
|
247
|
+
const input = {
|
|
248
|
+
kind: 'transcription',
|
|
249
|
+
model: v.model ?? DEFAULT_TRANSCRIPTION_MODEL,
|
|
250
|
+
...(v.title !== undefined ? { title: v.title } : {}),
|
|
251
|
+
};
|
|
252
|
+
const quoted = quotedCredits(v);
|
|
253
|
+
if (quoted !== undefined)
|
|
254
|
+
input.quotedCredits = quoted;
|
|
255
|
+
return { input, format };
|
|
256
|
+
}
|
|
257
|
+
/** The `makemidas …` command that runs each edit task. */
|
|
258
|
+
export const EDIT_COMMANDS = {
|
|
259
|
+
'remove-background': 'remove-bg',
|
|
260
|
+
'upscale-image': 'upscale',
|
|
261
|
+
'upscale-video': 'upscale-video',
|
|
262
|
+
};
|
|
263
|
+
const VIDEO_UPSCALE_RESOLUTIONS = ['1080P', '2K', '4K'];
|
|
264
|
+
/** A `makemidas remove-bg|upscale|upscale-video` request (kind edit). */
|
|
265
|
+
export function editInput(task, v) {
|
|
266
|
+
const command = EDIT_COMMANDS[task];
|
|
267
|
+
const others = [
|
|
268
|
+
...VISUAL_OPTIONS.filter((name) => name !== 'resolution'),
|
|
269
|
+
...MUSIC_OPTIONS,
|
|
270
|
+
...SFX_OPTIONS,
|
|
271
|
+
...SPEECH_OPTIONS,
|
|
272
|
+
'duration',
|
|
273
|
+
'format',
|
|
274
|
+
];
|
|
275
|
+
if (task !== 'upscale-image')
|
|
276
|
+
others.push('scale');
|
|
277
|
+
if (task !== 'upscale-video')
|
|
278
|
+
others.push('resolution');
|
|
279
|
+
refuse(v, others, command);
|
|
280
|
+
const input = {
|
|
281
|
+
kind: 'edit',
|
|
282
|
+
task,
|
|
283
|
+
...(v.model ? { model: v.model } : {}),
|
|
284
|
+
};
|
|
285
|
+
if (task === 'upscale-image' && v.scale !== undefined) {
|
|
286
|
+
const scale = Number(v.scale.replace(/x$/i, ''));
|
|
287
|
+
if (![1, 2, 4, 8].includes(scale)) {
|
|
288
|
+
throw usageError('--scale must be 1, 2, 4 or 8.');
|
|
289
|
+
}
|
|
290
|
+
input.upscaleFactor = scale;
|
|
291
|
+
}
|
|
292
|
+
if (task === 'upscale-video' && v.resolution !== undefined) {
|
|
293
|
+
const resolution = v.resolution.toUpperCase();
|
|
294
|
+
if (!VIDEO_UPSCALE_RESOLUTIONS.includes(resolution)) {
|
|
295
|
+
throw usageError('--resolution must be 1080P, 2K or 4K.');
|
|
296
|
+
}
|
|
297
|
+
input.resolution = resolution;
|
|
298
|
+
}
|
|
299
|
+
const quoted = quotedCredits(v);
|
|
300
|
+
if (quoted !== undefined)
|
|
301
|
+
input.quotedCredits = quoted;
|
|
302
|
+
return input;
|
|
303
|
+
}
|
|
304
|
+
/** `--models a,b[,c,d]` for `makemidas compare`. */
|
|
305
|
+
export function compareModels(value) {
|
|
306
|
+
const models = (value ?? '')
|
|
307
|
+
.split(',')
|
|
308
|
+
.map((id) => id.trim())
|
|
309
|
+
.filter(Boolean);
|
|
310
|
+
if (models.length < 2 || models.length > 4) {
|
|
311
|
+
throw usageError('Give 2 to 4 image models: `--models a,b[,c,d]`.');
|
|
312
|
+
}
|
|
313
|
+
if (new Set(models).size !== models.length) {
|
|
314
|
+
throw usageError('--models must be different models.');
|
|
315
|
+
}
|
|
316
|
+
return models;
|
|
317
|
+
}
|
|
318
|
+
export function compareOptions(v) {
|
|
319
|
+
refuse(v, [
|
|
320
|
+
'model',
|
|
321
|
+
'resolution',
|
|
322
|
+
'count',
|
|
323
|
+
'style',
|
|
324
|
+
'enhance',
|
|
325
|
+
'frame-mode',
|
|
326
|
+
'audio',
|
|
327
|
+
'duration',
|
|
328
|
+
...MUSIC_OPTIONS,
|
|
329
|
+
...SFX_OPTIONS,
|
|
330
|
+
...SPEECH_OPTIONS,
|
|
331
|
+
'scale',
|
|
332
|
+
'format',
|
|
333
|
+
], 'compare');
|
|
334
|
+
}
|
|
335
|
+
const FEEDBACK_KINDS = ['bug', 'feature', 'praise', 'other'];
|
|
336
|
+
export function feedbackKind(value) {
|
|
337
|
+
const kind = value ?? 'other';
|
|
338
|
+
if (!FEEDBACK_KINDS.includes(kind)) {
|
|
339
|
+
throw usageError('--kind must be bug, feature, praise or other.');
|
|
340
|
+
}
|
|
341
|
+
return kind;
|
|
342
|
+
}
|