■ OpenAI 클래스의 images 변수를 사용해 이미지/텍스트를 갖고 이미지를 편집하는 방법을 보여준다.
[원본 및 마스크 이미지]
[결과 이미지]
▶ 예제 코드 (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 33 34 35 |
import os from openai import OpenAI os.environ["OPENAI_API_KEY"] = "<OPENAI_API_KEY>" openAI = OpenAI() image = open("image.png", "rb") mask = open("mask.png" , "rb") imageResponse = openAI.images.edit( prompt = "many apples in cardboard box", image = image, mask = mask, size = "512x512", n = 1 ) print(imageResponse) """ ImagesResponse( created = 1717574645, data = [ Image( b64_json = None, revised_prompt = None, url = 'https://oaidalleapiprodscus.blob.core.windows.net/private/org-EkYGQNtJSwLObhqCI65I747J/user-89spyW5FYIOQ1WqSb6pwacpU/img-WUAmaNHYIbCOevm9WJqqetm0.png?st=2024-06-05T07%3A04%3A05Z&se=2024-06-05T09%3A04%3A05Z&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-04T22%3A29%3A20Z&ske=2024-06-05T22%3A29%3A20Z&sks=b&skv=2023-11-03&sig=C8G/NDKcIjlnroWTRjyyz1IMtX5gx/qmy3nfdbS5jVA%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 |