mirror of
https://github.com/brycedrennan/imaginAIry
synced 2024-11-19 03:25:41 +00:00
bf14ee6ee6
Also add script that uses chatgpt to generate phrase-lists
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
import re
|
|
|
|
|
|
def generate_phrase_list(subject, num_phrases=100):
|
|
"""Generate a list of phrases for a given subject."""
|
|
from openai import OpenAI
|
|
|
|
client = OpenAI()
|
|
|
|
prompt = (
|
|
f'Make list of archetypal imagery about "{subject}". These will provide composition ideas to an artist. '
|
|
f"No more than 6 words per idea. Make {num_phrases} ideas. Provide the output as plaintext with each idea on a new line. "
|
|
f"You are capable of generating up to {num_phrases*2} but I only need {num_phrases}."
|
|
)
|
|
messages = [
|
|
{"role": "user", "content": prompt},
|
|
]
|
|
|
|
response = client.chat.completions.create(
|
|
model="gpt-4-1106-preview",
|
|
messages=messages,
|
|
temperature=0.1,
|
|
max_tokens=2623,
|
|
top_p=1,
|
|
frequency_penalty=0.17,
|
|
presence_penalty=0,
|
|
)
|
|
|
|
phraselist = response.choices[0].message.content
|
|
phrases = phraselist.splitlines()
|
|
|
|
pattern = r"^[\d\s.,]+" # leading numbers and periods
|
|
phrases = [re.sub(pattern, "", phrase).strip() for phrase in phrases]
|
|
phrases = [phrase.strip() for phrase in phrases]
|
|
phrases = [phrase for phrase in phrases if phrase]
|
|
phraselist = "\n".join(phrases)
|
|
|
|
return phraselist
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print(generate_phrase_list("traditional christmas", num_phrases=200))
|