Closed elaine331917 closed 1 year ago
randomly generating words: https://stackoverflow.com/questions/18834636/random-word-generator-python
Getting list of nouns/verbs/adj:
https://stackoverflow.com/questions/24409642/how-to-extract-nouns-using-nltk-pos-tag nltk is a natural language toolkit for python: https://www.nltk.org/
https://www.geeksforgeeks.org/create-random-hex-color-code-using-python/#
import random
color_list = []
def generate_color(): color = random.randrange(0, 2**24) hex_color = hex(color) hexcode = "#" + hex_color[2:] return hexcode
color_list.append(generate_color()) color_list.append(generate_color()) color_list.append(generate_color())
for color in color_list: print(color)
the generated prompt should follow something like this format: [Adj] [Noun] [Verb] in [Style] style showing [Emotion] [Colors]
from urllib.request import urlopen
import random
import nltk
nltk.download('popular')
word_site = "https://www.mit.edu/~ecprice/wordlist.10000"
response = urlopen(word_site)
txt = response.read().decode()
WORDS = txt.splitlines()
tagged = nltk.pos_tag(WORDS)
nouns = [item[0] for item in tagged if item[1][0] == 'N']
verbs = [item[0] for item in tagged if item[1][0] == 'V']
adjs = [item[0] for item in tagged if item[1][0] == 'J']
styles = ['Impressionism', 'Avant-garde', 'Baroque', 'Cubism', 'Pixel Art', 'Expressionism', 'Futurism','Minimalism','Pop Art','Rococo','Surrealism']
emotions = ['Sad','Happy','Terror','Hunger']
color_list = []
def generate_color(colors, x):
for i in range(0,x):
color = random.randrange(0, 2**24)
hex_color = hex(color)
hexcode = "#" + hex_color[2:]
colors.append(hexcode)
generate_color(color_list,3)
# the generated prompt should follow something like this format: [Adj] [Noun] [Verb] in [Style] style showing [Emotion] [Colors]
noun = random.choice(nouns)
verb = random.choice(verbs)
adj = random.choice(adjs)
style = random.choice(styles)
emotion = random.choice(emotions)
print(f"{adj} {noun} {verb} in {style} style showing {emotion} with a pallet of {color_list}")
This generator will be the basis for meChallenges and should also be called in the backend to generate weChallenges every week.
It will need to randomly generate six different options: noun, adj, verb, style, emotion, and colors.
Noun, adj, verb, and emotions will possibly need to pull from an external dictionary/library.
Style will come from an enumeration including but not limited to: Impressionism Avant-garde Baroque Cubism Pixel Art Expressionism Futurism Minimalism Pop Art Rococo Surrealism
Colors will come from randomly generated hexcodes.