Skip to content

Instantly share code, notes, and snippets.

@andreasjansson
Created January 25, 2023 09:49
Show Gist options
  • Save andreasjansson/563c06035a492ba2e071370392296c49 to your computer and use it in GitHub Desktop.
Save andreasjansson/563c06035a492ba2e071370392296c49 to your computer and use it in GitHub Desktop.
Develop inside Cog container

Develop inside Cog container

Start a shell inside the container:

cog run bash

This will mount your working directory into /src inside the container.

When the shell has started, install ipython:

pip install ipython

Start ipython:

ipython

Inside ipython, enable autoreload:

%load_ext autoreload
%autoreload 2

Files you edit inside your working directory will now be changed inside the ipython environment.

Load the predictor:

from predict import Predictor
p = Predictor()
p.setup()

Make a prediction (note that all predict inputs need to be specified, even if they have defaults):

out = p.predict(prompt="a cat", guidance_scale=7.5, seed=0)

To pass in files, use pathlib.Path:

from pathlib import Path
out = p.predict(init_image=Path("my-image.png"), prompt="a cat", guidance_scale=7.5, seed=0)

You can now edit the predict function and see the changes when you run p.predict(), without having to reload the model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment