modelslab-image-generation について
modelslab-image-generation は、ModelsLab API で画像を生成・変換するスキルです。複数のモデルに対応し、インペインティングや非同期結果の取得も扱います。
主な機能
- 01テキストからの画像生成
- 02画像から画像への変換
- 03マスク領域のインペインティング
- 04画像モデルの検索と選択
- 05非同期生成結果の確認
活用シーン
- 01テキストからマーケティング画像を作成
- 02既存画像をもとにバリエーションを生成
- 03画像のマスク領域を補完
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ modelslab/ skills --skill modelslab-image-generationインストール後、Claude Code で/modelslab-image-generationを入力して読み込まれたか確認します。
詳細
ModelsLab 画像生成
ModelsLab の豊富なモデルライブラリと強力な生成エンドポイントを使って、魅力的な AI 画像を生成します。
このスキルを使用する場面
- テキストの説明から画像を生成する
- 既存の画像を変換または変更する
- 画像のマスク部分を埋める(インペインティング)
- ControlNet を使用して、細かく制御する
- 高速な生成が必要な場合(Realtime API)
- 最高品質が必要な場合(Community/FLUX モデル)
- 商品画像、マーケティング用グラフィック、アート作品を作成する
利用可能な API(v7)
1. テキストから画像へ
POST https://modelslab.com/api/v7/images/text-to-image- 50,000 以上のモデルを利用可能
2. 画像から画像へ
POST https://modelslab.com/api/v7/images/image-to-image- プロンプトを使って既存の画像を変換
3. インペインティング
POST https://modelslab.com/api/v7/images/inpaint- 画像のマスク領域を埋める
4. 結果の取得
POST https://modelslab.com/api/v7/images/fetch/{id}- 非同期生成の結果をポーリング
注:v6 エンドポイント(
/api/v6/images/text2imgなど)も引き続き動作しますが、現在のバージョンは v7 です。
画像モデルの検索
# Search image models by name
modelslab models search --feature imagen
# Search specific models
modelslab models search --search "flux"
modelslab models search --search "midjourney"
# Get model details
modelslab models detail --id flux
クイックスタート:テキストから画像へ
import requests
import time
def generate_image(prompt, api_key, model_id="flux"):
"""Generate an image from text.
Args:
prompt: Text description of the image
api_key: Your ModelsLab API key
model_id: Model to use (flux, midjourney, sdxl, imagen-3, etc.)
"""
response = requests.post(
"https://modelslab.com/api/v7/images/text-to-image",
json={
"key": api_key,
"model_id": model_id,
"prompt": prompt,
"negative_prompt": "blurry, low quality, distorted",
"width": 1024,
"height": 1024,
"samples": 1,
"guidance_scale": 7.5
}
)
data = response.json()
if data["status"] == "success":
return data["output"][0]
elif data["status"] == "processing":
return poll_result(data["id"], api_key)
else:
raise Exception(f"Error: {data.get('message')}")
def poll_result(request_id, api_key, timeout=300):
"""Poll for async generation results."""
start = time.time()
while time.time() - start < timeout:
resp = requests.post(
f"https://modelslab.com/api/v7/images/fetch/{request_id}",
json={"key": api_key}
)
data = resp.json()
if data["status"] == "success":
return data["output"][0]
elif data["status"] == "failed":
raise Exception(data.get("message", "Failed"))
time.sleep(5)
raise Exception("Timeout")
# Usage
image_url = generate_image(
"A futuristic cityscape at sunset, cyberpunk style, 8k, highly detailed",
"your_api_key",
model_id="flux"
)
print(f"Image: {image_url}")
画像から画像への変換
def transform_image(init_image, prompt, api_key, model_id="flux", strength=0.7):
"""Transform an existing image based on a prompt.
Args:
init_image: URL of the input image
prompt: How to transform the image
model_id: Model to use (flux models don't need scheduler, SD models do)
strength: 0.0-1.0, higher = more change
"""
payload = {
"key": api_key,
"model_id": model_id,
"prompt": prompt,
"init_image": [init_image], # v7 expects array
"strength": strength,
"width": 512,
"height": 512
}
response = requests.post(
"https://modelslab.com/api/v7/images/image-to-image",
json=payload
)
data = response.json()
if data["status"] == "success":
return data["output"][0]
elif data["status"] == "processing":
return poll_result(data["id"], api_key)
# Transform a photo into a painting
result = transform_image(
"https://example.com/photo.jpg",
"An oil painting in Van Gogh style",
"your_api_key",
model_id="flux",
strength=0.8
)
インペインティング(マスク領域を埋める)
def inpaint_image(image_url, mask_url, prompt, api_key, model_id="flux"):
"""Fill in masked parts of an image.
Args:
image_url: Original image URL
mask_url: Mask image URL (white = inpaint, black = keep)
prompt: What to generate in masked area
model_id: Model to use
"""
response = requests.post(
"https://modelslab.com/api/v7/images/inpaint",
json={
"key": api_key,
"model_id": model_id,
"init_image": image_url,
"mask_image": mask_url,
"prompt": prompt,
"negative_prompt": "blurry, low quality"
}
)
data = response.json()
if data["status"] == "success":
return data["output"][0]
elif data["status"] == "processing":
return poll_result(data["id"], api_key)
# Replace object in image
result = inpaint_image(
"https://example.com/room.jpg",
"https://example.com/mask.jpg",
"A modern red sofa",
"your_api_key",
model_id="flux"
)
人気のモデル ID
プレミアム/高速
flux- Flux Dev(高速、高品質、スケジューラー不要)imagen-3- Google Imagen 3(フォトリアリスティック)imagen-4- Google Imagen 4(最新版)
フォトリアリスティック
realistic-vision-v13- 高品質でリアルな画像deliberate-v2- 汎用性の高いリアルなスタイルabsolute-reality-v1.6- 超リアルな出力
アーティスティック/様式化
midjourney- MidJourney 風の画像(最も人気)dreamshaper-8- アーティスティックで汎用性が高いopenjourney- オープンソースの MidJourney 代替モデル
アニメ/イラスト
anything-v5- アニメスタイルcounterfeit-v2.5- アニメのポートレートmeinamix- 高品質なアニメアート
すべてのモデルを見る:https://modelslab.com/models
主なパラメーター
| パラメーター | 説明 | 推奨値 |
|---|---|---|
model_id | 使用するモデル(必須) | flux、midjourney、sdxl など |
prompt | 生成する画像のテキスト説明 | 具体的かつ詳細に記述 |
negative_prompt | 避ける内容 | "ぼやけた、低品質、歪んだ" |
width / height | 寸法(512~1024) | 512、768、1024 |
samples | 画像の枚数 | 1~4 |
guidance_scale | プロンプトへの準拠度 | 7~8(バランス型)、10~15(厳密) |
seed | 再現性 | null(ランダム)または数値 |
strength | img2img の変更量 | 0.3(わずか)、0.7(中程度)、0.9(大幅) |
webhook | 非同期通知 URL | URL 文字列 |
track_id | カスタム追跡 ID | 任意の文字列 |
ベストプラクティス
1. 効果的なプロンプトを作成する
Bad: "a car"
Good: "A red Ferrari sports car, studio lighting, highly detailed, 4k, photorealistic"
Include: Subject, style, lighting, quality descriptors
2. ネガティブプロンプトを使用する
negative_prompt = "blurry, low quality, distorted, deformed, ugly, bad anatomy, extra limbs"
3. 適切なモデルを選択する
- flux:高速、高品質で、デフォルトの選択肢として適しています
- midjourney:アーティスティックで様式化された出力
- imagen-3/4:プレミアムなフォトリアリスティック画像(Google)
- sdxl:多くのファインチューンモデルがある汎用的なベースモデル
4. 非同期処理を処理する
# Always check status and poll if needed
if data["status"] == "processing":
result = poll_result(data["id"], api_key)
5. 時間のかかる処理には Webhook を使用する
payload = {
"key": api_key,
"prompt": "...",
"webhook": "https://yourserver.com/webhook",
"track_id": "unique-identifier"
}
エラー処理
try:
image = generate_image(prompt, api_key)
print(f"Success: {image}")
except Exception as e:
print(f"Generation failed: {e}")
# Log error, retry, or notify user
リソース
- API ドキュメント:https://docs.modelslab.com/image-generation/overview
- モデルライブラリ:https://modelslab.com/models
- モデル選択ガイド:https://docs.modelslab.com/guides/model-selection
- API キーの取得:https://modelslab.com/dashboard
- コミュニティ:https://discord.gg/modelslab
関連スキル
modelslab-model-discovery- モデルを検索して絞り込むmodelslab-image-editing- 画像を編集して強化するmodelslab-video-generation- 画像から動画を生成するmodelslab-chat-generation- LLM モデルとチャットするmodelslab-webhooks- 非同期処理を扱うmodelslab-sdk-usage- 公式 SDK を使用する
コメント
Markdown 対応