cog icon indicating copy to clipboard operation
cog copied to clipboard

idea: interactive mode for the `cog predict` command

Open zeke opened this issue 3 years ago • 4 comments
trafficstars

Using the cog predict CLI command requires you to know the inputs to the model, which in turn requires reading the docs or the source for the model. It would be neat if there was an interactive mode for running predictions, so you could just jump in without doing any homework first.

So as an alternative to this:

$ cog predict -i [email protected] -i scale=4

You could some something like this:

$ cog predict --interactive

> Enter a path for `image`: @foo.jpg
> Enter a value for `scale` (min:0, max:10): 4

zeke avatar Jan 21 '22 18:01 zeke

This might be of use: https://github.com/AlecAivazis/survey

A [go] library for building interactive and accessible prompts on terminals supporting ANSI escape sequences

floer32 avatar Feb 06 '22 03:02 floer32

cc @nicholascelestin who had some feedback and suggestions on how a feature like this could work: https://github.com/replicate/cog/issues/649#issuecomment-1162377513

zeke avatar Jun 22 '22 18:06 zeke

For clarity, #649 was a subtly different thing: the need there was to run predict multiple times without having to call setup() again. The need expressed in this issue is making the inputs discoverable interactively.

The solution could be similar, but there are two distinct user needs.

bfirsh avatar Jun 22 '22 19:06 bfirsh

Like @zeke pointed out, I think it's possible to have interactive mode reference the OpenAPI schema, tell you what model you're working with, and interactively prompt you for [input name] of [input type] for all inputs.

It'd just be annoying to have fill all those out for every prediction, so it'd still be useful to pass in inputs with the -i flag, for ones you want to be static.

cog predict --interactive You are using cog in interactive mode for model {model_name}! You launched interactive mode with no inputs, so you will be prompted to enter all model inputs for each prediction. To launch interactive mode with some inputs pre-filled (you won't be prompted for them), pass inputs with the -i flag; e.g. cog predict --interactive -i scale=5 Enter 'Text To Image Prompt' (str): ___________________

It'd either print the model's output or save the output to the disk, depending on whether an output flag was passed. And then it'd prompt you for inputs again.

It could also support 'exit' / 'quit' keywords for when you were done. And it would be ideal if the interactive mode had a way to output or ignore logs for setup and prediction. And if it didn't crash because of a run-time python error in the predictor. That'd make it more handy for debugging.

It would be cool, but could be hard to write different logic for different input types.

Enter 'Scale' (float min:1 max:10): ___________________ Enter 'Size' (str): 256x256 ↓ (dropdown for choices) Enter init image (filepath or url): ___________

So maybe not for a first pass.

nicholascelestin avatar Jun 24 '22 04:06 nicholascelestin