Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,119 @@
|
|
1 |
import gradio as gr
|
2 |
-
import os
|
3 |
import sys
|
4 |
from pathlib import Path
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
18 |
|
19 |
-
|
20 |
-
def text_it1(inputs,text_gen1=text_gen1):
|
21 |
-
go_t1=text_gen1(inputs)
|
22 |
-
return(go_t1)
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
return gr.update(label=(f"{current_model}"))
|
27 |
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
|
36 |
with gr.Blocks(css='style.css') as demo:
|
@@ -48,107 +131,87 @@ with gr.Blocks(css='style.css') as demo:
|
|
48 |
}
|
49 |
</style>
|
50 |
<body>
|
51 |
-
<div class="center"><h1>
|
52 |
</div>
|
53 |
</body>
|
54 |
</div>
|
55 |
<p style="margin-bottom: 10px; color: #ffffff;">
|
56 |
PlaceHolder
|
57 |
-
</
|
|
|
58 |
<p style="margin-bottom: 10px; color: #ffaa66; font-size: 98%">
|
59 |
โค๏ธ Press the Like Button if you enjoy my space! โค๏ธ</a>
|
60 |
</p>
|
61 |
</div>
|
62 |
"""
|
63 |
)
|
64 |
-
with gr.
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
output1=gr.Image(label=(f"{current_model}"))
|
135 |
-
|
136 |
-
|
137 |
-
with gr.Row():
|
138 |
-
with gr.Column(scale=50):
|
139 |
-
input_text=gr.Textbox(label="Use this box to extend an idea automagically, by typing some words and clicking Extend Idea",lines=2)
|
140 |
-
use_short=gr.Button("Use Short Prompt")
|
141 |
-
see_prompts=gr.Button("Extend Idea")
|
142 |
-
def short_prompt(inputs):
|
143 |
-
return(inputs)
|
144 |
-
|
145 |
-
model_name1.change(set_model,inputs=model_name1,outputs=[output1])
|
146 |
-
|
147 |
-
run.click(send_it1, inputs=[magic1, model_name1], outputs=[output1])
|
148 |
-
|
149 |
-
use_short.click(short_prompt,inputs=[input_text],outputs=magic1)
|
150 |
-
|
151 |
-
see_prompts.click(text_it1,inputs=[input_text],outputs=magic1)
|
152 |
-
|
153 |
-
myface.queue(concurrency_count=200)
|
154 |
-
myface.launch(inline=True, show_api=False, max_threads=400)
|
|
|
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:
|
|
|
131 |
}
|
132 |
</style>
|
133 |
<body>
|
134 |
+
<div class="center"><h1>ToyWorld XL 401</h1>
|
135 |
</div>
|
136 |
</body>
|
137 |
</div>
|
138 |
<p style="margin-bottom: 10px; color: #ffffff;">
|
139 |
PlaceHolder
|
140 |
+
<a href="https://twitter.com/DavidJohnstonxx/">original space created by Phenomenon1981</a>.
|
141 |
+
</p>
|
142 |
<p style="margin-bottom: 10px; color: #ffaa66; font-size: 98%">
|
143 |
โค๏ธ Press the Like Button if you enjoy my space! โค๏ธ</a>
|
144 |
</p>
|
145 |
</div>
|
146 |
"""
|
147 |
)
|
148 |
+
with gr.Column(elem_id="col-container"):
|
149 |
+
with gr.Row(variant="compact"):
|
150 |
+
input_text = gr.Textbox(
|
151 |
+
label="Short Prompt",
|
152 |
+
show_label=False,
|
153 |
+
max_lines=2,
|
154 |
+
placeholder="Enter a basic idea and click 'Magic Prompt'. Got no ideas? No problem, Simply just hit the magic button!",
|
155 |
+
).style(
|
156 |
+
container=False,min_width=1200
|
157 |
+
)
|
158 |
+
see_prompts = gr.Button("โจ Magic Prompt โจ").style(full_width=False)
|
159 |
+
|
160 |
+
|
161 |
+
with gr.Row(variant="compact"):
|
162 |
+
prompt = gr.Textbox(
|
163 |
+
label="Enter your prompt",
|
164 |
+
show_label=False,
|
165 |
+
max_lines=2,
|
166 |
+
placeholder="Full Prompt",
|
167 |
+
).style(
|
168 |
+
container=False,
|
169 |
+
)
|
170 |
+
run = gr.Button("Generate Images").style(full_width=False)
|
171 |
+
|
172 |
+
with gr.Row():
|
173 |
+
with gr.Row():
|
174 |
+
#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.
|
175 |
+
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! ๐คฃ)")
|
176 |
+
with gr.Row():
|
177 |
+
with gr.Row():
|
178 |
+
output1=gr.Image(label="DreamAnything",show_label=False,min_width=640)
|
179 |
+
output2=gr.Image(label="DreamAnything",show_label=False,min_width=640)
|
180 |
+
with gr.Row():
|
181 |
+
with gr.Row():
|
182 |
+
output3=gr.Image(label="DreamAnything",show_label=False,min_width=640)
|
183 |
+
output4=gr.Image(label="DreamAnything",show_label=False,min_width=640)
|
184 |
+
with gr.Row():
|
185 |
+
with gr.Row():
|
186 |
+
output5=gr.Image(label="DreamAnything",show_label=False,min_width=640)
|
187 |
+
outputX=gr.Image(label="DreamAnything",show_label=False,min_width=640)
|
188 |
+
#with gr.Row():
|
189 |
+
#with gr.Row():
|
190 |
+
#output0=gr.Image(label="DreamAnything",show_label=False,min_width=640)
|
191 |
+
|
192 |
+
see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt], queue=False)
|
193 |
+
run.click(send_it1, inputs=[prompt, noise_level], outputs=[output1])
|
194 |
+
#run.click(send_it7, inputs=[prompt, noise_level], outputs=[output0])
|
195 |
+
run.click(send_it2, inputs=[prompt, noise_level], outputs=[output2])
|
196 |
+
run.click(send_it3, inputs=[prompt, noise_level], outputs=[output3])
|
197 |
+
run.click(send_it4, inputs=[prompt, noise_level], outputs=[output4])
|
198 |
+
run.click(send_it5, inputs=[prompt, noise_level], outputs=[output5])
|
199 |
+
run.click(send_itX, inputs=[prompt, noise_level], outputs=[outputX])
|
200 |
+
|
201 |
+
|
202 |
+
with gr.Row():
|
203 |
+
gr.HTML(
|
204 |
+
"""
|
205 |
+
<div class="footer">
|
206 |
+
<p> Demo for <a href="https://huggingface.co/Yntec/DreamAnything">DreamAnything</a> Stable Diffusion model
|
207 |
+
</p>
|
208 |
+
</div>
|
209 |
+
<div class="acknowledgments" style="font-size: 115%; color: #ffffff;">
|
210 |
+
<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!
|
211 |
+
</p>
|
212 |
+
</div>
|
213 |
+
"""
|
214 |
+
)
|
215 |
+
|
216 |
+
demo.launch(enable_queue=True, inline=True)
|
217 |
+
block.queue(concurrency_count=100)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|