-
Notifications
You must be signed in to change notification settings - Fork 27
/
lab5.py
38 lines (27 loc) · 1.09 KB
/
lab5.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
36
37
38
import openai
#NOTE: Run this command prior to running the code below: pip install openai
openai.api_key = "Your API key here"
#Set up the model and prompt
engine = "text-davinci-003"
prompt = "Make a detailed DALL-E prompt with several adjectives for a "
#Get input from the user
room = input("Enter a room of the house you'd like to decorate: ")
desc = input("Enter what type of decoration you'd like to do: ")
#Append input from user with our prompt
prompt = prompt + room + " that has " + desc
#Call OpenAI using the ChatGPT model
response = openai.Completion.create(
engine=engine,
prompt=prompt,
max_tokens=1024,
n=1,
temperature=0.7)
#Get image generation prompt from response
image_generation_prompt = response["choices"][0]["text"]
#Display prompt
print("Open AI Response: " + image_generation_prompt)
#Call OpenAI DALL-E model
response = openai.Image.create(prompt=image_generation_prompt, n=1, size="512x512")
#Get image from response
image = response.data[0].url
print("\r\rHere is the location to your image: " + image)