Programming/API

DALL-E 2 API 사용하기 | Text-to-Image AI

해드위그 2023. 10. 19. 21:47
반응형

안녕하세요.

오늘은 openai 사의 gpt가 아닌 다른 인공지능 모델을 사용해보겠습니다.

 

DALL-E 2 : OpenAI에서 만든 Text-to-Image AI 모델
AI를 기반으로 프롬프트에서 텍스트를 입력으로 받아 이미지를 생성해주는 인공지능 모델

 

 

DALL·E 2

DALL·E 2 is an AI system that can create realistic images and art from a description in natural language.

openai.com


DALL-E 2 API 사용하기

 

1. OpenAI에서 API키를 발급 받아야함

 

2. API를 발급 받고 나면 import openai로 api를 사용할 수 있음

 

3. 아래 코드에서 prompt에 이미지 생성을 원하는 문장을 입력해주면 됨

response = openai.Image.create(
    prompt="원하는 문장을 넣으세요",
    n=1,
    size="1024x1024",
    response_format="url"
)

image_url = response["data"][0]["url"]

from PIL import Image

im = Image.open(requests.get(image_url, stream=True).raw)
im.show()

 

* DALL-E 2로 생성한 이미지

Prompt = "Red panda eating apples"

 

반응형