Spaces:
Runtime error
Runtime error
phenomenon1981
commited on
Commit
•
f7ccecd
1
Parent(s):
d2406c4
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,8 @@ from pathlib import Path
|
|
5 |
import random
|
6 |
import string
|
7 |
import time
|
|
|
|
|
8 |
|
9 |
text_gen=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion")
|
10 |
proc1=gr.Interface.load("models/dreamlike-art/dreamlike-photoreal-2.0")
|
@@ -15,58 +17,116 @@ def add_random_noise(prompt, noise_level=0.1):
|
|
15 |
noise = "".join(random.choices(string.ascii_letters + string.punctuation, k=int(noise_level * 10)))
|
16 |
return prompt + noise
|
17 |
|
|
|
|
|
18 |
def send_it1(inputs, noise_level, proc1=proc1):
|
|
|
19 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
21 |
time.sleep(1)
|
22 |
return output1
|
23 |
|
24 |
def send_it2(inputs, noise_level, proc1=proc1):
|
|
|
25 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
|
|
26 |
output2 = proc1(prompt_with_noise)
|
|
|
|
|
|
|
|
|
27 |
time.sleep(1)
|
28 |
return output2
|
29 |
|
30 |
def send_it3(inputs, noise_level, proc1=proc1):
|
|
|
31 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
|
|
32 |
output3 = proc1(prompt_with_noise)
|
|
|
|
|
|
|
|
|
33 |
time.sleep(1)
|
34 |
return output3
|
35 |
|
36 |
def send_it4(inputs, noise_level, proc1=proc1):
|
|
|
37 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
|
|
38 |
output4 = proc1(prompt_with_noise)
|
|
|
|
|
|
|
|
|
39 |
time.sleep(1)
|
40 |
return output4
|
41 |
|
42 |
def send_it5(inputs, noise_level, proc5=proc5):
|
|
|
43 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
|
|
44 |
output5 = proc5(prompt_with_noise)
|
|
|
|
|
|
|
|
|
45 |
time.sleep(1)
|
46 |
return output5
|
47 |
|
48 |
def send_it6(inputs, noise_level, proc5=proc5):
|
|
|
49 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
|
|
50 |
output6 = proc5(prompt_with_noise)
|
|
|
|
|
|
|
|
|
51 |
time.sleep(1)
|
52 |
return output6
|
53 |
|
54 |
def send_it7(inputs, noise_level, proc5=proc5):
|
|
|
55 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
|
|
56 |
output7 = proc5(prompt_with_noise)
|
|
|
|
|
|
|
|
|
57 |
time.sleep(1)
|
58 |
return output7
|
59 |
|
60 |
def send_it8(inputs, noise_level, proc5=proc5):
|
|
|
61 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
|
|
62 |
output8 = proc5(prompt_with_noise)
|
|
|
|
|
|
|
|
|
63 |
time.sleep(1)
|
64 |
return output8
|
65 |
|
66 |
|
|
|
67 |
def get_prompts(prompt_text):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
time.sleep(1)
|
69 |
-
return
|
70 |
|
71 |
|
72 |
with gr.Blocks() as myface:
|
@@ -94,8 +154,8 @@ with gr.Blocks() as myface:
|
|
94 |
with gr.Row():
|
95 |
output7=gr.Image(label="Dreamlike Diffusion 1.0", blocking=True, timeout=30)
|
96 |
output8=gr.Image(label="Dreamlike Diffusion 1.0", blocking=True, timeout=30)
|
97 |
-
|
98 |
|
|
|
99 |
run.click(send_it1, inputs=[prompt, noise_level], outputs=[output1])
|
100 |
run.click(send_it2, inputs=[prompt, noise_level], outputs=[output2])
|
101 |
run.click(send_it3, inputs=[prompt, noise_level], outputs=[output3])
|
@@ -106,5 +166,7 @@ with gr.Blocks() as myface:
|
|
106 |
run.click(send_it8, inputs=[prompt, noise_level], outputs=[output8])
|
107 |
see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt])
|
108 |
|
|
|
|
|
109 |
myface.queue(concurrency_count=8)
|
110 |
myface.launch(enable_queue=True, inline=True)
|
|
|
5 |
import random
|
6 |
import string
|
7 |
import time
|
8 |
+
from queue import Queue
|
9 |
+
queue = Queue()
|
10 |
|
11 |
text_gen=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion")
|
12 |
proc1=gr.Interface.load("models/dreamlike-art/dreamlike-photoreal-2.0")
|
|
|
17 |
noise = "".join(random.choices(string.ascii_letters + string.punctuation, k=int(noise_level * 10)))
|
18 |
return prompt + noise
|
19 |
|
20 |
+
queue_length_counter = 0
|
21 |
+
|
22 |
def send_it1(inputs, noise_level, proc1=proc1):
|
23 |
+
global queue_length_counter
|
24 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
25 |
+
queue_length_counter += 1
|
26 |
+
output1 = proc1(prompt_with_noise)
|
27 |
+
queue_length_counter -= 1
|
28 |
+
if queue_length_counter > 25:
|
29 |
+
queue.queue.clear()
|
30 |
+
queue_length_counter = 0
|
31 |
time.sleep(1)
|
32 |
return output1
|
33 |
|
34 |
def send_it2(inputs, noise_level, proc1=proc1):
|
35 |
+
global queue_length_counter
|
36 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
37 |
+
queue_length_counter += 1
|
38 |
output2 = proc1(prompt_with_noise)
|
39 |
+
queue_length_counter -= 1
|
40 |
+
if queue_length_counter > 25:
|
41 |
+
queue.queue.clear()
|
42 |
+
queue_length_counter = 0
|
43 |
time.sleep(1)
|
44 |
return output2
|
45 |
|
46 |
def send_it3(inputs, noise_level, proc1=proc1):
|
47 |
+
global queue_length_counter
|
48 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
49 |
+
queue_length_counter += 1
|
50 |
output3 = proc1(prompt_with_noise)
|
51 |
+
queue_length_counter -= 1
|
52 |
+
if queue_length_counter > 25:
|
53 |
+
queue.queue.clear()
|
54 |
+
queue_length_counter = 0
|
55 |
time.sleep(1)
|
56 |
return output3
|
57 |
|
58 |
def send_it4(inputs, noise_level, proc1=proc1):
|
59 |
+
global queue_length_counter
|
60 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
61 |
+
queue_length_counter += 1
|
62 |
output4 = proc1(prompt_with_noise)
|
63 |
+
queue_length_counter -= 1
|
64 |
+
if queue_length_counter > 25:
|
65 |
+
queue.queue.clear()
|
66 |
+
queue_length_counter = 0
|
67 |
time.sleep(1)
|
68 |
return output4
|
69 |
|
70 |
def send_it5(inputs, noise_level, proc5=proc5):
|
71 |
+
global queue_length_counter
|
72 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
73 |
+
queue_length_counter += 1
|
74 |
output5 = proc5(prompt_with_noise)
|
75 |
+
queue_length_counter -= 1
|
76 |
+
if queue_length_counter > 25:
|
77 |
+
queue.queue.clear()
|
78 |
+
queue_length_counter = 0
|
79 |
time.sleep(1)
|
80 |
return output5
|
81 |
|
82 |
def send_it6(inputs, noise_level, proc5=proc5):
|
83 |
+
global queue_length_counter
|
84 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
85 |
+
queue_length_counter += 1
|
86 |
output6 = proc5(prompt_with_noise)
|
87 |
+
queue_length_counter -= 1
|
88 |
+
if queue_length_counter > 25:
|
89 |
+
queue.queue.clear()
|
90 |
+
queue_length_counter = 0
|
91 |
time.sleep(1)
|
92 |
return output6
|
93 |
|
94 |
def send_it7(inputs, noise_level, proc5=proc5):
|
95 |
+
global queue_length_counter
|
96 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
97 |
+
queue_length_counter += 1
|
98 |
output7 = proc5(prompt_with_noise)
|
99 |
+
queue_length_counter -= 1
|
100 |
+
if queue_length_counter > 25:
|
101 |
+
queue.queue.clear()
|
102 |
+
queue_length_counter = 0
|
103 |
time.sleep(1)
|
104 |
return output7
|
105 |
|
106 |
def send_it8(inputs, noise_level, proc5=proc5):
|
107 |
+
global queue_length_counter
|
108 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
109 |
+
queue_length_counter += 1
|
110 |
output8 = proc5(prompt_with_noise)
|
111 |
+
queue_length_counter -= 1
|
112 |
+
if queue_length_counter > 25:
|
113 |
+
queue.queue.clear()
|
114 |
+
queue_length_counter = 0
|
115 |
time.sleep(1)
|
116 |
return output8
|
117 |
|
118 |
|
119 |
+
|
120 |
def get_prompts(prompt_text):
|
121 |
+
global queue_length_counter
|
122 |
+
queue_length_counter += 1
|
123 |
+
output = text_gen(prompt_text)
|
124 |
+
queue_length_counter -= 1
|
125 |
+
if queue_length_counter > 25:
|
126 |
+
queue.queue.clear()
|
127 |
+
queue_length_counter = 0
|
128 |
time.sleep(1)
|
129 |
+
return output
|
130 |
|
131 |
|
132 |
with gr.Blocks() as myface:
|
|
|
154 |
with gr.Row():
|
155 |
output7=gr.Image(label="Dreamlike Diffusion 1.0", blocking=True, timeout=30)
|
156 |
output8=gr.Image(label="Dreamlike Diffusion 1.0", blocking=True, timeout=30)
|
|
|
157 |
|
158 |
+
|
159 |
run.click(send_it1, inputs=[prompt, noise_level], outputs=[output1])
|
160 |
run.click(send_it2, inputs=[prompt, noise_level], outputs=[output2])
|
161 |
run.click(send_it3, inputs=[prompt, noise_level], outputs=[output3])
|
|
|
166 |
run.click(send_it8, inputs=[prompt, noise_level], outputs=[output8])
|
167 |
see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt])
|
168 |
|
169 |
+
|
170 |
+
|
171 |
myface.queue(concurrency_count=8)
|
172 |
myface.launch(enable_queue=True, inline=True)
|