01 스테이블 디퓨전 API KEY 발급

API KEY 발급받기

https://markspeople.tistory.com/140

누구나 할 수 있는 AI 이미지 생성(1) : Stability.ai API KEY 발급하기

https://platform.stability.ai/docs/

02 구글 코랩에서 코드 작성

인증

import requests
from getpass import getpass

# 사용자로부터 API 키를 안전하게 입력받기
api_key = getpass("Enter your Stability AI API Key: ")

이미지 생성하기

import requests

response = requests.post(
    f"<https://api.stability.ai/v2beta/stable-image/generate/ultra>",
    headers={
        "authorization": f"Bearer {api_key}",  # 입력받은 API 키를 사용
        "accept": "image/*"
    },
    files={"none": ''},
    data={
        "prompt": "Lighthouse on a cliff overlooking the ocean",
        "output_format": "webp",
    },
)

if response.status_code == 200:
    with open("./lighthouse.webp", 'wb') as file:
        file.write(response.content)
else:
    raise Exception(str(response.json()))