Spaces:
Build error
Build error
Emiir
commited on
Commit
·
c1baaf9
1
Parent(s):
9bbc49c
Update app.py
Browse files
app.py
CHANGED
@@ -1,313 +1,123 @@
|
|
1 |
import gradio as gr
|
2 |
-
from datasets import load_dataset
|
3 |
-
from PIL import Image
|
4 |
-
|
5 |
-
import re
|
6 |
import os
|
7 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
}
|
39 |
-
input[type='range'] {
|
40 |
-
accent-color: black;
|
41 |
-
}
|
42 |
-
.dark input[type='range'] {
|
43 |
-
accent-color: #dfdfdf;
|
44 |
-
}
|
45 |
-
.container {
|
46 |
-
max-width: 730px;
|
47 |
-
margin: auto;
|
48 |
-
padding-top: 1.5rem;
|
49 |
-
}
|
50 |
-
#gallery {
|
51 |
-
min-height: 22rem;
|
52 |
-
margin-bottom: 15px;
|
53 |
-
margin-left: auto;
|
54 |
-
margin-right: auto;
|
55 |
-
border-bottom-right-radius: .5rem !important;
|
56 |
-
border-bottom-left-radius: .5rem !important;
|
57 |
-
}
|
58 |
-
#gallery>div>.h-full {
|
59 |
-
min-height: 20rem;
|
60 |
-
}
|
61 |
-
.details:hover {
|
62 |
-
text-decoration: underline;
|
63 |
-
}
|
64 |
-
.gr-button {
|
65 |
-
white-space: nowrap;
|
66 |
-
}
|
67 |
-
.gr-button:focus {
|
68 |
-
border-color: rgb(147 197 253 / var(--tw-border-opacity));
|
69 |
-
outline: none;
|
70 |
-
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
|
71 |
-
--tw-border-opacity: 1;
|
72 |
-
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
|
73 |
-
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
|
74 |
-
--tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
|
75 |
-
--tw-ring-opacity: .5;
|
76 |
-
}
|
77 |
-
#advanced-btn {
|
78 |
-
font-size: .7rem !important;
|
79 |
-
line-height: 19px;
|
80 |
-
margin-top: 12px;
|
81 |
-
margin-bottom: 12px;
|
82 |
-
padding: 2px 8px;
|
83 |
-
border-radius: 14px !important;
|
84 |
-
}
|
85 |
-
#advanced-options {
|
86 |
-
display: none;
|
87 |
-
margin-bottom: 20px;
|
88 |
-
}
|
89 |
-
.footer {
|
90 |
-
margin-bottom: 45px;
|
91 |
-
margin-top: 35px;
|
92 |
-
text-align: center;
|
93 |
-
border-bottom: 1px solid #e5e5e5;
|
94 |
-
}
|
95 |
-
.footer>p {
|
96 |
-
font-size: .8rem;
|
97 |
-
display: inline-block;
|
98 |
-
padding: 0 10px;
|
99 |
-
transform: translateY(10px);
|
100 |
-
background: white;
|
101 |
-
}
|
102 |
-
.dark .footer {
|
103 |
-
border-color: #303030;
|
104 |
-
}
|
105 |
-
.dark .footer>p {
|
106 |
-
background: #0b0f19;
|
107 |
-
}
|
108 |
-
.acknowledgments h4{
|
109 |
-
margin: 1.25em 0 .25em 0;
|
110 |
-
font-weight: bold;
|
111 |
-
font-size: 115%;
|
112 |
-
}
|
113 |
-
.animate-spin {
|
114 |
-
animation: spin 1s linear infinite;
|
115 |
-
}
|
116 |
-
@keyframes spin {
|
117 |
-
from {
|
118 |
-
transform: rotate(0deg);
|
119 |
-
}
|
120 |
-
to {
|
121 |
-
transform: rotate(360deg);
|
122 |
-
}
|
123 |
-
}
|
124 |
-
#share-btn-container {
|
125 |
-
display: flex; padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; width: 13rem;
|
126 |
-
margin-top: 10px;
|
127 |
-
margin-left: auto;
|
128 |
-
}
|
129 |
-
#share-btn {
|
130 |
-
all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.25rem !important; padding-bottom: 0.25rem !important;right:0;
|
131 |
-
}
|
132 |
-
#share-btn * {
|
133 |
-
all: unset;
|
134 |
-
}
|
135 |
-
#share-btn-container div:nth-child(-n+2){
|
136 |
-
width: auto !important;
|
137 |
-
min-height: 0px !important;
|
138 |
-
}
|
139 |
-
#share-btn-container .wrap {
|
140 |
-
display: none !important;
|
141 |
-
}
|
142 |
-
|
143 |
-
.gr-form{
|
144 |
-
flex: 1 1 50%; border-top-right-radius: 0; border-bottom-right-radius: 0;
|
145 |
-
}
|
146 |
-
#prompt-container{
|
147 |
-
gap: 0;
|
148 |
-
}
|
149 |
-
#prompt-text-input, #negative-prompt-text-input{padding: .45rem 0.625rem}
|
150 |
-
#component-16{border-top-width: 1px!important;margin-top: 1em}
|
151 |
-
.image_duplication{position: absolute; width: 100px; left: 50px}
|
152 |
-
"""
|
153 |
|
154 |
-
block = gr.Blocks(css=css)
|
155 |
|
156 |
-
examples = [
|
157 |
-
[
|
158 |
-
'A high tech solarpunk utopia in the Amazon rainforest',
|
159 |
-
'low quality',
|
160 |
-
9
|
161 |
-
],
|
162 |
-
[
|
163 |
-
'A pikachu fine dining with a view to the Eiffel Tower',
|
164 |
-
'low quality',
|
165 |
-
9
|
166 |
-
],
|
167 |
-
[
|
168 |
-
'A mecha robot in a favela in expressionist style',
|
169 |
-
'low quality, 3d, photorealistic',
|
170 |
-
9
|
171 |
-
],
|
172 |
-
[
|
173 |
-
'an insect robot preparing a delicious meal',
|
174 |
-
'low quality, illustration',
|
175 |
-
9
|
176 |
-
],
|
177 |
-
[
|
178 |
-
"A small cabin on top of a snowy mountain in the style of Disney, artstation",
|
179 |
-
'low quality, ugly',
|
180 |
-
9
|
181 |
-
],
|
182 |
-
]
|
183 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
align-items: center;
|
193 |
-
gap: 0.8rem;
|
194 |
-
font-size: 1.75rem;
|
195 |
-
"
|
196 |
-
>
|
197 |
-
<svg
|
198 |
-
width="0.65em"
|
199 |
-
height="0.65em"
|
200 |
-
viewBox="0 0 115 115"
|
201 |
-
fill="none"
|
202 |
-
xmlns="http://www.w3.org/2000/svg"
|
203 |
-
>
|
204 |
-
<rect width="23" height="23" fill="white"></rect>
|
205 |
-
<rect y="69" width="23" height="23" fill="white"></rect>
|
206 |
-
<rect x="23" width="23" height="23" fill="#AEAEAE"></rect>
|
207 |
-
<rect x="23" y="69" width="23" height="23" fill="#AEAEAE"></rect>
|
208 |
-
<rect x="46" width="23" height="23" fill="white"></rect>
|
209 |
-
<rect x="46" y="69" width="23" height="23" fill="white"></rect>
|
210 |
-
<rect x="69" width="23" height="23" fill="black"></rect>
|
211 |
-
<rect x="69" y="69" width="23" height="23" fill="black"></rect>
|
212 |
-
<rect x="92" width="23" height="23" fill="#D9D9D9"></rect>
|
213 |
-
<rect x="92" y="69" width="23" height="23" fill="#AEAEAE"></rect>
|
214 |
-
<rect x="115" y="46" width="23" height="23" fill="white"></rect>
|
215 |
-
<rect x="115" y="115" width="23" height="23" fill="white"></rect>
|
216 |
-
<rect x="115" y="69" width="23" height="23" fill="#D9D9D9"></rect>
|
217 |
-
<rect x="92" y="46" width="23" height="23" fill="#AEAEAE"></rect>
|
218 |
-
<rect x="92" y="115" width="23" height="23" fill="#AEAEAE"></rect>
|
219 |
-
<rect x="92" y="69" width="23" height="23" fill="white"></rect>
|
220 |
-
<rect x="69" y="46" width="23" height="23" fill="white"></rect>
|
221 |
-
<rect x="69" y="115" width="23" height="23" fill="white"></rect>
|
222 |
-
<rect x="69" y="69" width="23" height="23" fill="#D9D9D9"></rect>
|
223 |
-
<rect x="46" y="46" width="23" height="23" fill="black"></rect>
|
224 |
-
<rect x="46" y="115" width="23" height="23" fill="black"></rect>
|
225 |
-
<rect x="46" y="69" width="23" height="23" fill="black"></rect>
|
226 |
-
<rect x="23" y="46" width="23" height="23" fill="#D9D9D9"></rect>
|
227 |
-
<rect x="23" y="115" width="23" height="23" fill="#AEAEAE"></rect>
|
228 |
-
<rect x="23" y="69" width="23" height="23" fill="black"></rect>
|
229 |
-
</svg>
|
230 |
-
<h1 style="font-weight: 900; margin-bottom: 7px;margin-top:5px">
|
231 |
-
Araç Rayiç Değeri Ölçüm Yazılımının Araç Oluşturucu Yapay Zeka Yazılımı
|
232 |
-
</h1>
|
233 |
-
</div>
|
234 |
-
<p style="margin-bottom: 10px; font-size: 94%; line-height: 23px;">
|
235 |
-
Bu yazılım rayicdegeri.com tarafından oluşturulmuştur.
|
236 |
-
</p>
|
237 |
-
</div>
|
238 |
-
"""
|
239 |
-
)
|
240 |
-
with gr.Group():
|
241 |
-
with gr.Box():
|
242 |
-
with gr.Row(elem_id="prompt-container").style(mobile_collapse=False, equal_height=True):
|
243 |
-
with gr.Column():
|
244 |
-
text = gr.Textbox(
|
245 |
-
label="Enter your prompt",
|
246 |
-
show_label=False,
|
247 |
-
max_lines=1,
|
248 |
-
placeholder="Enter your prompt",
|
249 |
-
elem_id="prompt-text-input",
|
250 |
-
).style(
|
251 |
-
border=(True, False, True, True),
|
252 |
-
rounded=(True, False, False, True),
|
253 |
-
container=False,
|
254 |
-
)
|
255 |
-
negative = gr.Textbox(
|
256 |
-
label="Enter your negative prompt",
|
257 |
-
show_label=False,
|
258 |
-
max_lines=1,
|
259 |
-
placeholder="Enter a negative prompt",
|
260 |
-
elem_id="negative-prompt-text-input",
|
261 |
-
).style(
|
262 |
-
border=(True, False, True, True),
|
263 |
-
rounded=(True, False, False, True),
|
264 |
-
container=False,
|
265 |
-
)
|
266 |
-
btn = gr.Button("Generate image").style(
|
267 |
-
margin=False,
|
268 |
-
rounded=(False, True, True, False),
|
269 |
-
full_width=False,
|
270 |
-
)
|
271 |
|
272 |
-
|
273 |
-
|
274 |
-
|
|
|
|
|
|
|
|
|
275 |
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
#
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
# seed = gr.Slider(
|
284 |
-
# label="Seed",
|
285 |
-
# minimum=0,
|
286 |
-
# maximum=2147483647,
|
287 |
-
# step=1,
|
288 |
-
# randomize=True,
|
289 |
-
# )
|
290 |
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
block.queue(concurrency_count=80, max_size=100).launch(max_threads=150)
|
|
|
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("dreamlikeart, " + prompt_text)
|
16 |
+
else:
|
17 |
+
return text_gen("")
|
18 |
+
proc1=gr.Interface.load("models/dreamlike-art/dreamlike-diffusion-1.0")
|
19 |
|
20 |
+
def restart_script_periodically():
|
21 |
+
while True:
|
22 |
+
random_time = random.randint(540, 600)
|
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 |
+
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:
|
52 |
+
time.sleep(2)
|
53 |
+
queue.put(prompt_with_noise)
|
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:
|
60 |
+
time.sleep(2)
|
61 |
+
queue.put(prompt_with_noise)
|
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 |
+
|
84 |
+
with gr.Column(elem_id="col-container"):
|
85 |
+
with gr.Row(variant="compact"):
|
86 |
+
input_text = gr.Textbox(
|
87 |
+
label="Short Prompt",
|
88 |
+
show_label=False,
|
89 |
+
max_lines=2,
|
90 |
+
placeholder="Araç bilginizi giriniz.",
|
91 |
+
).style(
|
92 |
+
container=False,
|
93 |
+
)
|
94 |
+
see_prompts = gr.Button("Oluştur [Çok detaylı]").style(full_width=False)
|
95 |
+
|
96 |
+
|
97 |
+
with gr.Row(variant="compact"):
|
98 |
+
prompt = gr.Textbox(
|
99 |
+
label="Enter your prompt",
|
100 |
+
show_label=False,
|
101 |
+
max_lines=2,
|
102 |
+
placeholder="Araç bilginizi giriniz.",
|
103 |
+
).style(
|
104 |
+
container=False,
|
105 |
+
)
|
106 |
+
run = gr.Button("Oluştur [Az detaylı]").style(full_width=False)
|
107 |
|
108 |
+
with gr.Row():
|
109 |
+
with gr.Row():
|
110 |
+
noise_level = gr.Slider(minimum=0.0, maximum=3, step=0.1, label="Noise Level")
|
111 |
+
with gr.Row():
|
112 |
+
with gr.Row():
|
113 |
+
output1=gr.Image(label="Dreamlike Diffusion 1.0",show_label=False)
|
114 |
+
output2=gr.Image(label="Dreamlike Diffusion 1.0",show_label=False)
|
115 |
+
|
116 |
+
|
117 |
+
see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt], queue=False)
|
118 |
+
run.click(send_it1, inputs=[prompt, noise_level], outputs=[output1])
|
119 |
+
run.click(send_it2, inputs=[prompt, noise_level], outputs=[output2])
|
120 |
+
|
121 |
+
|
122 |
+
demo.launch(enable_queue=True, inline=True)
|
123 |
+
block.queue(concurrency_count=100)
|
|