jpskill.com
🎨 画像AI コミュニティ

replicate

APIを通じてクラウド上で機械学習モデルを実行し、画像生成や言語処理など多様なオープンソースモデルを利用したり、独自のデータでモデルを調整・デプロイしたりできるSkill。

📜 元の英語説明(参考)

Run machine learning models in the cloud via API. Access thousands of open-source models for image generation, language, audio, and video. Fine-tune models on custom data and deploy custom models with Cog packaging format.

🇯🇵 日本人クリエイター向け解説

一言でいうと

APIを通じてクラウド上で機械学習モデルを実行し、画像生成や言語処理など多様なオープンソースモデルを利用したり、独自のデータでモデルを調整・デプロイしたりできるSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o replicate.zip https://jpskill.com/download/15339.zip && unzip -o replicate.zip && rm replicate.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15339.zip -OutFile "$d\replicate.zip"; Expand-Archive "$d\replicate.zip" -DestinationPath $d -Force; ri "$d\replicate.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して replicate.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → replicate フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Replicate

インストール

# Python クライアントをインストール
pip install replicate

# API トークンを設定
export REPLICATE_API_TOKEN="r8_xxxxxxxxxxxx"

モデルの実行

# run_model.py — モデルを実行して出力を取得
import replicate

# Stable Diffusion XL を実行
output = replicate.run(
    "stability-ai/sdxl:7762fd07cf82c948538e41f63f77d685e02b063e37e496e96eefd46c929f9bdc",
    input={
        "prompt": "夕暮れ時の未来的な都市景観、デジタルアート",
        "negative_prompt": "ぼやけ、低品質",
        "width": 1024,
        "height": 1024,
        "num_outputs": 1,
    },
)

# 出力は URL のリスト
for url in output:
    print(url)

言語モデルの実行

# run_llm.py — Replicate 経由でオープンソース LLM を実行
import replicate

# ストリーミングで Llama を実行
for event in replicate.stream(
    "meta/llama-2-70b-chat",
    input={
        "prompt": "機械学習を5歳児に説明してください",
        "system_prompt": "あなたは親切な先生です。",
        "max_new_tokens": 500,
        "temperature": 0.7,
    },
):
    print(str(event), end="", flush=True)

非同期予測

# async_prediction.py — 予測を送信して結果をポーリング
import replicate
import time

# 待たずに予測を作成
prediction = replicate.predictions.create(
    model="stability-ai/sdxl",
    input={"prompt": "宇宙にいる猫"},
)
print(f"Prediction ID: {prediction.id}")
print(f"Status: {prediction.status}")

# 完了までポーリング
while prediction.status not in ("succeeded", "failed", "canceled"):
    time.sleep(2)
    prediction.reload()
    print(f"Status: {prediction.status}")

if prediction.status == "succeeded":
    print(f"Output: {prediction.output}")

Webhook

# webhook_prediction.py — Webhook 経由で予測が完了したときに通知を受け取る
import replicate

prediction = replicate.predictions.create(
    model="stability-ai/sdxl",
    input={"prompt": "山の風景"},
    webhook="https://myapp.com/api/replicate-webhook",
    webhook_events_filter=["completed"],
)
print(f"Prediction started: {prediction.id}")

ファイン・チューニング

# fine_tune.py — カスタム画像で SDXL をファイン・チューニング
import replicate

# ファイン・チューン学習を作成
training = replicate.trainings.create(
    version="stability-ai/sdxl:7762fd07cf82c948538e41f63f77d685e02b063e37e496e96eefd46c929f9bdc",
    input={
        "input_images": "https://my-bucket.s3.amazonaws.com/training-images.zip",
        "token_string": "TOK",
        "caption_prefix": "TOK の写真, ",
        "max_train_steps": 1000,
        "use_face_detection_instead": False,
    },
    destination="my-username/my-sdxl-model",
)

print(f"Training ID: {training.id}")
print(f"Status: {training.status}")

# 学習ステータスを確認
training.reload()
print(f"Status: {training.status}")
print(f"Model version: {training.output.get('version')}")

Cog を使用したカスタムモデルのデプロイ

# cog.yaml — Cog パッケージング用のモデル環境を定義
build:
  python_version: "3.11"
  python_packages:
    - torch==2.1.0
    - transformers==4.36.0
  gpu: true
predict: "predict.py:Predictor"
# predict.py — カスタムモデルデプロイメント用の Cog 予測クラス
from cog import BasePredictor, Input, Path
from transformers import pipeline

class Predictor(BasePredictor):
    def setup(self):
        """コンテナ起動時にモデルをメモリにロード"""
        self.pipe = pipeline("text-generation", model="./model", device=0)

    def predict(
        self,
        prompt: str = Input(description="入力テキストプロンプト"),
        max_tokens: int = Input(description="生成する最大トークン数", default=100, ge=1, le=1000),
        temperature: float = Input(description="サンプリング温度", default=0.7, ge=0, le=2),
    ) -> str:
        """単一の予測を実行"""
        output = self.pipe(prompt, max_new_tokens=max_tokens, temperature=temperature)
        return output[0]["generated_text"]
# Cog を使用してカスタムモデルを構築およびプッシュ
pip install cog

# ローカルでテスト
cog predict -i prompt="Hello world"

# Replicate にプッシュ
cog login
cog push r8.im/my-username/my-model

Node.js クライアント

// replicate_node.ts — Node.js から Replicate を使用
import Replicate from "replicate";

const replicate = new Replicate({ auth: process.env.REPLICATE_API_TOKEN });

const output = await replicate.run("stability-ai/sdxl", {
  input: {
    prompt: "ロボットの水彩画",
    width: 1024,
    height: 1024,
  },
});

