Commit
·
7a9883b
1
Parent(s):
4511dc8
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
from time import time, ctime
|
4 |
+
|
5 |
+
def promptgen(choice, num):
|
6 |
+
t = time()
|
7 |
+
print(ctime(t))
|
8 |
+
|
9 |
+
if choice == "Prompt Generator v0.1(Better quality)":
|
10 |
+
prompt = open('prompttext.txt').read().splitlines()
|
11 |
+
elif choice == "Prompt Generator v0.2(More tags)":
|
12 |
+
prompt = open('prompttext2.txt').read().splitlines()
|
13 |
+
|
14 |
+
if int(num) < 1 or int(num) > 20:
|
15 |
+
num = 10
|
16 |
+
|
17 |
+
vocab = len(prompt)
|
18 |
+
generated = []
|
19 |
+
while len(sorted(set(generated), key=lambda d: generated.index(d))) < num:
|
20 |
+
rand = random.randint(0, vocab)
|
21 |
+
generated.append(prompt[rand-1])
|
22 |
+
return ' '.join(sorted(set(generated), key=lambda d: generated.index(d)))
|
23 |
+
|
24 |
+
demo = gr.Blocks()
|
25 |
+
|
26 |
+
with demo:
|
27 |
+
gr.HTML(
|
28 |
+
"""
|
29 |
+
<div style="text-align: center; margin: 0 auto;">
|
30 |
+
<div style="display: inline-flex;align-items: center;gap: 0.8rem;font-size: 1.75rem;">
|
31 |
+
<h1 style="font-weight: 900; margin-bottom: 7px;margin-top:5px">
|
32 |
+
Simple Prompt Generator v0.4 (Gradio Demo)
|
33 |
+
</h1>
|
34 |
+
</div>
|
35 |
+
<p style="margin-bottom: 10px; font-size: 94%; line-height: 23px;">
|
36 |
+
Simple prompt generation script for Midjourney, DALLe, Stable and Disco diffusion and etc neural networks. <br> <p>More examples in <a class='link-info' href="https://github.com/WiNE-iNEFF/Simple_Prompt_Generator" target="_blank">Github</a> and <a class='link-info' href="https://wine-ineff.github.io/Simple_Prompt_Generator/" target="_blank">Project site</a></p>
|
37 |
+
</p>
|
38 |
+
<center>
|
39 |
+
<img src='https://visitor-badge.glitch.me/badge?page_id=WiNE-iNEFF_Simple_Prompt_Generator&left_text=GithubVisitors' alt='visitor badge'>
|
40 |
+
</center>
|
41 |
+
</div>
|
42 |
+
"""
|
43 |
+
)
|
44 |
+
with gr.Column():
|
45 |
+
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)")
|
46 |
+
number = gr.Number(value="10", label="Num of tag (MAX 20)", show_label=True)
|
47 |
+
out = gr.Textbox(lines=4, label="Generated Prompts")
|
48 |
+
greet_btn = gr.Button("Generate")
|
49 |
+
greet_btn.click(fn=promptgen, inputs=[model_size, number], outputs=out)
|
50 |
+
gr.HTML(
|
51 |
+
"""
|
52 |
+
<div class="footer">
|
53 |
+
<div style='text-align: center;'>Simple Prompt Generator by <a href='https://twitter.com/wine_ineff' target='_blank'>Artsem Holub (WiNE-iNEFF)</a><br>More information about this demo and script your can find in <a class='link-info' href="https://github.com/WiNE-iNEFF/Simple_Prompt_Generator" target="_blank">Github</a> and <a class='link-info' href="https://wine-ineff.github.io/Simple_Prompt_Generator/" target="_blank">Project site</a></div>
|
54 |
+
</div>
|
55 |
+
"""
|
56 |
+
)
|
57 |
+
|
58 |
+
demo.queue(concurrency_count=4)
|
59 |
+
demo.launch()
|