tianjiangyou commited on
Commit
1adbb33
1 Parent(s): b078df4

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +97 -0
  2. ideas.txt +0 -0
  3. style.css +84 -0
app.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline, set_seed
2
+ import gradio as grad, random, re
3
+ import os
4
+ import sys
5
+
6
+ gpt2_pipe = pipeline('text-generation', model='Gustavosta/MagicPrompt-Stable-Diffusion', tokenizer='gpt2')
7
+
8
+
9
+ def generate(starting_text):
10
+ with open("ideas.txt", "r") as f:
11
+ line = f.readlines()
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", "").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, 80)), num_return_sequences=1)
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)
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
+ with grad.Blocks(css='style.css') as demo:
34
+ grad.HTML(
35
+ """
36
+ <div style="text-align: center; max-width: 650px; margin: 0 auto;">
37
+ <div>
38
+ <h1 style="font-weight: 900; font-size: 3rem; margin-bottom:20px;">
39
+ The Stable Diffusion Prompt Generator - because your text needs a little more visual spice.
40
+ </h1>
41
+ </div>
42
+ <p style="margin-bottom: 10px; font-size: 96%">
43
+ 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.
44
+ </p>
45
+ <p style="margin-bottom: 10px; font-size: 98%">
46
+ ❤️ Press the Like Button if you enjoy my space! ❤️</a>
47
+ </p>
48
+ </div>
49
+ """
50
+ )
51
+ with grad.Column(elem_id="col-container"):
52
+ with grad.Row(variant="compact"):
53
+ txt = grad.Textbox(
54
+ label="Initial Text",
55
+ show_label=False,
56
+ max_lines=1,
57
+ placeholder="Enter a basic idea",
58
+ ).style(
59
+ container=False,
60
+ )
61
+ run = grad.Button("✨ Magic Prompt ✨").style(full_width=False)
62
+
63
+
64
+
65
+ with grad.Row(variant="compact"):
66
+ out = grad.Textbox(
67
+ label="Generated Text",
68
+ show_label=False,
69
+ lines=5,
70
+ ).style(
71
+ container=False,
72
+ )
73
+
74
+ run.click(generate, inputs=[txt], outputs=[out])
75
+
76
+
77
+
78
+ with grad.Row():
79
+ grad.HTML(
80
+ """
81
+ <div class="footer">
82
+ <p> Powered by <a href="https://huggingface.co/Gustavosta">Gustavosta</a> Stable Diffusion model
83
+ </p>
84
+ </div>
85
+ <div class="acknowledgments" style="font-size: 115%">
86
+ <p> 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.
87
+ </p>
88
+ </div>
89
+ """
90
+ )
91
+
92
+
93
+ fn=generate,
94
+ run=generate,
95
+ inputs=txt,
96
+ outputs=out
97
+ demo.launch(enable_queue=False, inline=True)
ideas.txt ADDED
The diff for this file is too large to render. See raw diff
 
style.css ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #col-container {
2
+ max-width: 800px;
3
+ margin-left: auto;
4
+ margin-right: auto;
5
+ }
6
+ a {
7
+ color: inherit;
8
+ text-decoration: underline;
9
+ }
10
+ .gradio-container {
11
+ font-family: 'IBM Plex Sans', sans-serif;
12
+ }
13
+ .gr-button {
14
+ color: white;
15
+ border-color: #9d66e5;
16
+ background: #9d66e5;
17
+ }
18
+ input[type='range'] {
19
+ accent-color: #9d66e5;
20
+ }
21
+ .dark input[type='range'] {
22
+ accent-color: #dfdfdf;
23
+ }
24
+ .container {
25
+ max-width: 800px;
26
+ margin: auto;
27
+ padding-top: 1.5rem;
28
+ }
29
+ #gallery {
30
+ min-height: 22rem;
31
+ margin-bottom: 15px;
32
+ margin-left: auto;
33
+ margin-right: auto;
34
+ border-bottom-right-radius: .5rem !important;
35
+ border-bottom-left-radius: .5rem !important;
36
+ }
37
+ #gallery>div>.h-full {
38
+ min-height: 20rem;
39
+ }
40
+ .details:hover {
41
+ text-decoration: underline;
42
+ }
43
+ .gr-button {
44
+ white-space: nowrap;
45
+ }
46
+ .gr-button:focus {
47
+ border-color: rgb(147 197 253 / var(--tw-border-opacity));
48
+ outline: none;
49
+ box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
50
+ --tw-border-opacity: 1;
51
+ --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
52
+ --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
53
+ --tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
54
+ --tw-ring-opacity: .5;
55
+ }
56
+ #advanced-options {
57
+ margin-bottom: 20px;
58
+ }
59
+ .footer {
60
+ margin-bottom: 45px;
61
+ margin-top: 35px;
62
+ text-align: center;
63
+ border-bottom: 1px solid #e5e5e5;
64
+ }
65
+ .footer>p {
66
+ font-size: .8rem;
67
+ display: inline-block;
68
+ padding: 0 10px;
69
+ transform: translateY(10px);
70
+ background: white;
71
+ }
72
+ .dark .logo{ filter: invert(1); }
73
+ .dark .footer {
74
+ border-color: #303030;
75
+ }
76
+ .dark .footer>p {
77
+ background: #0b0f19;
78
+ }
79
+ .acknowledgments h4{
80
+ margin: 1.25em 0 .25em 0;
81
+ font-weight: bold;
82
+ font-size: 115%;
83
+ }
84
+