from transformers import pipeline, set_seed import gradio as grad, random, re import os import sys gpt2_pipe = pipeline('text-generation', model='Gustavosta/MagicPrompt-Stable-Diffusion', tokenizer='gpt2') def generate(starting_text): with open("ideas.txt", "r") as f: line = f.readlines() seed = random.randint(100, 1000000) set_seed(seed) if starting_text == "": starting_text: str = line[random.randrange(0, len(line))].replace("\n", "").capitalize() starting_text: str = re.sub(r"\.", '', starting_text) response = gpt2_pipe(starting_text, max_length=(len(starting_text) + random.randint(60, 80)), num_return_sequences=1) response_list = [] for x in response: resp = x['generated_text'].strip() if resp != starting_text and len(resp) > (len(starting_text) + 4) and resp.endswith((":", "-", "—")) is False: response_list.append(resp) response_end = "\n".join(response_list) response_end = re.sub('[^ ]+\.[^ ]+','', response_end) response_end = response_end.replace("<", "").replace(">", "") if response_end != "": return response_end with grad.Blocks(css='style.css') as demo: grad.HTML( """
Ready to see some magic happen? Simply type in your basic idea. Feeling lazy? No problem, just hit the "Magic Prompt" button and it will randomly pull from a list of thousands of ideas for you.
❤️ Press the Like Button if you enjoy my space! ❤️
Transform your boring ideas into creative masterpieces with just one click! Enter a spark of inspiration and let the "Magic Prompt" button work its magic.