OpenAI の新しい画像生成API(gpt-image-1)を試してみた #ChatGPT - Qiita

image.png

↓↓説明

ガイド

image.png
俺たちにできないことを平然とやってのける。そこに痺れる。憧れる。

要点

  • gpt-image-1は で 「画像のChatGPT」 といえる存在
  • APIから使えるようになったのは商用にも大きい
  • 安全対策も万全(Moderationパラメータで調整可)

認証が必要(個人情報登録)

なんか、オーガナイゼーション認証が必要でした。犯罪に使われるからでしょうか?

とりあえず、マイナンバーカードでサクッと登録、個人情報を紐づけます。顔面の写真も撮られます。
いわゆる eKYCですね。



使い方

あとは、PlayGroundでプロンプト適当に入れると絵が生成されます。

image.png

image.png

PlayGroundだとNSFWっぽいのプロンプトはすぐ怒られます。

image.png

多分コンテンツ モデレーション(moderation)パラメータで倫理観をlowで落とせばOK?

image.png

API

APIはこんな感じ

Python

from openai import OpenAI
client = OpenAI()

response = client.images.generate(
  model="gpt-image-1",
  prompt="anime-style illustration of a magical girl version of a 22-year-old Japanese female college student, long blonde twintails, wearing a sparkly pink and gold magical costume with ribbons, thigh-high boots, holding a glowing wand, on a starry stage with spotlight, cute and confident pose, 7000K lighting, vivid colors, anime background  n",
  n=1,
  size="1024x1536",
  quality="high"
)

Node.js

import OpenAI from "openai";

const openai = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
});

const response = await openai.images.generate({
  model: "gpt-image-1",
  prompt: "anime-style illustration of a magical girl version of a 22-year-old Japanese female college student, long blonde twintails, wearing a sparkly pink and gold magical costume with ribbons, thigh-high boots, holding a glowing wand, on a starry stage with spotlight, cute and confident pose, 7000K lighting, vivid colors, anime background  n",
  n: 1,
  size: "1024x1536",
  quality: "high"
});

JSON

{
  "model": "gpt-image-1",
  "prompt": "anime-style illustration of a magical girl version of a 22-year-old Japanese female college student, long blonde twintails, wearing a sparkly pink and gold magical costume with ribbons, thigh-high boots, holding a glowing wand, on a starry stage with spotlight, cute and confident pose, 7000K lighting, vivid colors, anime background  n",
  "n": 1,
  "size": "1024x1536",
  "quality": "high"
}

Curl

curl https://api.openai.com/v1/images/generations 
  -H "Content-Type: application/json" 
  -H "Authorization: Bearer $OPENAI_API_KEY" 
  -d '{
  "model": "gpt-image-1",
  "prompt": "anime-style illustration of a magical girl version of a 22-year-old Japanese female college student, long blonde twintails, wearing a sparkly pink and gold magical costume with ribbons, thigh-high boots, holding a glowing wand, on a starry stage with spotlight, cute and confident pose, 7000K lighting, vivid colors, anime background  n",
  "n": 1,
  "size": "1024x1536",
  "quality": "high"
}' | jq -r '.data[0].b64_json' | base64 --decode > output.png

実際に API 使ってみた

普通に Curl

image.png

image.png

透過PNGを出す

“background”: “transparent”

image.png

iTerm2.Zi2dWR.png

コスト

結構高いw

image.png

最後に

image.png

AI情報発信してます!(1日二十円で読める
↓↓↓



フラッグシティパートナーズ海外不動産投資セミナー 【DMM FX】入金

Source link