달리2 api-keys:
https://platform.openai.com/account/api-keys
#(1)
pip install transformers datasets tqdm konlpy googletrans==4.0.0-rc1 diffusers
#(2)
import torch
import random
from googletrans import Translator
from diffusers import StableDiffusionPipeline
#(3)
model_id = "prompthero/openjourney"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipe = pipe.to("cuda")
translator = Translator()
#(4)
list_a=[
"문장을 적어주세요."
]
summarized = random.choice(list_a)
#(5)
en_prompt = translator.translate(summarized, dest="en")
image = pipe(en_prompt.text+', mdjrny-v4 style').images[0]
print(summarized)
print(en_prompt.text)
image
>>>영어번역 및 이미지출력
#(1)
pip install openai
#(2)
import random
list_a=[
"영어문장을 적어주세요"
]
#(3)
import os
import openai
from IPython.display import Image
from IPython import display
from base64 import b64decode
PROMPT = random.choice(list_a)
openai.api_key = "키를 다운받아 적어주세요."
response = openai.Image.create(
prompt=PROMPT,
n=1,
size="256x256",
response_format="b64_json"
)
image_b64 = response['data'][0]['b64_json']
display.Image(b64decode(image_b64))
>>>이미지 출력