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 genreated 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.2.tar.gz (8.3 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: cogreqs-0.0.2.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.9.2

File hashes

Hashes for cogreqs-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f8895e8daef10d7b832ab5c5f872488a710abaa6263ca4edabb71c69a0c8a5ff
MD5 ad48d3d88698c76ff08a325bce8765ee
BLAKE2b-256 a269284639e0db970108352b840456095f9d60fc7ff74774cf9cb920d176d2be

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