Spaces:
Runtime error
Runtime error
Commit
•
68dd11f
1
Parent(s):
ac6bdf7
Update app.py
Browse files
app.py
CHANGED
@@ -9,13 +9,15 @@ 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("dreamlikeart, " + prompt_text)
|
16 |
else:
|
17 |
return text_gen("")
|
18 |
-
|
|
|
19 |
|
20 |
def restart_script_periodically():
|
21 |
while True:
|
@@ -23,11 +25,9 @@ def restart_script_periodically():
|
|
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 |
|
@@ -35,7 +35,7 @@ def add_random_noise(prompt, noise_level=0.00):
|
|
35 |
if noise_level == 0:
|
36 |
noise_level = 0.00
|
37 |
percentage_noise = noise_level * 5
|
38 |
-
num_noise_chars = int(len(prompt) * (percentage_noise/100))
|
39 |
noise_indices = random.sample(range(len(prompt)), num_noise_chars)
|
40 |
prompt_list = list(prompt)
|
41 |
noise_chars = list(string.ascii_letters + string.punctuation + ' ' + string.digits)
|
@@ -44,8 +44,6 @@ def add_random_noise(prompt, noise_level=0.00):
|
|
44 |
prompt_list[index] = random.choice(noise_chars)
|
45 |
return "".join(prompt_list)
|
46 |
|
47 |
-
|
48 |
-
|
49 |
def send_it1(inputs, noise_level, proc1=proc1):
|
50 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
51 |
while queue.qsize() >= queue_threshold:
|
@@ -62,23 +60,6 @@ def send_it2(inputs, noise_level, proc1=proc1):
|
|
62 |
output2 = proc1(prompt_with_noise)
|
63 |
return output2
|
64 |
|
65 |
-
#def send_it3(inputs, noise_level, proc1=proc1):
|
66 |
-
#prompt_with_noise = add_random_noise(inputs, noise_level)
|
67 |
-
#while queue.qsize() >= queue_threshold:
|
68 |
-
#time.sleep(2)
|
69 |
-
#queue.put(prompt_with_noise)
|
70 |
-
#output3 = proc1(prompt_with_noise)
|
71 |
-
#return output3
|
72 |
-
|
73 |
-
#def send_it4(inputs, noise_level, proc1=proc1):
|
74 |
-
#prompt_with_noise = add_random_noise(inputs, noise_level)
|
75 |
-
#while queue.qsize() >= queue_threshold:
|
76 |
-
#time.sleep(2)
|
77 |
-
#queue.put(prompt_with_noise)
|
78 |
-
#output4 = proc1(prompt_with_noise)
|
79 |
-
#return output4
|
80 |
-
|
81 |
-
|
82 |
with gr.Blocks(css='style.css') as demo:
|
83 |
gr.HTML(
|
84 |
"""
|
@@ -104,38 +85,30 @@ with gr.Blocks(css='style.css') as demo:
|
|
104 |
label="Short Prompt",
|
105 |
show_label=False,
|
106 |
max_lines=2,
|
107 |
-
placeholder="Enter a basic idea and click 'Magic Prompt'. Got no ideas? No problem, Simply just hit the magic button!"
|
108 |
-
).style(
|
109 |
-
container=False,
|
110 |
)
|
111 |
see_prompts = gr.Button("✨ Magic Prompt ✨").style(full_width=False)
|
112 |
|
113 |
-
|
114 |
with gr.Row(variant="compact"):
|
115 |
prompt = gr.Textbox(
|
116 |
label="Enter your prompt",
|
117 |
show_label=False,
|
118 |
max_lines=2,
|
119 |
-
placeholder="Full Prompt"
|
120 |
-
).style(
|
121 |
-
container=False,
|
122 |
)
|
123 |
run = gr.Button("Generate Images").style(full_width=False)
|
124 |
|
125 |
with gr.Row():
|
126 |
-
|
127 |
-
|
128 |
with gr.Row():
|
129 |
-
|
130 |
-
|
131 |
-
output2=gr.Image(label="Dreamlike Diffusion 1.0",show_label=False)
|
132 |
|
133 |
-
|
134 |
see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt], queue=False)
|
135 |
run.click(send_it1, inputs=[prompt, noise_level], outputs=[output1])
|
136 |
run.click(send_it2, inputs=[prompt, noise_level], outputs=[output2])
|
137 |
|
138 |
-
|
139 |
with gr.Row():
|
140 |
gr.HTML(
|
141 |
"""
|
@@ -151,4 +124,4 @@ with gr.Blocks(css='style.css') as demo:
|
|
151 |
)
|
152 |
|
153 |
demo.launch(enable_queue=True, inline=True)
|
154 |
-
block.queue(concurrency_count=100)
|
|
|
9 |
from threading import Thread
|
10 |
import emoji
|
11 |
|
12 |
+
text_gen = gr.Interface.load("spaces/phenomenon1981/MagicPrompt-Stable-Diffusion")
|
13 |
+
|
14 |
def get_prompts(prompt_text):
|
15 |
if prompt_text:
|
16 |
return text_gen("dreamlikeart, " + prompt_text)
|
17 |
else:
|
18 |
return text_gen("")
|
19 |
+
|
20 |
+
proc1 = gr.Interface.load("models/dreamlike-art/dreamlike-diffusion-1.0")
|
21 |
|
22 |
def restart_script_periodically():
|
23 |
while True:
|
|
|
25 |
time.sleep(random_time)
|
26 |
os.execl(sys.executable, sys.executable, *sys.argv)
|
27 |
|
|
|
28 |
restart_thread = Thread(target=restart_script_periodically, daemon=True)
|
29 |
restart_thread.start()
|
30 |
|
|
|
31 |
queue = Queue()
|
32 |
queue_threshold = 100
|
33 |
|
|
|
35 |
if noise_level == 0:
|
36 |
noise_level = 0.00
|
37 |
percentage_noise = noise_level * 5
|
38 |
+
num_noise_chars = int(len(prompt) * (percentage_noise / 100))
|
39 |
noise_indices = random.sample(range(len(prompt)), num_noise_chars)
|
40 |
prompt_list = list(prompt)
|
41 |
noise_chars = list(string.ascii_letters + string.punctuation + ' ' + string.digits)
|
|
|
44 |
prompt_list[index] = random.choice(noise_chars)
|
45 |
return "".join(prompt_list)
|
46 |
|
|
|
|
|
47 |
def send_it1(inputs, noise_level, proc1=proc1):
|
48 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
49 |
while queue.qsize() >= queue_threshold:
|
|
|
60 |
output2 = proc1(prompt_with_noise)
|
61 |
return output2
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
with gr.Blocks(css='style.css') as demo:
|
64 |
gr.HTML(
|
65 |
"""
|
|
|
85 |
label="Short Prompt",
|
86 |
show_label=False,
|
87 |
max_lines=2,
|
88 |
+
placeholder="Enter a basic idea and click 'Magic Prompt'. Got no ideas? No problem, Simply just hit the magic button!"
|
|
|
|
|
89 |
)
|
90 |
see_prompts = gr.Button("✨ Magic Prompt ✨").style(full_width=False)
|
91 |
|
|
|
92 |
with gr.Row(variant="compact"):
|
93 |
prompt = gr.Textbox(
|
94 |
label="Enter your prompt",
|
95 |
show_label=False,
|
96 |
max_lines=2,
|
97 |
+
placeholder="Full Prompt"
|
|
|
|
|
98 |
)
|
99 |
run = gr.Button("Generate Images").style(full_width=False)
|
100 |
|
101 |
with gr.Row():
|
102 |
+
noise_level = gr.Slider(minimum=0.0, maximum=3, step=0.1, label="Noise Level")
|
103 |
+
|
104 |
with gr.Row():
|
105 |
+
output1 = gr.Image(label="Dreamlike Diffusion 1.0", show_label=False)
|
106 |
+
output2 = gr.Image(label="Dreamlike Diffusion 1.0", show_label=False)
|
|
|
107 |
|
|
|
108 |
see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt], queue=False)
|
109 |
run.click(send_it1, inputs=[prompt, noise_level], outputs=[output1])
|
110 |
run.click(send_it2, inputs=[prompt, noise_level], outputs=[output2])
|
111 |
|
|
|
112 |
with gr.Row():
|
113 |
gr.HTML(
|
114 |
"""
|
|
|
124 |
)
|
125 |
|
126 |
demo.launch(enable_queue=True, inline=True)
|
127 |
+
block.queue(concurrency_count=100)
|