mcpField
N
nano-banana

nano-banana

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

nano-banana について

ユーザーの依頼に基づき、Google Geminiの画像生成モデルで画像を作るスキルです。Pythonと`google-genai`を使い、APIキーは`.env`から読み込みます。

主な機能

  1. 01Geminiによる画像生成
  2. 02ユーザー依頼からのプロンプト作成
  3. 03Pythonでの`google-genai`利用
  4. 04`.env`からの`GEMINI_API_KEY`読み込み

活用シーン

  1. 01テキスト依頼からの画像作成
  2. 02ユーザーの言語によるプロンプトでの画像生成

インストール

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

$npx skills add https://github.com/aturilin/nano-banana --skill nano-banana

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

同梱ファイルREADME.mdskills/nano-banana/nano_banana.py

詳細

Nano Banana — 画像生成ツール

Google Gemini の画像生成モデルを使って画像を生成します。

ユーザーのリクエスト: $ARGUMENTS

前提条件

  • Python 3.10+
  • google-genai パッケージ(pip install google-genai)
  • .env ファイル内の GEMINI_API_KEY(無料キーは aistudio.google.com で取得できます)

生成方法

次の Python スクリプトを作成して実行します。

import os
import sys
from pathlib import Path
from datetime import datetime

# Load .env
env_file = Path(".env")
if env_file.exists():
    for line in env_file.read_text().splitlines():
        line = line.strip()
        if line and not line.startswith('#') and '=' in line:
            key, value = line.split('=', 1)
            os.environ[key] = value

from google import genai
from google.genai import types

api_key = os.environ.get("GEMINI_API_KEY")
if not api_key:
    print("❌ GEMINI_API_KEY not found. Add it to .env file.")
    sys.exit(1)

client = genai.Client(api_key=api_key)

prompt = "<USER'S IMAGE DESCRIPTION HERE>"

try:
    response = client.models.generate_content(
        model="gemini-3.1-flash-image-preview",
        contents=prompt,
        config=types.GenerateContentConfig(
            response_modalities=['IMAGE', 'TEXT']
        )
    )

    if not response.candidates:
        print("❌ No response — image may have been blocked by safety filter")
        sys.exit(1)

    candidate = response.candidates[0]
    if not candidate.content or not candidate.content.parts:
        print("❌ No content in response — try a different prompt")
        sys.exit(1)

    for part in candidate.content.parts:
        if part.inline_data is not None:
            ext = "png" if "png" in part.inline_data.mime_type else "jpg"
            timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
            filepath = f"images/{timestamp}.{ext}"
            Path("images").mkdir(exist_ok=True)
            Path(filepath).write_bytes(part.inline_data.data)
            print(f"✅ Image saved: {filepath}")
            break
    else:
        print("❌ No image in response — model returned text only")
        sys.exit(1)

except Exception as e:
    print(f"❌ Error: {e}")
    sys.exit(1)

重要

  1. <USER'S IMAGE DESCRIPTION HERE> をユーザーのリクエストに基づく実際のプロンプトに置き換えてください
  2. プロンプトは、ユーザーが使用した言語と同じ言語で記述してください
  3. google-genai がインストールされていない場合は、先にインストールしてください:pip install google-genai
  4. 生成後、Read ツールを使って画像をユーザーに表示してください

コメント