■ OpenAI 클래스의 images 변수를 사용해 텍스트를 갖고 이미지를 만드는 방법을 보여준다.
• 한국어보다 영어가 더 정확하기 때문에 영어로 prompt 인자를 설정했다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import os from openai import OpenAI os.environ["OPENAI_API_KEY"] = "<OPENAI_API_KEY>" openAI = OpenAI() imageResponse = openAI.images.generate( model = "dall-e-2", prompt = "cat dancing on truck", size = "512x512", quality = "standard", n = 1 ) print(imageResponse) """ ImagesResponse( created = 1717575169, data = [ Image( b64_json = None, revised_prompt = None, url = 'https://oaidalleapiprodscus.blob.core.windows.net/private/org-EkYGQNtJSwLObhqCI65I747J/user-89spyW5FYIOQ1WqSb6pwacpU/img-wQ2aEHjzR03TKlI0QRwNQyPq.png?st=2024-06-05T07%3A12%3A49Z&se=2024-06-05T09%3A12%3A49Z&sp=r&sv=2023-11-03&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2024-06-05T06%3A57%3A33Z&ske=2024-06-06T06%3A57%3A33Z&sks=b&skv=2023-11-03&sig=1Qh4jdeQXfXAmA3hSN2nfGIKuO06drlrE5%2BwnW%2BLc1M%3D' ) ] ) """ |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
annotated-types==0.7.0 anyio==4.4.0 certifi==2024.6.2 distro==1.9.0 exceptiongroup==1.2.1 h11==0.14.0 httpcore==1.0.5 httpx==0.27.0 idna==3.7 openai==1.31.0 pydantic==2.7.3 pydantic_core==2.18.4 sniffio==1.3.1 tqdm==4.66.4 typing_extensions==4.12.1 |