├── requirements.txt ├── images └── Stable-Diff-Prompt-Gen.png ├── README.md ├── app.py └── examples.txt /requirements.txt: -------------------------------------------------------------------------------- 1 | jinja2==3.0.3 2 | transformers==4.22.2 3 | sentencepiece 4 | torch 5 | -------------------------------------------------------------------------------- /images/Stable-Diff-Prompt-Gen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kaludii/Stable-Diffusion-Prompt-Generator/HEAD/images/Stable-Diff-Prompt-Gen.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Stable Diffusion Prompt Creator 3 | 4 | Created for [this](https://huggingface.co/Gustavosta/MagicPrompt-Stable-Diffusion) model trained by Gustavosta for Stable Diffusion to create a prompt from a few words. You can submit your own text or select from provided examples. 5 | 6 | # Web App 7 | Click [Here](https://huggingface.co/spaces/Kaludi/Stable-Diffusion-Prompt-Generator_App "Here") To View This App Online! 8 | 9 | ![Image](https://github.com/Kaludii/Stable-Diffusion-Prompt-Generator/blob/main/images/Stable-Diff-Prompt-Gen.png?raw=true) 10 | 11 | ## Features 12 | 13 | - Generate prompts based on a starting text entered by the user 14 | - Uses a pre-trained language model to generate the prompt 15 | - Option to select examples or enter own starting text 16 | 17 | ## Usage 18 | 19 | To use the app, enter a starting text in the input field or select an example from the provided examples. Then click on the "Generate" button to generate a prompt based on the starting text. 20 | 21 | ## Technical details 22 | 23 | The app uses Streamlit for the user interface and the Hugging Face Transformers library to access the pre-trained language model. The model is a GPT-2 language model trained for Stable Diffusion. 24 | 25 | ## Requirements 26 | 27 | - Python 3.6 or higher 28 | - Streamlit 29 | - Transformers (Hugging Face) 30 | 31 | ## Installation 32 | 33 | 1. Clone the repository: 34 | 35 | `git clone https://github.com/Kaludii/Stable-Diffusion-Prompt-Generator.git` 36 | 37 | 2. Install the required packages: 38 | 39 | `pip install streamlit transformers` 40 | 41 | 3. Run the app: 42 | 43 | `streamlit run app.py` 44 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import random 3 | import re 4 | from transformers import pipeline, set_seed 5 | 6 | gpt2_pipe = pipeline('text-generation', model='Gustavosta/MagicPrompt-Stable-Diffusion', tokenizer='gpt2') 7 | 8 | with open("examples.txt", "r") as f: 9 | line = f.readlines() 10 | 11 | def generate(starting_text): 12 | seed = random.randint(100, 1000000) 13 | set_seed(seed) 14 | 15 | if starting_text == "": 16 | starting_text: str = line[random.randrange(0, len(line))].replace("\n", "").lower().capitalize() 17 | starting_text: str = re.sub(r"[,:\-–.!;?_]", '', starting_text) 18 | 19 | response = gpt2_pipe(starting_text, max_length=(len(starting_text) + random.randint(60, 90)), num_return_sequences=4) 20 | response_list = [] 21 | for x in response: 22 | resp = x['generated_text'].strip() 23 | if resp != starting_text and len(resp) > (len(starting_text) + 4) and resp.endswith((":", "-", "—")) is False: 24 | response_list.append(resp+'\n') 25 | 26 | response_end = "\n".join(response_list) 27 | response_end = re.sub('[^ ]+\.[^ ]+','', response_end) 28 | response_end = response_end.replace("<", "").replace(">", "") 29 | 30 | if response_end != "": 31 | return response_end 32 | 33 | st.title("Stable Diffusion Prompt Generator") 34 | 35 | st.markdown("This is a web app for [this](https://huggingface.co/Gustavosta/MagicPrompt-Stable-Diffusion) model trained by Gustavosta for Stable Diffusion to create a Prompt from a few words. You can submit your own text or select from provided examples.") 36 | 37 | starting_text = st.text_input(label="Initial Text", placeholder="Text here", value="") 38 | 39 | if st.button("Generate"): 40 | result = generate(starting_text) 41 | st.write("
{}
".format("
".join(result.splitlines())), unsafe_allow_html=True) 42 | 43 | examples = [] 44 | for x in range(5): 45 | examples.append(line[random.randrange(0, len(line))].replace("\n", "").lower().capitalize()) 46 | 47 | st.write("") 48 | st.write("
Examples:
",unsafe_allow_html=True) 49 | for example in examples: 50 | st.write("
• {}
".format(example), unsafe_allow_html=True) -------------------------------------------------------------------------------- /examples.txt: -------------------------------------------------------------------------------- 1 | The Dusk of the Damned Hamlet 2 | The Blackwell Brigade Circus. 3 | The Pilgrim of the Paradox 4 | The Blackened Blight of Vengeance 5 | The Depths of the Cosmic Calamity 6 | The Treasonous Treacherous Throne 7 | The Bloodthirsty Bandit's Booty 8 | The Enchanted Estate of the Epic Endgame 9 | The Enchanted Enclave of the End 10 | A Precious Prize from Frankenstein's Lab 11 | The Priestess and the Prophecy 12 | The Hideaway that Prague Hid 13 | Among the Branches and the Blackbirds 14 | The Enchanted Enclave of the Eclipse 15 | The Laughter of the Living Dead's Last Laugh 16 | Among the Branches and the Belligerent Blackbirds 17 | The Treacherous Trickster Throne 18 | Into the Depths of the Cosmic Horror 19 | The Priceless Prize from Frankenstein's Frightening Factory 20 | The Priestess and the Ravens 21 | The Pilgrim of the Past 22 | The Depths of the Cosmic Catastrophe 23 | The Mechanics of the Matrix 24 | The Jailer's Chilly Chains 25 | The Emergence of the Enchanting Enchantress 26 | The Brutal Bounty of the Bandit 27 | Among the Boughs and the Beautiful Blackbirds 28 | The Province of the Prophet 29 | The Flames of the Fateful Studio 30 | The Goblins of the Glitzy Glee and Glamorous Glitz 31 | The Dark Dominion of the Dictators 32 | The Lucky Losses of the Gambler 33 | The Enchanted Enclave of the Endgame 34 | The Secret Treacherous Throne 35 | The Majestic Maleficent Monarchs 36 | The Priestess and the Pyrotechnics 37 | The Silent Shadow Overlords 38 | The Rise of the She-Wolf 39 | The Priestess and the Pyre 40 | The Precious Prize from Frankenstein's Foundry 41 | The Treacherous Trickster's Tainted Throne 42 | The Mechanics of the Maze 43 | The Hideout that Prague Hid in the Hinterlands 44 | The Mechanisms of the Mind 45 | The Treasonous Trickster's Triumphant Throne 46 | The Majestic Malevolent Monarchies of Misery 47 | The Machines of the Malevolent Matrix 48 | The Blackwell Bro Circus Brigade 49 | The Goblins of the Glamour and Glitz 50 | The Quest for the Queen 51 | The Lodge that Prague Left Behind 52 | The Blackwell Bro Circus Band 53 | The Treasonous Trickster’s Throne 54 | The Jailer's Chilly Clutches 55 | The Precious Prize from Frankenstein's Forge 56 | The Enchanted Expedition 57 | The Legacy of the Legendary Legends 58 | The Jailer’s Chilly Clutch 59 | The Cryptic Crowned Commanders 60 | The Grandiose Grim Monarchs 61 | The Fortunate Fortune of the Fortuneteller's Fate 62 | The Mechanics of the Merciless Maze 63 | The Fortunate Fate of the Fortune Teller 64 | The Fortunate Fate of the Fortuneteller 65 | The Sunset of the Sullen Hamlet 66 | To Laugh or to Die 67 | The Hideout that Prague Hid Away 68 | The Blackwell Bro Circus. 69 | The Quest for the Queen of the Quicksilver 70 | The Province of the Powerful Prophet 71 | The Quest for the Queen of the Quagmire 72 | The Secret Sovereigns of the Shadowlands of Sorrow 73 | The Brutal Bounty of the Bandit King 74 | The Emperor in the Freezer of Winter 75 | The Goblins of the Glee and Glitzy Glamour 76 | The Secret Sovereigns of the Shadowlands 77 | The Harmony of the Hallowed Studio 78 | The Depths of the Cosmic Catastrophic Chaos 79 | The Jailer's Cold Clasp 80 | The Goblins of the Glitz and Glamour 81 | The Sunset of the Sinister Hamlet 82 | The Sunset of the Sorrowful Hamlet 83 | The Dark Domain of the Dictatorship 84 | The Jailer's Chill 85 | The Emperor in the Frigid Frost of Winter 86 | The Mysterious Dungeon of Despair 87 | The Property of the Pope 88 | The Legacy of the Legendaries 89 | The Goblins of the Glee and Glitz 90 | The Depths of the Cosmic Cataclysm 91 | The Hideaway that Prague Held Hostage 92 | The Emperor in the Flames of Winter 93 | The Bloodthirsty Bandit's Bounty 94 | The Awakening of the Amazonian Warrior 95 | The Goblins of the Glitzy Glee and Glittering Glamour 96 | The Twilight of the Tragic Hamlet 97 | The Laughter of the Living Dead 98 | The Twilight of the Tragic Tragedy of Hamlet 99 | Among the Roots and the Ravens 100 | The Steam-Powered Stallion of the Stunning Spectacle 101 | The Steam-Powered Strongman of the Stage 102 | The Priceless Prize from Frankenstein’s Factory 103 | The Blackwell Brothers Circus. 104 | The Legacy of the Legendary Heroes 105 | The Majestic malevolent Monarchs 106 | The Precious Prize from Frankenstein's Frightening Furnace 107 | The Legacy of the Legend 108 | The Priestess and the Pyromania 109 | The Emperor in the Frigid Freezer of the Frozen Winter 110 | Among the Branches and the Batty Birds 111 | The Emperor in the Frost of Winter 112 | The Laugh of the Living Dead 113 | The Pilgrim of the Perplexing Paradox 114 | The Champions of the Champion 115 | The Pilgrim of the Puzzling Paradox 116 | The Pilgrim of the Present 117 | The Quest for the Queen of the Quicksand 118 | The Majestic Malevolent Monarchs 119 | The Harmony of the Hallowed House of Horror Studio 120 | The Machines of the Mind 121 | The Awakening of the Amazon 122 | The Fortunate Fortune of the Gambler 123 | The Depths of the Cosmic Horror 124 | The Grandiose Grim Monarchies 125 | The Emergence of the Enchantress 126 | The Enchanted Estate of the Endgame 127 | The Emperor in the Frigid Freezer of Winter 128 | The Steam-Powered Showman of Strength 129 | Among the Boughs and the Blackcaps 130 | The Province of the Prince 131 | The Bloodthirsty Bandit's Bountiful Booty 132 | The Harmony of the Haunted House Studio 133 | The Harmony of the Haunted Studio 134 | The Steam-Powered Stallion of the Stage 135 | The Dominion of the Daring Duke 136 | The Hideout that Prague Hid in the Hills 137 | The Laughter of the Lurking Dead 138 | The Dominion of the Duke 139 | The Steam-Powered Stallion of the Spectacle --------------------------------------------------------------------------------