console.log(output);

主要な概念

  • バージョンの固定: モデルは SHA によってバージョン管理されます — 再現性のためにバージョンを固定します
  • コールドスタート: モデルへの最初の要求は、起動に 10〜60 秒かかる場合があります。後続の呼び出しは高速になります
  • ストリーミング: 言語モデルからのリアルタイムのトークン出力には replicate.stream() を使用します
  • Cog: Replicate 用に ML モデルを Docker コンテナとしてパッケージ化するためのオープンソースツール
  • Webhook: 予測が完了したときに HTTP コールバックを受信して、ポーリングを回避します
  • 価格設定: コンピューティングの秒単位で支払い。 GPU タイプはモデルによって異なります
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Replicate

Installation

# Install Python client
pip install replicate

# Set API token
export REPLICATE_API_TOKEN="r8_xxxxxxxxxxxx"

Run a Model

# run_model.py — Run a model and get the output
import replicate

# Run Stable Diffusion XL
output = replicate.run(
    "stability-ai/sdxl:7762fd07cf82c948538e41f63f77d685e02b063e37e496e96eefd46c929f9bdc",
    input={
        "prompt": "A futuristic cityscape at sunset, digital art",
        "negative_prompt": "blurry, low quality",
        "width": 1024,
        "height": 1024,
        "num_outputs": 1,
    },
)

# Output is a list of URLs
for url in output:
    print(url)

Run Language Models

# run_llm.py — Run open-source LLMs via Replicate
import replicate

# Run Llama with streaming
for event in replicate.stream(
    "meta/llama-2-70b-chat",
    input={
        "prompt": "Explain machine learning to a 5-year-old",
        "system_prompt": "You are a friendly teacher.",
        "max_new_tokens": 500,
        "temperature": 0.7,
    },
):
    print(str(event), end="", flush=True)

Async Predictions

# async_prediction.py — Submit a prediction and poll for results
import replicate
import time

# Create prediction without waiting
prediction = replicate.predictions.create(
    model="stability-ai/sdxl",
    input={"prompt": "A cat in space"},
)
print(f"Prediction ID: {prediction.id}")
print(f"Status: {prediction.status}")

# Poll for completion
while prediction.status not in ("succeeded", "failed", "canceled"):
    time.sleep(2)
    prediction.reload()
    print(f"Status: {prediction.status}")

if prediction.status == "succeeded":
    print(f"Output: {prediction.output}")

Webhooks

# webhook_prediction.py — Get notified when a prediction completes via webhook
import replicate

prediction = replicate.predictions.create(
    model="stability-ai/sdxl",
    input={"prompt": "A mountain landscape"},
    webhook="https://myapp.com/api/replicate-webhook",
    webhook_events_filter=["completed"],
)
print(f"Prediction started: {prediction.id}")

Fine-Tuning

# fine_tune.py — Fine-tune SDXL on custom images
import replicate

# Create a fine-tune training
training = replicate.trainings.create(
    version="stability-ai/sdxl:7762fd07cf82c948538e41f63f77d685e02b063e37e496e96eefd46c929f9bdc",
    input={
        "input_images": "https://my-bucket.s3.amazonaws.com/training-images.zip",
        "token_string": "TOK",
        "caption_prefix": "a photo of TOK, ",
        "max_train_steps": 1000,
        "use_face_detection_instead": False,
    },
    destination="my-username/my-sdxl-model",
)

print(f"Training ID: {training.id}")
print(f"Status: {training.status}")

# Check training status
training.reload()
print(f"Status: {training.status}")
print(f"Model version: {training.output.get('version')}")

Deploy Custom Models with Cog

# cog.yaml — Define model environment for Cog packaging
build:
  python_version: "3.11"
  python_packages:
    - torch==2.1.0
    - transformers==4.36.0
  gpu: true
predict: "predict.py:Predictor"
# predict.py — Cog predictor class for custom model deployment
from cog import BasePredictor, Input, Path
from transformers import pipeline

class Predictor(BasePredictor):
    def setup(self):
        """Load model into memory during container startup"""
        self.pipe = pipeline("text-generation", model="./model", device=0)

    def predict(
        self,
        prompt: str = Input(description="Input text prompt"),
        max_tokens: int = Input(description="Max tokens to generate", default=100, ge=1, le=1000),
        temperature: float = Input(description="Sampling temperature", default=0.7, ge=0, le=2),
    ) -> str:
        """Run a single prediction"""
        output = self.pipe(prompt, max_new_tokens=max_tokens, temperature=temperature)
        return output[0]["generated_text"]
# Build and push a custom model with Cog
pip install cog

# Test locally
cog predict -i prompt="Hello world"

# Push to Replicate
cog login
cog push r8.im/my-username/my-model

Node.js Client

// replicate_node.ts — Use Replicate from Node.js
import Replicate from "replicate";

const replicate = new Replicate({ auth: process.env.REPLICATE_API_TOKEN });

const output = await replicate.run("stability-ai/sdxl", {
  input: {
    prompt: "A watercolor painting of a robot",
    width: 1024,
    height: 1024,
  },
});

console.log(output);

Key Concepts

  • Version pinning: Models are versioned by SHA — pin versions for reproducibility
  • Cold starts: First request to a model may take 10-60s to boot; subsequent calls are faster
  • Streaming: Use replicate.stream() for real-time token output from language models
  • Cog: Open-source tool to package ML models as Docker containers for Replicate
  • Webhooks: Avoid polling by receiving HTTP callbacks when predictions complete
  • Pricing: Pay per second of compute; GPU type depends on the model