Skip to main content

Automatically construct cog.yaml from a repository

Project description

Cogreqs

Cogreqs is an experimental drop-in replacement for cog init that intelligently populates cog.yaml.

Installation

pip install cogreqs

Usage

Run the following command in an existing Python repository:

$ cogreqs --gpu .

Wrote cog.yaml
Wrote predict.py

cog.yaml may now contain something like

# Configuration for Cog ⚙
# Reference: https://github.com/replicate/cog/blob/main/docs/yaml.md

build:
  # set to true if your model requires a GPU
  gpu: true

  # a list of ubuntu apt packages to install
  system_packages:
  - "ffmpeg"
  - "libsndfile-dev"

  # python version in the form '3.8' or '3.8.12'
  python_version: "3.8"

  # a list of packages in the format <package-name>==<version>
  python_packages:
  - "librosa==0.9.1"
  - "numpy==1.22.2"
  - "scipy==1.8.0"
  - "torch==1.10.2"

  # commands run after the environment is setup
  run:

NOTE: Cogreqs outputs a predict.py that's only compatible with the future branch of Cog. Until that branch is merged into main, install Cog from https://github.com/replicate/cog/releases/tag/v0.1.0-alpha

You can also output the generated cog.yaml contents to stdout:

$ cogreqs --config-path=- --predict-path=/dev/null .

# Configuration for Cog ⚙
# Reference: https://github.com/replicate/cog/blob/main/docs/yaml.md

build:
[...]

CLI reference

usage: cogreqs [-h] [-f] [-g] [--config-path CONFIG_PATH] [--predict-path PREDICT_PATH] folder

Generate cog.yaml and predict.py from an existing repository. This is an experimental alternative to
cog init

positional arguments:
  folder                Project folder

optional arguments:
  -h, --help            show this help message and exit
  -f, --force-overwrite
                        Overwrite existing cog.yaml and predict.py
  -g, --gpu             Use GPU
  --config-path CONFIG_PATH
                        Config file path (default cog.yaml)
  --predict-path PREDICT_PATH
                        Predict file path (default predict.py)

How does it work?

Cogreqs uses pipreqs to extract requirements from Python files in a repository. It then applies a sequence of heuristics on those requirements to populate python_packages and system_packages in cog.yaml.

For example, cogreqs knows that librosa requires the ffmpeg and libsndfile-dev system packages so it will add those to system_packages if librosa is one of the python requirements.

Work in progress!

This project is very much work in progress. Please submit an issue or pull request if you have ideas for heuristics or other features!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cogreqs-0.0.6.tar.gz (9.1 kB view details)

Uploaded Source

File details

Details for the file cogreqs-0.0.6.tar.gz.

File metadata

  • Download URL: cogreqs-0.0.6.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for cogreqs-0.0.6.tar.gz
Algorithm Hash digest
SHA256 fee54a89fbebe63d29700e94ea2a44881e3a31d184f78f088ecce99daa4b8e00
MD5 54099a88e92859d1e0acceff91c5d88e
BLAKE2b-256 fd988050518a758910d64ec31787db30cb638c9ec6552e12ef389e28fa7e6902

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page