mcpField
M
modelslab-deepfake

modelslab-deepfake

github.com/modelslabクリエイティブ・メディア1384 回インストール36 週間前に更新
リポジトリ

modelslab-deepfake について

ModelsLab API を利用する開発者向けの、画像・動画の顔交換スキルです。特定の顔や複数の顔を扱い、動画の非同期処理にも対応します。

主な機能

  1. 01画像内の特定の顔を交換
  2. 02画像内の複数の顔を交換
  3. 03動画内の顔または指定した顔を交換
  4. 04ポーリングまたは Webhook で結果を取得

活用シーン

  1. 01プロフィール画像のバリエーション作成
  2. 02テンプレート動画のパーソナライズ
  3. 03複数人が写る画像や動画の編集

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/modelslab/skills --skill modelslab-deepfake

インストール後、Claude Code で/modelslab-deepfakeを入力して読み込まれたか確認します。

詳細

ModelsLab ディープフェイクと顔の入れ替え

高度なAI搭載ディープフェイク技術を使用して、画像や動画の顔を入れ替えます。

このスキルを使用する場面

  • 写真の顔を入れ替える
  • 動画の顔を置き換える
  • パーソナライズされた動画コンテンツを作成する
  • キャラクターのバリエーションを生成する
  • 顔入れ替えアプリケーションを構築する
  • エンターテインメントコンテンツを作成する

利用可能なエンドポイント

画像の顔入れ替え
  • 特定の顔の入れ替え:POST https://modelslab.com/api/v6/deepfake/specific_face_swap
  • 複数の顔の入れ替え:POST https://modelslab.com/api/v6/deepfake/multiple_face_swap
動画の顔入れ替え
  • 単一動画の入れ替え:POST https://modelslab.com/api/v6/deepfake/single_video_swap
  • 特定の動画の入れ替え:POST https://modelslab.com/api/v6/deepfake/specific_video_swap

特定の顔の入れ替え(画像)

import requests

def swap_face(target_image, face_to_use, api_key):
    """Swap a face in an image.

    Args:
        target_image: URL of the image containing face to replace
        face_to_use: URL of the image with face to swap in
        api_key: Your ModelsLab API key

    Returns:
        URL of the face-swapped image
    """
    response = requests.post(
        "https://modelslab.com/api/v6/deepfake/specific_face_swap",
        json={
            "key": api_key,
            "init_image": target_image,
            "target_image": face_to_use
        }
    )

    data = response.json()

    if data["status"] == "success":
        return data["output"][0]
    else:
        raise Exception(f"Error: {data.get('message', 'Unknown error')}")

# Usage
result = swap_face(
    "https://example.com/target-photo.jpg",  # Photo to modify
    "https://example.com/face-to-swap.jpg",  # Face to insert
    "your_api_key"
)
print(f"Face swapped image: {result}")

複数の顔の入れ替え(画像)

def swap_multiple_faces(image_with_faces, face_to_use, api_key):
    """Swap all faces in an image with the same face.

    Args:
        image_with_faces: URL of image with multiple faces
        face_to_use: URL of face to swap in
    """
    response = requests.post(
        "https://modelslab.com/api/v6/deepfake/multiple_face_swap",
        json={
            "key": api_key,
            "init_image": image_with_faces,
            "target_image": face_to_use
        }
    )

    data = response.json()

    if data["status"] == "success":
        return data["output"][0]
    else:
        raise Exception(data.get("message"))

# Swap all faces in group photo
result = swap_multiple_faces(
    "https://example.com/group-photo.jpg",
    "https://example.com/celebrity-face.jpg",
    "your_api_key"
)

単一動画の顔入れ替え

import time

