Spaces:
Build error
Build error
Emiir
commited on
Commit
ยท
2966162
1
Parent(s):
294bd5f
Update app.py
Browse files
app.py
CHANGED
@@ -9,13 +9,18 @@ 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:
|
@@ -27,25 +32,29 @@ def restart_script_periodically():
|
|
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 |
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)
|
42 |
-
noise_chars.extend(
|
|
|
|
|
|
|
|
|
|
|
43 |
for index in noise_indices:
|
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:
|
@@ -54,6 +63,7 @@ def send_it1(inputs, noise_level, proc1=proc1):
|
|
54 |
output1 = proc1(prompt_with_noise)
|
55 |
return output1
|
56 |
|
|
|
57 |
def send_it2(inputs, noise_level, proc1=proc1):
|
58 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
59 |
while queue.qsize() >= queue_threshold:
|
@@ -62,49 +72,47 @@ 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
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
|
82 |
with gr.Blocks(css='style.css') as demo:
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
with gr.Row():
|
96 |
-
|
97 |
-
|
98 |
with gr.Row():
|
99 |
-
|
100 |
-
|
101 |
-
output2=gr.Image(label="Dreamlike Diffusion 1.0",show_label=False)
|
102 |
-
|
103 |
-
|
104 |
-
see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt], queue=False)
|
105 |
-
run.click(send_it1, inputs=[prompt, noise_level], outputs=[output1])
|
106 |
-
run.click(send_it2, inputs=[prompt, noise_level], outputs=[output2])
|
107 |
|
|
|
|
|
|
|
108 |
|
109 |
-
|
110 |
-
|
|
|
9 |
from threading import Thread
|
10 |
import emoji
|
11 |
|
12 |
+
text_gen = gr.Interface.load("spaces/phenomenon1981/MagicPrompt-Stable-Diffusion")
|
13 |
+
|
14 |
+
|
15 |
def get_prompts(prompt_text):
|
16 |
if prompt_text:
|
17 |
return text_gen("dreamlikeart, " + prompt_text)
|
18 |
else:
|
19 |
return text_gen("")
|
20 |
+
|
21 |
+
|
22 |
+
proc1 = gr.Interface.load("models/dreamlike-art/dreamlike-diffusion-1.0")
|
23 |
+
|
24 |
|
25 |
def restart_script_periodically():
|
26 |
while True:
|
|
|
32 |
restart_thread = Thread(target=restart_script_periodically, daemon=True)
|
33 |
restart_thread.start()
|
34 |
|
|
|
35 |
queue = Queue()
|
36 |
queue_threshold = 100
|
37 |
|
38 |
+
|
39 |
def add_random_noise(prompt, noise_level=0.00):
|
40 |
if noise_level == 0:
|
41 |
noise_level = 0.00
|
42 |
percentage_noise = noise_level * 5
|
43 |
+
num_noise_chars = int(len(prompt) * (percentage_noise / 100))
|
44 |
noise_indices = random.sample(range(len(prompt)), num_noise_chars)
|
45 |
prompt_list = list(prompt)
|
46 |
noise_chars = list(string.ascii_letters + string.punctuation + ' ' + string.digits)
|
47 |
+
noise_chars.extend(
|
48 |
+
['๐', '๐ฉ', '๐', '๐ค', '๐', '๐ค', '๐ญ', '๐', '๐ท', '๐คฏ', '๐คซ', '๐ฅด', '๐ด', '๐คฉ', '๐ฅณ', '๐', '๐ฉ', '๐คช',
|
49 |
+
'๐', '๐คข', '๐', '๐น', '๐ป', '๐ค', '๐ฝ', '๐', '๐', '๐
', '๐', '๐', '๐', '๐', '๐', '๐', '๐ฎ', 'โค๏ธ',
|
50 |
+
'๐', '๐', '๐', '๐', '๐ถ', '๐ฑ', '๐ญ', '๐น', '๐ฆ', '๐ป', '๐จ', '๐ฏ', '๐ฆ', '๐', '๐ฅ', '๐ง๏ธ', '๐', '๐',
|
51 |
+
'๐ฅ', '๐ด', '๐', '๐บ', '๐ป', '๐ธ', '๐จ', '๐
', '๐', 'โ๏ธ', 'โ๏ธ', 'โ๏ธ', 'โ๏ธ', '๐ค๏ธ', 'โ
๏ธ', '๐ฅ๏ธ', '๐ฆ๏ธ', '๐ง๏ธ',
|
52 |
+
'๐ฉ๏ธ', '๐จ๏ธ', '๐ซ๏ธ', 'โ๏ธ', '๐ฌ๏ธ', '๐จ', '๐ช๏ธ', '๐'])
|
53 |
for index in noise_indices:
|
54 |
prompt_list[index] = random.choice(noise_chars)
|
55 |
return "".join(prompt_list)
|
56 |
|
57 |
|
|
|
58 |
def send_it1(inputs, noise_level, proc1=proc1):
|
59 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
60 |
while queue.qsize() >= queue_threshold:
|
|
|
63 |
output1 = proc1(prompt_with_noise)
|
64 |
return output1
|
65 |
|
66 |
+
|
67 |
def send_it2(inputs, noise_level, proc1=proc1):
|
68 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
69 |
while queue.qsize() >= queue_threshold:
|
|
|
72 |
output2 = proc1(prompt_with_noise)
|
73 |
return output2
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
+
# def send_it3(inputs, noise_level, proc1=proc1):
|
77 |
+
# prompt_with_noise = add_random_noise(inputs, noise_level)
|
78 |
+
# while queue.qsize() >= queue_threshold:
|
79 |
+
# time.sleep(2)
|
80 |
+
# queue.put(prompt_with_noise)
|
81 |
+
# output3 = proc1(prompt_with_noise)
|
82 |
+
# return output3
|
83 |
+
|
84 |
+
# def send_it4(inputs, noise_level, proc1=proc1):
|
85 |
+
# prompt_with_noise = add_random_noise(inputs, noise_level)
|
86 |
+
# while queue.qsize() >= queue_threshold:
|
87 |
+
# time.sleep(2)
|
88 |
+
# queue.put(prompt_with_noise)
|
89 |
+
# output4 = proc1(prompt_with_noise)
|
90 |
+
# return output4
|
91 |
|
92 |
|
93 |
with gr.Blocks(css='style.css') as demo:
|
94 |
+
with gr.Row(variant="compact"):
|
95 |
+
prompt = gr.Textbox(
|
96 |
+
label="Enter your prompt",
|
97 |
+
show_label=False,
|
98 |
+
max_lines=2,
|
99 |
+
placeholder="Araรง bilginizi giriniz.",
|
100 |
+
).style(
|
101 |
+
container=False,
|
102 |
+
)
|
103 |
+
run = gr.Button("Oluลtur [Az detaylฤฑ]").style(full_width=False)
|
104 |
+
|
105 |
+
with gr.Row():
|
106 |
with gr.Row():
|
107 |
+
noise_level = gr.Slider(minimum=0.0, maximum=3, step=0.1, label="Gรถrรผntรผnรผn Gรผrรผltรผ Katsayฤฑsฤฑ")
|
108 |
+
with gr.Row():
|
109 |
with gr.Row():
|
110 |
+
output1 = gr.Image(label="Dreamlike Diffusion 1.0", show_label=False)
|
111 |
+
output2 = gr.Image(label="Dreamlike Diffusion 1.0", show_label=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
+
see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt], queue=False)
|
114 |
+
run.click(send_it1, inputs=[prompt, noise_level], outputs=[output1])
|
115 |
+
run.click(send_it2, inputs=[prompt, noise_level], outputs=[output2])
|
116 |
|
117 |
+
demo.launch(enable_queue=True, inline=True)
|
118 |
+
block.queue(concurrency_count=100)
|