# This work is based on this webpage # http://dalle2-prompt-generator.s3-website-us-west-2.amazonaws.com/ import gradio as gr import random import re def generate_sentence(type): if type == "Humanoid": template = "#humanoid# #human-mod# in #setting#, #img-type#, #img-mod#." return resolve(template).capitalize() if type == "Holdable": template = "#holdable# #obj-mod# in #setting#, #img-type#, #img-mod#." return resolve(template).capitalize() def resolve(template): result = template placeholders = re.findall(r"#[a-z\-]*#", template) for placeholder in placeholders: options = get_options_by_placeholder(placeholder) input_value = resolve(get_random_from_array(options)) result = result.replace(placeholder, input_value) return result def get_random_from_array(array): return random.choice(array) def get_options_by_placeholder(param): switcher = { "#img-type#": ["On the television show #show#", "In the movie #movie#", "Painting by #painter#", "Cover of #magazine# magazine", "Realistic photograph", "Realistic painting", "Selfie", "Pixel Art", "Portrait", "Detailed scientific diagram", "Movie Poster", "Victorian Newspaper article", "Cinematic shot", "Digital art", "35mm photograph", "Baroque painting", "Advertisement", "Comic-style art", "Book cover", "Early 1900s newspaper", "Renaissance painting", "Sculpture", "Grafitti art", "Crayon art by 5 year old", "watercolors by 5 year old", "1960s Cartoon", "Cyberpunk digital art", "Go pro footage", "Oil painting", "Sketch", "Neoclassical painting"], "#img-mod#": ["Hyperrealistic", "Closeup", "Award winning", "Vintage", "4K HD", "Highly Detailed"], "#food#": ["a bowl of cereal", "hot wings", "cake", "pizza", "a hamburger", "french fries", "a plate of nachos", "onion rings", "pudding", "#veggie#", "#fruit#"], "#color#": ["red", "orange", "yellow", "green", "blue", "purple", "silver", "black", "brown", "white", "grey", "gold", "teal", "magenta", "indigo"], "#setting#": ["the pouring rain", "a space station on Mars", "a desert", "a plain", "a tundra", "a wetland", "a mountainside scene", "a beach scene", "a rock concert", "a bustling modern city", "an alley", "a boat on a river", "a forest", "a jungle", "a winter wonderland", "Ancient Egypt", "Ancient Rome", "a zoo", "a McDonalds's", "space", "a museum", "a bus stop", "a school", "a cafeteria", "a concert hall", "a playground", "a bathroom", "minecraft", "a subway", "a submarine", "a haunted house", "a cave", "a swimming pool", "a restaurant", "a bar", "a prison cell", "the back of a bus", "a tree", "a car", "an alien spaceship", "a medieval castle", "a bungalow on the beach", "heaven", "an academy", "a farm", "an airport", "a beauty salon", "a basement", "a casino", "a circus", "a church", "a bookstore", "a barber shop", "a sewer", "a garden", "a football stadium", "a hospital", "a police station", "a zen garden", "a volcano", "Easter Island", "a winery", "a temple", "a small town", "a train station", "a secret hideaway"], "#humanoid#": ["#profession#", "a robot", "a gorilla", "an elf", "a hobbit", "a sloth", "an alien", "Winnie the Pooh", "Darth Vader", "Cthulhu", "A giant squid", "SpongeBob SquarePants", "Gandalf the Grey", "a goblin", "Batman", "Cleopatra", "Superman", "Harry Potter", "Homer Simpson", "Mickey Mouse", "Princess Jasmine", "Garfield", "Marge Simpson", "Fred Flintstone", "Super Mario", "Luigi from Super Mario", "Tony the Tiger", "Snow White", "an Imperial Stormtrooper", "Boba Fett"], "#human-mod#": ["with #color# hair eating #food#", "dressed as #profession# holding #holdable#", "with #color# hair holding #holdable#", "dressed as #profession# riding #rideable#", "holding #holdable#", "holding #holdable# and eating #food#", "driving #driveable#", "eating #food#", "riding #rideable#", "with #color# hair planting #plantable#", "holding #holdable# planting #plantable#", "dressed as #profession# planting #plantable#", "sleeping", "dancing with #humanoid#", "talking to #humanoid#", "falling asleep", "wearing #wearable# driving #driveable#", "wearing #wearable# holding #holdable#", "wearing #wearable# drinking #drinkable#", "dressed as #profession# drinking #drinkable#", "wearing #wearable# with #color# hair", "learning to fly", "playing #playable#", "playing #playable# while eating #food#", "wearing #wearable# playing #playable#", "playing #playable# and losing", "playing #playable# and winning", "talking to #critter#"], "#critter#": ["a mouse", "a bird", "a squirrel", "a cat", "a fish", "a tiny horse", "a huge bumblebee", "a sloth", "a hamster", "a lizard", "a spider", "a scorpion", "a beetle", "a centipede", "a pokemon", "a pikachu", "a squirtle"], "#driveable#": ["a school bus", "a car", "a truck", "a motorcycle", "a lawnmower", "a garbage truck", "a snowmobile", "a lamborghini", "a tesla", "a motor scooter", "a cadillac", "a forklift", "a clown car", "a dump truck"], "#rideable#": ["#humanoid#", "#critter#", "a bicycle", "a horse", "a hang glider", "a boat", "an osterich", "a dolphin", "a pterodactyl", "a velociraptor", "a train", "a goat", "a giraffe", "a camel", "a donkey", "a lawnmower"], "#profession#": ["a doctor", "a scientist", "the pope", "an astronaut", "a medieval knight", "a lawyer", "a CEO", "a samurai", "a paramedic", "a construction worker", "a shaman", "a firefighter", "a mailman", "an electrician", "a chef", "a merchanic", "a pharmacist", "a fortune teller", "an engineer", "a butcher", "a policeman"], "#painter#": ["Vincent van Gogh", "Leonardo Da Vinci", "Rembrandt", "Pablo Picasso", "Andy Warhol", "Gustav Klimt", "Salvador Dali", "Claude Monet", "H.R. Giger"], "#magazine#": ["Time", "Vogue", "GQ", "National Geographic", "Rolling Stone", "MAD", "Cosmopolitan"], "#show#": ["Simpsons", "Sopranos", "Baywatch", "Southpark", "The X Files", "Seinfeld", "The Office", "Law & Order", "The Brady Bunch", "Friends", "The Fresh Prince of Bel-Air", "Sesame Street"], "#movie#": ["The Godfather", "Indiana Jones", "Saving Private Ryan", "Lord of the Rings", "Star Wars", "Terminator", "The Wizard of Oz", "Jurassic Park", "Gone with the Wind", "Rocky"], "#holdable#": ["#critter#", "a cigarette", "a bag of marbles", "a candybar", "a crystal ball", "#plantable#", "a fork", "a knife", "a pencil", "a boombox", "a wedding ring", "a camera", "a phone", "a compass", "#food#", "#drinkable#", "#drinkable# and #food#", "#wearable# and #wearable#", "#wearable#"], "#obj-mod#": ["covered in #material#", "sitting on top of #holdable#", "sitting on top of #holdable#", "melting into a puddle", "standing upright", "giving off light", "reflecting the surroundings", "being sucked into a blackhole", "slowly disappearing", "on fire", "evolving into #holdable#", "evaporating into thin air", "covered in cheese", "glowing and floating", "glowing and vibrating", "sitting next to #holdable#", "being licked by #critter#", "carried by #humanoid#", "riding on #rideable#", "made out of #material#", "made out of #material#", "made out of #material#", "shaped like #critter#"], "#fruit#": ["an apple", "a banana", "a pear", "grapes", "an orange", "a lemon", "a lime", "a watermelon", "a tangerine", "cantaloupe", "blueberries", "raspberries", "cherries"], "#veggie#": ["broccoli", "peas", "asparagus", "a potato", "onions", "squash", "cucumbers", "cauliflower", "corn", "carrots", "lima beans", "okra", "avocados"], "#drinkable#": ["a bottle of water", "a jug of milk", "a glass of orange juice", "a mug of beer", "a flask of whiskey", "a jug of moonshine", "a cup of coffee", "a cup of tea", "a glass of wine"], "#plantable#": ["#fruit#", "#fruit#", "#fruit#", "#fruit#", "#fruit#", "#veggie#", "#veggie#", "#veggie#", "#veggie#", "flowers", "trees", "bushes", "seeds", "a cactus", "lush foliage"], "#wearable#": ["a funny #color# hat", "a stylish #color# cape", "fancy #color# pants", "an ornate scarf", "#color# gloves", "a work uniform", "funny glasses", "a bright #color# dress", "#color# shoes", "a crown", "a #wearable-mod# #color# bathrobe", "sunglasses", "a trench coat made out of #material#", "a baseball cap", "a black leather jacket", "blue jeans", "an ugly sweater", "#footwear# and a #wearable-mod# #color# t-shirt", "a tie made out of #material#", "#footwear# and #color# gloves", "#footwear# and a #wearable-mod# tie", "#footwear#", "#footwear#", "#footwear#"], "#playable#": ["chess", "tennis", "baseball", "football", "with #holdable#", "chess with #humanoid#", "ping pong with #humanoid#", "a video game", "volleyball", "basketball", "solitaire", "poker", "billiards", "blackjack", "poker with #humanoid#", "basketball with #humanoid#"], "#wearable-mod#": ["wrinkled", "fancy", "funny", "dirty", "vintage", "worn-out", "brand new", "striped", "shiny"], "#footwear#": ["shoes", "boots", "flip flops", "high heels", "combat boots", "sandals", "cowboy boots", "hiking boots", "loafers", "crocs", "tennis shoes", "sneakers"], "#material#": ["chocolate", "cheese", "solid gold", "crystal", "cardboard", "silk", "rubber", "metal", "glass", "plastic", "wood", "stone", "marble", "paper", "fabric", "feathers"], "#food#": ["a burger", "a pizza", "spaghetti", "sushi", "tacos", "a sandwich", "chicken wings", "french fries", "popcorn", "a hot dog", "a burrito", "pancakes", "a donut", "ice cream", "a cupcake", "a cookie"], "#color#": ["red", "orange", "yellow", "green", "blue", "purple", "silver", "black", "brown", "white", "grey", "gold", "teal", "magenta", "indigo"] } return switcher.get(param, []) def generate_prompt(type): prompt = generate_sentence(type) return prompt value1 = gr.inputs.Radio(choices=["Humanoid", "Holdable"], label="Select the type") value2 = gr.outputs.Textbox(label="Prompt") # examples = [ # ["example1"], # ["example2"], # ["example3"] # ] demo = gr.Interface( fn=generate_prompt, inputs=value1, outputs=value2, title="Prompt Generator for OpenAI's DALL-E", # examples=examples, description="This tool has been developed by Rubén Darío Jaramillo. You can reach me via email at rubend18@hotmail.com or WhatsApp at +593 93 979 6676." ) demo.launch(debug=True)