def swap_video_faces(video_url, face_image, api_key, output_format="mp4"):
    """Swap all faces in a video.

    Args:
        video_url: URL of the video
        face_image: URL of face to swap in
        output_format: "mp4" or "gif"

    Returns:
        URL of the face-swapped video
    """
    response = requests.post(
        "https://modelslab.com/api/v6/deepfake/single_video_swap",
        json={
            "key": api_key,
            "init_video": video_url,
            "target_image": face_image,
            "output_format": output_format,
            "watermark": False  # Set to True for watermark
        }
    )

    data = response.json()

    if data["status"] == "error":
        raise Exception(f"Error: {data['message']}")

    if data["status"] == "success":
        return data["output"][0]

    # Video processing is async
    request_id = data["id"]
    print(f"Video processing... Request ID: {request_id}")

    return poll_deepfake_result(request_id, api_key)

def poll_deepfake_result(request_id, api_key, timeout=900):
    """Poll for video face swap results."""
    start_time = time.time()

    while time.time() - start_time < timeout:
        fetch = requests.post(
            f"https://modelslab.com/api/v6/deepfake/fetch/{request_id}",
            json={"key": api_key}
        )
        result = fetch.json()

        if result["status"] == "success":
            return result["output"][0]
        elif result["status"] == "failed":
            raise Exception(result.get("message", "Failed"))

        print(f"Processing... ({int(time.time() - start_time)}s)")
        time.sleep(10)

    raise Exception("Timeout")

# Usage
swapped_video = swap_video_faces(
    "https://example.com/video.mp4",
    "https://example.com/face.jpg",
    "your_api_key"
)
print(f"Face-swapped video: {swapped_video}")

特定の動画の顔入れ替え

def swap_specific_video_face(video_url, new_face, reference_face, api_key):
    """Swap a specific face in a video (when multiple faces present).

    Args:
        video_url: URL of the video
        new_face: URL of the face to swap in
        reference_face: URL of the specific face to replace
    """
    response = requests.post(
        "https://modelslab.com/api/v6/deepfake/specific_video_swap",
        json={
            "key": api_key,
            "init_video": video_url,
            "target_image": new_face,
            "source_image": reference_face,
            "output_format": "mp4",
            "watermark": False
        }
    )

    data = response.json()

    if data["status"] == "processing":
        return poll_deepfake_result(data["id"], api_key)
    elif data["status"] == "success":
        return data["output"][0]
    else:
        raise Exception(data.get("message"))

# Swap only one person's face in multi-person video
result = swap_specific_video_face(
    "https://example.com/interview.mp4",
    "https://example.com/new-face.jpg",
    "https://example.com/face-to-replace.jpg",
    "your_api_key"
)

Webhook の使用

def deepfake_with_webhook(video_url, face_image, api_key, webhook_url, track_id):
    """Process video face swap with webhook notification."""
    response = requests.post(
        "https://modelslab.com/api/v6/deepfake/single_video_swap",
        json={
            "key": api_key,
            "init_video": video_url,
            "target_image": face_image,
            "output_format": "mp4",
            "webhook": webhook_url,
            "track_id": track_id
        }
    )

    data = response.json()
    print(f"Request submitted: {data['id']}")
    return data["id"]

# Usage
request_id = deepfake_with_webhook(
    "https://example.com/video.mp4",
    "https://example.com/face.jpg",
    "your_api_key",
    "https://yourserver.com/webhook/deepfake",
    "video_001"
)

主なパラメーター

パラメーター説明値
init_image変更対象の画像画像 URL
init_video変更対象の動画動画 URL
target_image入れ替え先の顔顔がはっきり写った画像 URL
source_image置き換える特定の顔画像 URL(特定の入れ替え用)
output_format動画の出力形式mp4 または gif
watermark透かしを追加するtrue または false
webhook非同期コールバック URLお使いのサーバーのエンドポイント
track_idリクエスト識別子一意の追跡 ID

ベストプラクティス

1. 高品質な顔画像を使用する
✓ Good: Clear, well-lit frontal face photo
✓ Good: High resolution (at least 512x512)
✓ Good: Neutral expression works best

