Daniton phenomenon1981 commited on
Commit
a83a43e
0 Parent(s):

Duplicate from phenomenon1981/MagicPrompt-Stable-Diffusion

Browse files

Co-authored-by: Dee Jay <phenomenon1981@users.noreply.huggingface.co>

Files changed (6) hide show
  1. .gitattributes +31 -0
  2. README.md +14 -0
  3. app.py +98 -0
  4. ideas.txt +0 -0
  5. requirements.txt +5 -0
  6. style.css +84 -0
.gitattributes ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ftz filter=lfs diff=lfs merge=lfs -text
6
+ *.gz filter=lfs diff=lfs merge=lfs -text
7
+ *.h5 filter=lfs diff=lfs merge=lfs -text
8
+ *.joblib filter=lfs diff=lfs merge=lfs -text
9
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
10
+ *.model filter=lfs diff=lfs merge=lfs -text
11
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
12
+ *.npy filter=lfs diff=lfs merge=lfs -text
13
+ *.npz filter=lfs diff=lfs merge=lfs -text
14
+ *.onnx filter=lfs diff=lfs merge=lfs -text
15
+ *.ot filter=lfs diff=lfs merge=lfs -text
16
+ *.parquet filter=lfs diff=lfs merge=lfs -text
17
+ *.pickle filter=lfs diff=lfs merge=lfs -text
18
+ *.pkl filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pt filter=lfs diff=lfs merge=lfs -text
21
+ *.pth filter=lfs diff=lfs merge=lfs -text
22
+ *.rar filter=lfs diff=lfs merge=lfs -text
23
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
24
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
25
+ *.tflite filter=lfs diff=lfs merge=lfs -text
26
+ *.tgz filter=lfs diff=lfs merge=lfs -text
27
+ *.wasm filter=lfs diff=lfs merge=lfs -text
28
+ *.xz filter=lfs diff=lfs merge=lfs -text
29
+ *.zip filter=lfs diff=lfs merge=lfs -text
30
+ *.zst filter=lfs diff=lfs merge=lfs -text
31
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: MagicPrompt Stable Diffusion
3
+ emoji: 🍄
4
+ colorFrom: red
5
+ colorTo: indigo
6
+ sdk: gradio
7
+ sdk_version: 3.3.1
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ duplicated_from: phenomenon1981/MagicPrompt-Stable-Diffusion
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline, set_seed
2
+ import gradio as grad, random, re
3
+ import os
4
+ import sys
5
+
6
+
7
+ gpt2_pipe = pipeline('text-generation', model='Gustavosta/MagicPrompt-Stable-Diffusion', tokenizer='gpt2')
8
+
9
+
10
+ def generate(starting_text):
11
+ with open("ideas.txt", "r") as f:
12
+ line = f.readlines()
13
+ seed = random.randint(100, 1000000)
14
+ set_seed(seed)
15
+
16
+ if starting_text == "":
17
+ starting_text: str = line[random.randrange(0, len(line))].replace("\n", "").capitalize()
18
+ starting_text: str = re.sub(r"\.", '', starting_text)
19
+
20
+ response = gpt2_pipe(starting_text, max_length=(len(starting_text) + random.randint(60, 80)), num_return_sequences=1)
21
+ response_list = []
22
+ for x in response:
23
+ resp = x['generated_text'].strip()
24
+ if resp != starting_text and len(resp) > (len(starting_text) + 4) and resp.endswith((":", "-", "—")) is False:
25
+ response_list.append(resp)
26
+
27
+ response_end = "\n".join(response_list)
28
+ response_end = re.sub('[^ ]+\.[^ ]+','', response_end)
29
+ response_end = response_end.replace("<", "").replace(">", "")
30
+
31
+ if response_end != "":
32
+ return response_end
33
+
34
+ with grad.Blocks(css='style.css') as demo:
35
+ grad.HTML(
36
+ """
37
+ <div style="text-align: center; max-width: 650px; margin: 0 auto;">
38
+ <div>
39
+ <h1 style="font-weight: 900; font-size: 3rem; margin-bottom:20px;">
40
+ The Stable Diffusion Prompt Generator - because your text needs a little more visual spice.
41
+ </h1>
42
+ </div>
43
+ <p style="margin-bottom: 10px; font-size: 96%">
44
+ 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.
45
+ </p>
46
+ <p style="margin-bottom: 10px; font-size: 98%">
47
+ ❤️ Press the Like Button if you enjoy my space! ❤️</a>
48
+ </p>
49
+ </div>
50
+ """
51
+ )
52
+ with grad.Column(elem_id="col-container"):
53
+ with grad.Row(variant="compact"):
54
+ txt = grad.Textbox(
55
+ label="Initial Text",
56
+ show_label=False,
57
+ max_lines=1,
58
+ placeholder="Enter a basic idea",
59
+ ).style(
60
+ container=False,
61
+ )
62
+ run = grad.Button("✨ Magic Prompt ✨").style(full_width=False)
63
+
64
+
65
+
66
+ with grad.Row(variant="compact"):
67
+ out = grad.Textbox(
68
+ label="Generated Text",
69
+ show_label=False,
70
+ lines=5,
71
+ ).style(
72
+ container=False,
73
+ )
74
+
75
+ run.click(generate, inputs=[txt], outputs=[out])
76
+
77
+
78
+
79
+ with grad.Row():
80
+ grad.HTML(
81
+ """
82
+ <div class="footer">
83
+ <p> Powered by <a href="https://huggingface.co/Gustavosta">Gustavosta</a> Stable Diffusion model
84
+ </p>
85
+ </div>
86
+ <div class="acknowledgments" style="font-size: 115%">
87
+ <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.
88
+ </p>
89
+ </div>
90
+ """
91
+ )
92
+
93
+
94
+ fn=generate,
95
+ run=generate,
96
+ inputs=txt,
97
+ outputs=out
98
+ demo.launch(enable_queue=False, inline=True)
ideas.txt ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ jinja2==3.0.3
2
+ transformers==4.22.2
3
+ sentencepiece
4
+ torch
5
+ gradio
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
+