-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopen_ai_play.py
More file actions
63 lines (48 loc) · 1.66 KB
/
open_ai_play.py
File metadata and controls
63 lines (48 loc) · 1.66 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from keys import * # secret file with the prices
import os
import openai
import requests
import shutil
import datetime
openai.api_key = OPENAI_API_KEY
# Remember that the model predicts which text is most likely to follow the text preceding it.
# Temperature is a value between 0 and 1 that essentially lets you control how confident the
# model should be when making these predictions. Lowering temperature means it will take fewer
# risks, and completions will be more accurate and deterministic. Increasing temperature will
# result in more diverse completions.
def create_cat():
response = openai.Image.create(
prompt="a white siamese cat",
n=1,
size="1024x1024"
)
img_url = response['data'][0]['url']
print (img_url)
# Download the image
response = requests.get(img_url, stream=True)
current_date_time = datetime.datetime.now().strftime("%Y_%m_%d__%H_%M_%S")
output_filename = f'generated_{current_date_time}.png'
# Save it to a file
with open(output_filename, 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
print (f"saved - {output_filename}")
# Clean up
del response
def index(animal):
prompt = generate_prompt(animal)
print (prompt)
response = openai.Completion.create(
model="text-davinci-003",
prompt=prompt,
temperature=0.6,
)
return response.choices[0].text
def generate_prompt(animal):
return """Suggest three names for an animal that is a superhero.
Animal: {}
Names:""".format(
animal.capitalize()
)
answer = index("cat")
print (answer)
#create_cat()