Skip to content

Commit

Permalink
Merge pull request #4 from zeke/allow-extra-flags-as-inputs-to-the-model
Browse files Browse the repository at this point in the history
feat: allow extra flags as inputs to the model
  • Loading branch information
zeke authored Sep 18, 2024
2 parents 32dd15c + cfbc22b commit 674ef24
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
output-*
*.webp
*.webp
*.jpg
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ If you want more images, use the `--count` option:
aimg "cute cat" --count 20
```

## Extra flags as inputs to the model

Any extra flags you pass will be passed along to the model as input. For example, if the model takes an `output_format` input, you can pass it like this:

```
aimg "cute cat" --output_format jpg
```

### Random prompts

If you want generate a different semi-random prompt for each image, specify a `subject` and it will use [promptmaker](https://npm.im/promptmaker) to generate random prompts:
Expand Down
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const subject = argv.subject
const outputDir = argv.outputdir || '.'

if (!prompt && !subject) {
console.log('Usage: aimg <prompt> [--count 3] [--model black-forest-labs/flux-schnell] [--subject <subject>] [--outputdir output-<timestamp>]')
console.log('Usage: aimg <prompt> [--count 3] [--model black-forest-labs/flux-schnell] [--subject <subject>] [--outputdir output-<timestamp>] [--<flag> <value>...]')
process.exit()
}

Expand All @@ -25,5 +25,14 @@ for (let i = 0; i < count; i++) {
prompt = promptmaker({ subject })
}

run({ model, prompt, outputDir })
const input = { prompt }

// Add arbitrary CLI flags to the input object
for (const [key, value] of Object.entries(argv)) {
if (!['_', 'count', 'model', 'subject', 'outputdir'].includes(key)) {
input[key] = value
}
}

run({ model, input, outputDir })
}
4 changes: 1 addition & 3 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ async function getModelFullNameWithVersion (model) {
throw new Error('Invalid model format. Expected "owner/name".')
}

export async function run ({ model, prompt, outputDir }) {
const input = { prompt }

export async function run ({ model, input, outputDir }) {
let output
let prediction
try {
Expand Down

0 comments on commit 674ef24

Please sign in to comment.