✗ Avoid: Blurry or low-resolution images
✗ Avoid: Extreme angles or profiles
✗ Avoid: Heavy shadows or poor lighting
2. 動画の顔入れ替えに関する要件
  • 動画内の顔がはっきりと見えること
  • 照明条件が良好であること
  • 正面または正面に近い角度が最適です
  • 動画が短いほど処理が速くなります
3. 非同期処理を処理する
# Video face swaps are ALWAYS async
if data["status"] == "processing":
    result = poll_deepfake_result(data["id"], api_key)
4. 適切なタイムアウトを設定する
# Video processing takes time
poll_deepfake_result(request_id, api_key, timeout=900)  # 15 minutes
5. 長い動画には Webhook を使用する
# Don't poll for long videos, use webhooks
deepfake_with_webhook(video_url, face, api_key, webhook_url, track_id)

よくあるユースケース

プロフィール画像ジェネレーター
def create_profile_variations(base_photo, face_images, api_key):
    """Generate multiple profile picture variations."""
    variations = []

    for i, face in enumerate(face_images):
        result = swap_face(base_photo, face, api_key)
        variations.append(result)
        print(f"Variation {i+1} created: {result}")

    return variations

# Create variations
profiles = create_profile_variations(
    "https://example.com/professional-photo.jpg",
    [
        "https://example.com/style1-face.jpg",
        "https://example.com/style2-face.jpg",
        "https://example.com/style3-face.jpg"
    ],
    api_key
)
動画のパーソナライズ
def personalize_video(template_video, user_face, api_key):
    """Create personalized video with user's face."""
    personalized = swap_video_faces(
        template_video,
        user_face,
        api_key,
        output_format="mp4"
    )
    print(f"Personalized video: {personalized}")
    return personalized

# Create custom greeting video
greeting = personalize_video(
    "https://example.com/greeting-template.mp4",
    "https://example.com/user-photo.jpg",
    api_key
)
キャラクターのバリエーション
def generate_character_variations(character_image, face_options, api_key):
    """Generate different character variations."""
    characters = []

    for face in face_options:
        char = swap_face(character_image, face, api_key)
        characters.append(char)

    return characters
グループ写真の編集
# Replace one person in group photo
edited_group_photo = swap_specific_video_face(
    "https://example.com/group-video.mp4",
    "https://example.com/replacement-face.jpg",
    "https://example.com/person-to-replace.jpg",
    api_key
)

エラー処理

try:
    result = swap_face(target, face, api_key)
    print(f"Face swap successful: {result}")
except Exception as e:
    print(f"Face swap failed: {e}")
    # Check image quality, try different images, or notify user

パフォーマンスのヒント

  1. Webhook を使用する:動画では必ず Webhook を使用します
  2. 顔画像を最適化する:鮮明で高品質な顔画像を使用します
  3. バッチ処理する:複数のリクエストをまとめて送信します
  4. 結果をキャッシュする:生成したコンテンツを保存します
  5. 処理時間を監視する:時間を追跡し、最適化します

倫理的な配慮

⚠️ 重要:顔の入れ替え技術は責任を持って使用してください

  • 他人の顔を使用する前に同意を得てください
  • 誤解を招くコンテンツや有害なコンテンツを作成しないでください
  • 現地の法律や規制に従ってください
  • プライバシーと肖像権を尊重してください
  • ディープフェイクコンテンツを共有する際は免責事項を追加してください

エンタープライズ API

専用リソースについては、以下をご覧ください。

# Enterprise endpoints
url = "https://modelslab.com/api/v1/enterprise/deepfake/specific_face_swap"
url = "https://modelslab.com/api/v1/enterprise/deepfake/single_video_swap"

リソース

関連スキル

  • modelslab-video-generation - 動画を生成する
  • modelslab-webhooks - 非同期処理を処理する
  • modelslab-sdk-usage - 公式 SDK を使用する

コメント