chphoom / aroundtheblock

0 stars 1 forks source link

implement challenge generator #15

Closed elaine331917 closed 1 year ago

elaine331917 commented 1 year ago

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.

chphoom commented 1 year ago

https://www.geeksforgeeks.org/create-random-hex-color-code-using-python/#

chphoom commented 1 year ago

https://stackoverflow.com/questions/13998901/generating-a-random-hex-color-in-python

elaine331917 commented 1 year ago

randomly generating words: https://stackoverflow.com/questions/18834636/random-word-generator-python

elaine331917 commented 1 year ago

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/

elaine331917 commented 1 year ago

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)

elaine331917 commented 1 year ago

the generated prompt should follow something like this format: [Adj] [Noun] [Verb] in [Style] style showing [Emotion] [Colors]

chphoom commented 1 year ago
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}")