JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 134
  • Score
    100M100P100Q73898F
  • License MIT

A NodeJS client for Replicate.

Package Exports

  • node-replicate
  • node-replicate/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-replicate) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

node-replicate

A NodeJS client for Replicate.

import replicate from "node-replicate"

const prediction = await replicate
  .model(
    "stability-ai/stable-diffusion:db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf",
   )
  .predict({
    prompt: "an astronaut riding on a horse",
  })

console.log(prediction.output)

// [ "https://replicate.delivery/pbxt/f4nlztv3uz1iFC4AEf2wBYQGTezdVeysvtZUtwfsvZOJDN6AC/out-0.png" ]

Introduction

Replicate is an online platform for running machine learning models in the cloud. This package implements a lightweight client for their anonymous API, allowing you to run Stable Diffusion, Midjourney and other cutting-edge models with just a few lines of code 😊👌.

Features

  • Run Replicate models anonymously 👻.
  • Track pending predictions ⌛.
  • Very lightweight - under 100 lines of code ⚡.

Installation

Install with npm.

npm i node-replicate

Usage

To run a Replicate model, pass its identifier to replicate.model() and then invoke predict() asynchronously.

import replicate from "node-replicate"

const prediction = await replicate
  .model(
    "stability-ai/stable-diffusion:db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf",
   )
  .predict({
    prompt: "an astronaut riding on a horse",
  })

console.log(prediction.output)

// [ "https://replicate.delivery/pbxt/f4nlztv3uz1iFC4AEf2wBYQGTezdVeysvtZUtwfsvZOJDN6AC/out-0.png" ]

You can also track a pending predictions by passing an onUpdate() callback.

import replicate from "node-replicate"

const prediction = await replicate
  .model(
    "stability-ai/stable-diffusion:db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf",
   )
  .predict(
    {
      prompt: "an astronaut riding on a horse",
    },
    {
      onUpdate(prediction) {
        console.log(prediction.status)
      }
    },
  )

console.log(prediction.output)

// [ "https://replicate.delivery/pbxt/f4nlztv3uz1iFC4AEf2wBYQGTezdVeysvtZUtwfsvZOJDN6AC/out-0.png" ]

Examples

1. Visual Question-answering with blip

import replicate from "node-replicate"

const prediction = await replicate
  .model(
    "salesforce/blip:2e1dddc8621f72155f24cf2e0adbde548458d3cab9f00c0139eea840d0ac4746",
   )
  .predict({
    image: 'https://replicate.delivery/pbxt/IVSaMZb8iBkELQvQya84wz5i1YfQC1HxrtSfSaL4QRTtsOlP/cat.jpg',
    question: "What color is the cat?",
    task: "visual_question_answering",
  })

console.log(prediction.output)

// "Answer: orange"

2. Image Style Transfer with clipstyler

import replicate from "node-replicate"

const prediction = await replicate
  .model(
    "salesforce/blip:2e1dddc8621f72155f24cf2e0adbde548458d3cab9f00c0139eea840d0ac4746",
   )
  .predict({
    image: "https://replicate.delivery/pbxt/IVSrp3308R8Uq0sJx6yAozDSuLswkkq6IlaOS5liUI7TCwAU/cat.jpg",
    iterations: 100,
    text: "made from leaves",
  })

console.log(prediction.output)

// [ ... ]

Contributing

Have a feature you'd like to see added? Create a pull request or open an issue.