Yntec commited on
Commit
5c847b9
0 Parent(s):

Duplicate from Yntec/DreamAnything

Browse files
Files changed (5) hide show
  1. .gitattributes +34 -0
  2. README.md +19 -0
  3. app.py +218 -0
  4. requirements.txt +4 -0
  5. style.css +93 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: DreamAnything X6
3
+ emoji: 🎎
4
+ colorFrom: yellow
5
+ colorTo: red
6
+ sdk: gradio
7
+ sdk_version: 3.16.1
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: Yntec/DreamAnything
11
+ ---
12
+ ---
13
+ title: DreamAnything X6
14
+ emoji: 🎎
15
+ colorFrom: yellow
16
+ colorTo: red
17
+ sdk: gradio
18
+ sdk_version: 3.16.1
19
+ app_file: app.py
app.py ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import sys
4
+ from pathlib import Path
5
+ import random
6
+ import string
7
+ import time
8
+ from queue import Queue
9
+ from threading import Thread
10
+ import emoji
11
+
12
+ text_gen=gr.Interface.load("spaces/phenomenon1981/MagicPrompt-Stable-Diffusion")
13
+ def get_prompts(prompt_text):
14
+ if prompt_text:
15
+ return text_gen(prompt_text + " Dream")
16
+ else:
17
+ return text_gen("")
18
+ proc1=gr.Interface.load("models/Yntec/DreamAnything")
19
+
20
+ def restart_script_periodically():
21
+ while True:
22
+ random_time = random.randint(5400, 6000)
23
+ time.sleep(random_time)
24
+ os.execl(sys.executable, sys.executable, *sys.argv)
25
+
26
+
27
+ restart_thread = Thread(target=restart_script_periodically, daemon=True)
28
+ restart_thread.start()
29
+
30
+
31
+ queue = Queue()
32
+ queue_threshold = 100
33
+
34
+ #Don't add noise to the first picture no matter what (the point of noise is to get varied outputs, the first one doesn't need to vary about anything)
35
+ def noadd_random_noise(prompt, noise_level=0.00):
36
+ if noise_level == 0:
37
+ noise_level = 0.00
38
+ percentage_noise = noise_level * 5
39
+ num_noise_chars = int(len(prompt) * (percentage_noise/100))
40
+ noise_indices = random.sample(range(len(prompt)), num_noise_chars)
41
+ prompt_list = list(prompt)
42
+ noise_chars = list(string.ascii_letters + string.punctuation + '' + string.digits)
43
+ noise_chars.extend([''])
44
+ for index in noise_indices:
45
+ prompt_list[index] = random.choice(noise_chars)
46
+ return "".join(prompt_list)
47
+
48
+ #normal behavior
49
+ def add_random_noise(prompt, noise_level=0.00):
50
+ if noise_level == 0:
51
+ noise_level = 0.00
52
+ percentage_noise = noise_level * 5
53
+ num_noise_chars = int(len(prompt) * (percentage_noise/100))
54
+ noise_indices = random.sample(range(len(prompt)), num_noise_chars)
55
+ prompt_list = list(prompt)
56
+ noise_chars = list(string.ascii_letters + string.punctuation + ' ' + string.digits)
57
+ noise_chars.extend(['😍', 'beautiful', '😂', '🤔', '😊', '🤗', '😭', '🙄', 'pretty', '🤯', '🤫', '🥴', 'sitting', '🤩', '🥳', '😔', '😩', '🤪', '😇', 'retro', '😈', '👹', 'masterpiece', '🤖', '👽', 'high quality', '🎃', '🎅', '🎄', '🎁', '🎂', '🎉', '🎈', '🎊', '🎮', '❤️', '💔', '💕', '💖', '💗', '🐶', '🐱', 'visible', '🐹', '🦊', '🐻', '🐨', '🐯', '🦁', '🐘', '🔥', '🌧️', '🌞', '🌈', '💥', '🌴', '🌊', '🌺', '🌻', '🌸', '🎨', '🌅', '🌌', '☁️', '⛈️', '❄️', '☀️', '🌤️', '⛅️', '🌥️', '🌦️', '🌧️', '🌩️', '🌨️', '🌫️', '☔️', '🌬️', '💨', '🌪️', 'cute', 'kawaii', 'little'])
58
+ for index in noise_indices:
59
+ prompt_list[index] = random.choice(noise_chars)
60
+ return "".join(prompt_list)
61
+
62
+ def send_it1(inputs, noise_level, proc1=proc1):
63
+ prompt_with_noise = noadd_random_noise(inputs, noise_level)
64
+ while queue.qsize() >= queue_threshold:
65
+ time.sleep(2)
66
+ queue.put(prompt_with_noise)
67
+ output1 = proc1(prompt_with_noise)
68
+ return output1
69
+
70
+ def send_it2(inputs, noise_level, proc1=proc1):
71
+ prompt_with_noise = add_random_noise(inputs, noise_level)
72
+ while queue.qsize() >= queue_threshold:
73
+ time.sleep(2)
74
+ queue.put(prompt_with_noise)
75
+ output2 = proc1(prompt_with_noise)
76
+ return output2
77
+
78
+ def send_itX(inputs, noise_level, proc1=proc1):
79
+ prompt_with_noise = add_random_noise(inputs, noise_level)
80
+ while queue.qsize() >= queue_threshold:
81
+ time.sleep(2)
82
+ queue.put(prompt_with_noise)
83
+ outputX = proc1(prompt_with_noise)
84
+ return outputX
85
+
86
+ def send_it3(inputs, noise_level, proc1=proc1):
87
+ prompt_with_noise = add_random_noise(inputs, noise_level)
88
+ while queue.qsize() >= queue_threshold:
89
+ time.sleep(2)
90
+ queue.put(prompt_with_noise)
91
+ output3 = proc1(prompt_with_noise)
92
+ return output3
93
+
94
+ def send_it4(inputs, noise_level, proc1=proc1):
95
+ prompt_with_noise = add_random_noise(inputs, noise_level)
96
+ while queue.qsize() >= queue_threshold:
97
+ time.sleep(2)
98
+ queue.put(prompt_with_noise)
99
+ output4 = proc1(prompt_with_noise)
100
+ return output4
101
+
102
+ def send_it5(inputs, noise_level, proc1=proc1):
103
+ prompt_with_noise = add_random_noise(inputs, noise_level)
104
+ while queue.qsize() >= queue_threshold:
105
+ time.sleep(2)
106
+ queue.put(prompt_with_noise)
107
+ output5 = proc1(prompt_with_noise)
108
+ return output5
109
+
110
+ #def send_it7(inputs, noise_level, proc1=proc1):
111
+ #prompt_with_noise = add_random_noise(inputs, noise_level)
112
+ #while queue.qsize() >= queue_threshold:
113
+ # time.sleep(2)
114
+ #queue.put(prompt_with_noise)
115
+ #output5 = proc1(prompt_with_noise)
116
+ #return output0
117
+
118
+
119
+ with gr.Blocks(css='style.css') as demo:
120
+ gr.HTML(
121
+ """
122
+ <div style="text-align: center; max-width: 1200px; margin: 0 auto;">
123
+ <div>
124
+ <style>
125
+ h1 {
126
+ font-size: 6em;
127
+ color: #ffffff;
128
+ margin-top: 30px;
129
+ margin-bottom: 30px;
130
+ text-shadow: 3px 3px 0 rgba(0, 0, 0, 1) !important;
131
+ }
132
+ </style>
133
+ <body>
134
+ <div class="center"><h1>DreamAnything</h1>
135
+ </div>
136
+ </body>
137
+ </div>
138
+ <p style="margin-bottom: 10px; color: #ffffff;">
139
+ If you have an idea, put it on the first box to expand it, if you have a full prompt, you can leave the first box empty and just put it on the second one and click generate images!
140
+ Noise Level: Controls how much randomness is added to the input of the boxes after the first one before it is sent to the model, so you can get 6 unique 768x768 images. Higher noise level produces more diverse outputs, while lower noise level produces similar outputs,
141
+ <a href="https://twitter.com/DavidJohnstonxx/">original space created by Phenomenon1981</a>.
142
+ </p>
143
+ <p style="margin-bottom: 10px; color: #ffaa66; font-size: 98%">
144
+ ❤️ Press the Like Button if you enjoy my space! ❤️</a>
145
+ </p>
146
+ </div>
147
+ """
148
+ )
149
+ with gr.Column(elem_id="col-container"):
150
+ with gr.Row(variant="compact"):
151
+ input_text = gr.Textbox(
152
+ label="Short Prompt",
153
+ show_label=False,
154
+ max_lines=2,
155
+ placeholder="Enter a basic idea and click 'Magic Prompt'. Got no ideas? No problem, Simply just hit the magic button!",
156
+ ).style(
157
+ container=False,min_width=1200
158
+ )
159
+ see_prompts = gr.Button("✨ Magic Prompt ✨").style(full_width=False)
160
+
161
+
162
+ with gr.Row(variant="compact"):
163
+ prompt = gr.Textbox(
164
+ label="Enter your prompt",
165
+ show_label=False,
166
+ max_lines=2,
167
+ placeholder="Full Prompt",
168
+ ).style(
169
+ container=False,
170
+ )
171
+ run = gr.Button("Generate Images").style(full_width=False)
172
+
173
+ with gr.Row():
174
+ with gr.Row():
175
+ #Now that the first box generates a picture with noise=0 having the default at 0 makes no sense as it'd generate the same image 6 times.
176
+ noise_level = gr.Slider(minimum=0.2, maximum=3, step=0.1, label="Noise Level (0.1 or less was generating the same pic 6 times! 🤣)")
177
+ with gr.Row():
178
+ with gr.Row():
179
+ output1=gr.Image(label="DreamAnything",show_label=False,min_width=640)
180
+ output2=gr.Image(label="DreamAnything",show_label=False,min_width=640)
181
+ with gr.Row():
182
+ with gr.Row():
183
+ output3=gr.Image(label="DreamAnything",show_label=False,min_width=640)
184
+ output4=gr.Image(label="DreamAnything",show_label=False,min_width=640)
185
+ with gr.Row():
186
+ with gr.Row():
187
+ output5=gr.Image(label="DreamAnything",show_label=False,min_width=640)
188
+ outputX=gr.Image(label="DreamAnything",show_label=False,min_width=640)
189
+ #with gr.Row():
190
+ #with gr.Row():
191
+ #output0=gr.Image(label="DreamAnything",show_label=False,min_width=640)
192
+
193
+ see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt], queue=False)
194
+ run.click(send_it1, inputs=[prompt, noise_level], outputs=[output1])
195
+ #run.click(send_it7, inputs=[prompt, noise_level], outputs=[output0])
196
+ run.click(send_it2, inputs=[prompt, noise_level], outputs=[output2])
197
+ run.click(send_it3, inputs=[prompt, noise_level], outputs=[output3])
198
+ run.click(send_it4, inputs=[prompt, noise_level], outputs=[output4])
199
+ run.click(send_it5, inputs=[prompt, noise_level], outputs=[output5])
200
+ run.click(send_itX, inputs=[prompt, noise_level], outputs=[outputX])
201
+
202
+
203
+ with gr.Row():
204
+ gr.HTML(
205
+ """
206
+ <div class="footer">
207
+ <p> Demo for <a href="https://huggingface.co/Yntec/DreamAnything">DreamAnything</a> Stable Diffusion model
208
+ </p>
209
+ </div>
210
+ <div class="acknowledgments" style="font-size: 115%; color: #ffffff;">
211
+ <p> Unleash your creative side and generate mesmerizing images with just a few clicks! Enter a spark of inspiration in the "Basic Idea" text box and click the "Magic Prompt" button to elevate it to a polished masterpiece. Make any final tweaks in the "Full Prompt" box and hit the "Generate Images" button to watch your vision come to life. Experiment with the "Noise Level" for a diverse range of outputs, from similar to wildly unique. Let the fun begin!
212
+ </p>
213
+ </div>
214
+ """
215
+ )
216
+
217
+ demo.launch(enable_queue=True, inline=True)
218
+ block.queue(concurrency_count=100)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ accelerate==0.12.0
2
+ gradio
3
+ xformers
4
+ emoji
style.css ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #col-container {color: white;
2
+ max-width: 1200px;
3
+ margin-left: auto;
4
+ margin-right: auto;
5
+ }
6
+ a {
7
+ color: inherit;
8
+ text-decoration: underline;
9
+ }
10
+ .gradio-container {
11
+ color: #ffaa66;
12
+ background-color: #005566;
13
+ font-family: 'IBM Plex Sans', sans-serif;
14
+ }
15
+ .gr-button {
16
+ color: white;
17
+ border-color: #ff0000;
18
+ background: #ff0000;
19
+ }
20
+ input[type='range'] {
21
+ accent-color: #9d66e5;
22
+ }
23
+ .dark input[type='range'] {
24
+ accent-color: #dfdfdf;
25
+ }
26
+ .container {
27
+ color: #ffaa66;
28
+ max-width: 1200px;
29
+ margin: auto;
30
+ padding-top: 1.5rem;
31
+ }
32
+ #gallery {
33
+ color: #ffaa66;
34
+ min-height: 22rem;
35
+ margin-bottom: 15px;
36
+ margin-left: auto;
37
+ margin-right: auto;
38
+ border-bottom-right-radius: .5rem !important;
39
+ border-bottom-left-radius: .5rem !important;
40
+ }
41
+ #gallery>div>.h-full {
42
+ color: #ffaa66;
43
+ min-height: 20rem;
44
+ }
45
+ .details:hover {
46
+ text-decoration: underline;
47
+ }
48
+ .gr-button {
49
+ white-space: nowrap;
50
+ }
51
+ .gr-button:focus {
52
+ border-color: rgb(255 160 0 / var(--tw-border-opacity));
53
+ outline: none;
54
+ box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
55
+ --tw-border-opacity: 1;
56
+ --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
57
+ --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
58
+ --tw-ring-color: rgb(0 0 0 / var(--tw-ring-opacity));
59
+ --tw-ring-opacity: .5;
60
+ }
61
+ #advanced-options {
62
+ color: #ffaa66;
63
+ margin-bottom: 20px;
64
+ }
65
+ .footer {
66
+ color: #ffaa66;
67
+ margin-bottom: 45px;
68
+ margin-top: 35px;
69
+ text-align: center;
70
+ border-bottom: 1px solid #e5e5e5;
71
+ }
72
+ .footer>p {
73
+ color: #ffaa66;
74
+ font-size: .8rem;
75
+ display: inline-block;
76
+ padding: 0 10px;
77
+ transform: translateY(10px);
78
+ background: white;
79
+ }
80
+ .dark .logo{ filter: invert(1); }
81
+ .dark .footer {
82
+ border-color: #303030;
83
+ }
84
+ .dark .footer>p {
85
+ background: #0b0f19;
86
+ }
87
+ .acknowledgments h4{
88
+ color: #ffaa66;
89
+ margin: 1.25em 0 .25em 0;
90
+ font-weight: bold;
91
+ font-size: 115%;
92
+ }
93
+