import gradio as gr import random from time import time, ctime def promptgen(choice, num, artist): t = time() print(ctime(t)) if choice == "Prompt Generator v0.1(Better quality)": prompt = open('pr1.txt').read().splitlines() elif choice == "Prompt Generator v0.2(More tags)": prompt = open('pr2.txt').read().splitlines() if int(num) < 1 or int(num) > 20: num = 10 if int(artist) < 0 or int(artist) > 40: artist = 2 vocab = len(prompt) generated = [] artists_num = 0 while len(sorted(set(generated), key=lambda d: generated.index(d))) < int(num): rand = random.choice(prompt) if rand.startswith('art by') and artists_num < int(artist): artists_num +=1 generated.append(rand) elif not rand.startswith('art by'): generated.append(rand) print(', '.join(set(generated)) + '\n\n') return ', '.join(set(generated)) demo = gr.Blocks() with demo: gr.HTML( """

Simple Prompt Generator v0.6 (Gradio Demo)

Simple prompt generation script for Midjourney, DALLe, Stable and Disco diffusion and etc neural networks.

More examples in Github and Project site

visitor badge visitor badge
""" ) with gr.Column(): model_size = gr.Radio(["Prompt Generator v0.1(Better quality)", "Prompt Generator v0.2(More tags)"], label="Model Variant", value="Prompt Generator v0.1(Better quality)") number = gr.Number(value="10", label="Num of tag (MAX 20)", show_label=True) artist = gr.Number(value="2", label="Num of artist (Standart 2)", show_label=True) out = gr.Textbox(lines=4, label="Generated Prompts") greet_btn = gr.Button("Generate") greet_btn.click(fn=promptgen, inputs=[model_size, number, artist], outputs=out, concurrency_limit=4) gr.HTML( """ """ ) demo.queue() demo.launch()