Skip to content

Commit

Permalink
v0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
tacomilkshake committed Oct 8, 2022
1 parent 992c729 commit 9b38a03
Show file tree
Hide file tree
Showing 22 changed files with 1,299 additions and 211 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ vendor/
# Go workspace file
go.work

# Binary
replicate
# Misc
.DS_Store
98 changes: 78 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,120 @@
# replicate-cli
Command line interface for the Replicate API, powered by Go.
Command line interface for the [Replicate API](https://replicate.com/docs/reference/http), powered by Go.

### Version 0.1.0 - Experimental Support
Run open source AI models from the command line using [Replicate.com's](https://replicate.com) hardware.

Run models and retrieves model version IDs. See TODO for proposed feature list. Currently only supports models that accept a single "image" input. **Note: Stable Diffusion and other text input models are not yet supported, but will be soon. Executable name may change to replicate, from replicate-cli.**
## Features

Version 0.2.2 - Expanded model support + chaining

* Run models
* Chaining: pass the output of one model to another replicate command
* URL or Local file support
* Get model info
* Get model input parameters
* Get model versions

## Requirements
* Go 1.19
* Replicate API Token, [get yours here](https://replicate.com/account).

## Install, Build & Run
## Installation

### Install
[go](https://go.dev/dl/) is required.
```
go install github.com/jamiesteven/replicate-cli@latest
go install github.com/jamiesteven/replicate-cli/cmd/replicate@latest
```

### Run
```
replicate-cli
replicate
```

### Uninstall
```
rm $GOPATH/bin/replicate-cli
rm $GOPATH/bin/replicate
```

## How to use
## Usage

### Authentication
The Replicate API requires an API token. [Get one here.](https://replicate.com/account).
The Replicate API requires an API token. [Get one here.](https://replicate.com/account)

Set a ```REPLICATE_TOKEN``` environment variable, or use ```--token <your key here>```.
```
replicate-cli --token <your key here>
replicate --token <your key here>
```

### Get model versions
### Input Parameters
Input parameters use the [shorthand](https://github.com/danielgtaylor/shorthand) format, separated by comma.
```
replicate-cli versions jingyunliang/swinir
image:https://picsum.photos/512/512, fidelity:0.4
```

### Run a model
### run: run a model
```
replicate run [model] [inputs]
```

#### Run a model with parameter input
```
replicate run stability-ai/stable-diffusion prompt:photo of a cat
```

**Run using model name.** replicate-cli will use the latest version.
#### Run a model using an image URL
```
replicate-cli run jingyunliang/swinir [input]
replicate run jingyunliang/swinir image:https://picsum.photos/512/512
```
Input currently supports a fully qualified domain-name.

**Run using version ID.**
#### Run a model using using a local image
```
replicate-cli run jingyunliang/swinir
replicate run jingyunliang/swinir image:/path/to/file.png
```

### Chaining: run multiple AI models in succession
Pipe the output of one replicate command to another:
```
replicate run stability-ai/stable-diffusion prompt:photo of a smiling person \
| replicate run jingyunliang/swinir image: \
| replicate run sczhou/codeformer codeformer_fidelity:0.4, upscale:1, image:
```

### info: get model info
```
replicate info [model]
replicate info stability-ai/stable-diffusion
```

### inputs: get inputs for a specific model
```
replicate inputs [model] [?version]
replicate inputs jingyunliang/swinir
replicate inputs jingyunliang/swinir 9d91795e944f3a585fa83f749617fc75821bea8b323348f39cf84f8fd0cbc2f7
```

### versions: get versions for a specific model
```
replicate versions [model]
replicate versions jingyunliang/swinir
```

## Development
Pull requests welcome! replicate-cli is built using [Cobra](https://cobra.dev).
Pull requests welcome!

## Credits

replicate-cli uses the following packages:

---
* [cobra](https://github.com/spf13/cobra)
* [shorthand](https://github.com/danielgtaylor/shorthand)
* [resty](https://github.com/go-resty/resty)
* [gjson](https://github.com/tidwall/gjson)
* [tablewritter](https://github.com/olekukonko/tablewriter)
* [spinner](https://github.com/briandowns/spinner)

**Copyright (c) 2022 Jamie Steven. Licensed Under Apache 2.0.**
44 changes: 32 additions & 12 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
v0.1.0
v0.1.x
Experimental support
Code cleanup
Document code where needed
Publish to GitHub with license
"Release in GitHub"

v0.2.0
Support text models, like Stable Diffusion
Support models with unique inputs using via flags or arguments
Add local file support as image input
Save output to local file
Consider normalizing model output (always wrap in JSON?)
v0.2.x
Change to 'replicate' as primary command, from 'replicate-cli'
run command: run a model
Support most models with command line parameter support
Shorthand support for inputting parameters using https://github.com/danielgtaylor/shorthand
Command chaining: run commands supports piping input from one replicate command to another
Support local file as image input
Normalize model output to output as a standardized URL
Improved waiting indicator
info command: get info about models
input command: get the inputs for a specific model
Normalize errors
Add known issues
Give credit to primary packages

v0.?
Tests?
Improved documentation?
Packagecloud binary support?
v0.3.0 (or later)
Optionally save output to local file
Explore support for non-image models, like Whisper
start command - run model asynchronously
predictions command - list, view and stop predictions
models/collections command - list and view models
Provide shorthand input examples for each model
Improved documentation for each command
Notate required fields on inputs
Pre-compiled binary support (Packagecloud, Homebrew tap, etc)
Tests

Known issues:
Currently does not support the output of multiple images; Replicate API issue?
Does not support image URL paths that includes commas - shorthand uses commas to delineate args

Notes:
Suggest Replicate team return 404 for https://api.replicate.com/v1/predictions on non-existant version IDs
Suggest Replicate team return 404 for https://api.replicate.com/v1/predictions on non-existent version IDs
9 changes: 9 additions & 0 deletions cmd/replicate/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import (
cmd "github.com/jamiesteven/replicate-cli/internal/cmd"
)

func main() {
cmd.Execute()
}
95 changes: 0 additions & 95 deletions cmd/run.go

This file was deleted.

49 changes: 0 additions & 49 deletions cmd/versions.go

This file was deleted.

14 changes: 9 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ go 1.19

require (
github.com/briandowns/spinner v1.19.0
github.com/danielgtaylor/shorthand v1.1.0
github.com/go-resty/resty/v2 v2.7.0
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/cobra v1.5.0
github.com/tidwall/gjson v1.14.3
)

require (
github.com/fatih/color v1.13.0 // indirect
github.com/fatih/color v1.7.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.8 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect
golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2 // indirect
golang.org/x/net v0.0.0-20220926192436-02166a98028e // indirect
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
Loading

0 comments on commit 9b38a03

Please sign in to comment.