MrDrmm commited on
Commit
34c7716
·
verified ·
1 Parent(s): e6b822c

Upload app-3.py

Browse files
Files changed (1) hide show
  1. app-3.py +318 -0
app-3.py ADDED
@@ -0,0 +1,318 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from random import randint
3
+
4
+ import torch
5
+ import os
6
+
7
+ os.environ["CUDA_VISIBLE_DEVICES"] = "" # Отключаем CUDA
8
+
9
+
10
+ device = "cpu" # Используем CPU
11
+ model_repo_id = "stabilityai/sdxl-turbo"
12
+
13
+ torch_dtype = torch.float32 # Тип данных для CPU
14
+
15
+ models = [
16
+ 'stabilityai/stable-diffusion-3.5-large-turbo',
17
+ 'black-forest-labs/FLUX.1-dev',
18
+ 'strangerzonehf/Flux-Isometric-3D-LoRA',
19
+ 'ckpt/kivotos-xl-2.0',
20
+ 'stabilityai/stable-diffusion-3.5-large',
21
+ 'yodayo-ai/clandestine-xl-1.0',
22
+ 'yodayo-ai/kivotos-xl-2.0',
23
+ 'yodayo-ai/holodayo-xl-2.1',
24
+ 'prithivMLmods/SD3.5-Large-Anime-LoRA',
25
+ 'FluffyKaeloky/Midnight-Miqu-103B-v1.5',
26
+ 'cagliostrolab/animagine-xl-3.1',
27
+ 'votepurchase/ponyDiffusionV6XL',
28
+ 'eienmojiki/Anything-XL',
29
+ 'eienmojiki/Starry-XL-v5.2',
30
+ "digiplay/MilkyWonderland_v1",
31
+ 'Sombressoul/Yi-34B-200K-AWQ',
32
+ 'digiplay/majicMIX_realistic_v7',
33
+ 'votepurchase/counterfeitV30_v30',
34
+ 'Linaqruf/animagine-xl-2.0',
35
+ 'KBlueLeaf/Kohaku-XL-Epsilon-rev3',
36
+ 'KBlueLeaf/Kohaku-XL-Zeta',
37
+ 'kayfahaarukku/UrangDiffusion-1.4',
38
+ 'Eugeoter/artiwaifu-diffusion-2.0',
39
+ 'Raelina/Rae-Diffusion-XL-V2',
40
+ 'Raelina/Raemu-XL-V4',
41
+ 'Jonjew/NSFWMaster',
42
+ ]
43
+
44
+ def load_fn(models):
45
+ global models_load
46
+ models_load = {}
47
+ for model in models:
48
+ if model not in models_load.keys():
49
+ try:
50
+ m = gr.load(f'models/{model}')
51
+ except Exception as error:
52
+ m = gr.Interface(lambda txt: None, ['text'], ['image'])
53
+ models_load.update({model: m})
54
+
55
+ load_fn(models)
56
+
57
+ num_models = len(models)
58
+ default_models = models[:num_models]
59
+
60
+ def extend_choices(choices):
61
+ return choices + (num_models - len(choices)) * ['NA']
62
+
63
+ def update_imgbox(choices):
64
+ choices_plus = extend_choices(choices)
65
+ return [gr.Image(None, label=m, visible=(m != 'NA'), elem_id="custom_image") for m in choices_plus]
66
+
67
+ def gen_fn(model_str, prompt):
68
+ if model_str == 'NA':
69
+ return None
70
+ noise = str(randint(0, 9999999))
71
+ return models_load[model_str](f'{prompt} {noise}')
72
+
73
+ def make_me():
74
+ with gr.Row():
75
+ with gr.Column(scale=1):
76
+ txt_input = gr.Textbox(
77
+ label='Your prompt:',
78
+ lines=3,
79
+ container=False,
80
+ elem_id="custom_textbox",
81
+ placeholder="Prompt"
82
+ )
83
+ with gr.Row():
84
+ gen_button = gr.Button('Generate images', elem_id="custom_gen_button")
85
+ stop_button = gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
86
+
87
+ def on_generate_click():
88
+ return gr.Button('Generate images', elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=True, elem_id="custom_stop_button")
89
+
90
+ def on_stop_click():
91
+ return gr.Button('Generate images', elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
92
+
93
+ gen_button.click(on_generate_click, inputs=None, outputs=[gen_button, stop_button])
94
+ stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button])
95
+
96
+ # Делим вывод изображений на два ряда
97
+ with gr.Row():
98
+ half = len(default_models) // 2
99
+ output_row1 = [gr.Image(label=m, min_width=250, height=250, elem_id="custom_image") for m in default_models[:half]]
100
+ output_row2 = [gr.Image(label=m, min_width=250, height=250, elem_id="custom_image") for m in default_models[half:]]
101
+ current_models_row1 = [gr.Textbox(m, visible=False) for m in default_models[:half]]
102
+ current_models_row2 = [gr.Textbox(m, visible=False) for m in default_models[half:]]
103
+
104
+ # Первый ряд изображений
105
+ for m, o in zip(current_models_row1, output_row1):
106
+ gen_event = gen_button.click(gen_fn, [m, txt_input], o)
107
+ stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button], cancels=[gen_event])
108
+
109
+ # Второй ряд изображений
110
+ for m, o in zip(current_models_row2, output_row2):
111
+ gen_event = gen_button.click(gen_fn, [m, txt_input], o)
112
+ stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button], cancels=[gen_event])
113
+
114
+ # Разделяем чекбоксы на два ряда
115
+ with gr.Accordion('Model selection', elem_id="custom_accordion"):
116
+ half = len(models) // 2
117
+ model_choice_row1 = models[:half]
118
+ model_choice_row2 = models[half:]
119
+
120
+ model_choice1 = gr.CheckboxGroup(
121
+ model_choice_row1,
122
+ label=f'{len(model_choice_row1)} models selected',
123
+ value=default_models[:half],
124
+ interactive=True,
125
+ elem_id="custom_checkbox_group"
126
+ )
127
+ model_choice2 = gr.CheckboxGroup(
128
+ model_choice_row2,
129
+ label=f'{len(model_choice_row2)} models selected',
130
+ value=default_models[half:],
131
+ interactive=True,
132
+ elem_id="custom_checkbox_group"
133
+ )
134
+
135
+ # Обновляем первый ряд
136
+ model_choice1.change(update_imgbox, model_choice1, output_row1)
137
+ model_choice1.change(extend_choices, model_choice1, current_models_row1)
138
+
139
+ # Обновляем второй ряд
140
+ model_choice2.change(update_imgbox, model_choice2, output_row2)
141
+ model_choice2.change(extend_choices, model_choice2, current_models_row2)
142
+
143
+ with gr.Row():
144
+ gr.HTML("")
145
+
146
+ custom_css = """
147
+ :root {
148
+ --body-background-fill: #2d3d4f;
149
+ }
150
+
151
+ body {
152
+ background-color: var(--body-background-fill) !important;
153
+ color: #2d3d4f;
154
+ margin: 0;
155
+ padding: 0;
156
+ font-family: Arial, sans-serif;
157
+ height: 100vh;
158
+ overflow-y: auto;
159
+ }
160
+
161
+ .gradio-container {
162
+ background-color: #2d3d4f;
163
+ color: #c5c6c7;
164
+ padding: 20px;
165
+ border-radius: 8px;
166
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
167
+ width: 100%;
168
+ max-width: 1200px;
169
+ margin: 20px auto;
170
+ display: block;
171
+ min-height: 100vh;
172
+ }
173
+
174
+ .app_title {
175
+ background-color: #2d3d4f;
176
+ color: #c5c6c7;
177
+ padding: 10px 20px;
178
+ border-bottom: 1px solid #3b4252;
179
+ text-align: center;
180
+ font-size: 24px;
181
+ font-weight: bold;
182
+ width: 100%;
183
+ box-sizing: border-box;
184
+ margin-bottom: 20px;
185
+ }
186
+
187
+ .custom_textbox {
188
+ background-color: #2d343f;
189
+ border: 1px solid #3b4252;
190
+ color: #7f8184;
191
+ padding: 10px;
192
+ border-radius: 4px;
193
+ margin-bottom: 10px;
194
+ width: 100%;
195
+ box-sizing: border-box;
196
+ }
197
+
198
+ .custom_gen_button {
199
+ background-color: #8b38ff;
200
+ border: 1px solid #ffffff;
201
+ color: blue;
202
+ padding: 15px 32px;
203
+ text-align: center;
204
+ text-decoration: none;
205
+ display: inline-block;
206
+ font-size: 16px;
207
+ margin: 4px 2px;
208
+ cursor: pointer;
209
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
210
+ transition: transform 0.2s, box-shadow 0.2s;
211
+ border-radius: 4px;
212
+ }
213
+ .custom_gen_button:hover {
214
+ transform: translateY(-2px);
215
+ box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3);
216
+ }
217
+ .custom_stop_button {
218
+ background-color: #6200ea;
219
+ border: 1px solid #ffffff;
220
+ color: blue;
221
+ padding: 15px 32px;
222
+ text-align: center;
223
+ text-decoration: none;
224
+ display: inline-block;
225
+ font-size: 16px;
226
+ margin: 4px 2px;
227
+ cursor: pointer;
228
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
229
+ transition: transform 0.2s, box-shadow 0.2s;
230
+ border-radius: 4px;
231
+ }
232
+ .custom_stop_button:hover {
233
+ transform: translateY(-2px);
234
+ box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3);
235
+ }
236
+
237
+ .custom_image {
238
+ border: 1px solid #3b4252;
239
+ background-color: #2d343f;
240
+ border-radius: 4px;
241
+ margin: 10px;
242
+ max-width: 100%;
243
+ box-sizing: border-box;
244
+ }
245
+
246
+ .custom_accordion {
247
+ background-color: #2d3d4f;
248
+ color: #7f8184;
249
+ border: 1px solid #3b4252;
250
+ border-radius: 4px;
251
+ margin-top: 20px;
252
+ width: 100%;
253
+ box-sizing: border-box;
254
+ transition: margin 0.2s ease;
255
+ }
256
+
257
+ .custom_accordion .gr-accordion-header {
258
+ background-color: #2d3d4f;
259
+ color: #7f8184;
260
+ padding: 10px 20px;
261
+ border-bottom: 1px solid #5b6270;
262
+ cursor: pointer;
263
+ font-size: 18px;
264
+ font-weight: bold;
265
+ height: 40px;
266
+ display: flex;
267
+ align-items: center;
268
+ }
269
+
270
+ .custom_accordion .gr-accordion-header:hover {
271
+ background-color: #2d3d4f;
272
+ }
273
+
274
+ .custom_accordion .gr-accordion-content {
275
+ padding: 10px 20px;
276
+ background-color: #2d3d4f;
277
+ border-top: 1px solid #5b6270;
278
+ max-height: 0;
279
+ overflow: hidden;
280
+ transition: max-height 0.2s ease;
281
+ }
282
+
283
+ .custom_accordion .gr-accordion-content.open {
284
+ max-height: 500px;
285
+ }
286
+
287
+ .custom_checkbox_group {
288
+ background-color: #2d343f;
289
+ border: 1px solid #3b4252;
290
+ color: #7f8184;
291
+ border-radius: 4px;
292
+ padding: 10px;
293
+ width: 100%;
294
+ box-sizing: border-box;
295
+ }
296
+
297
+ @media (max-width: 768px) {
298
+ .gradio-container {
299
+ width: 100%;
300
+ margin: 0;
301
+ padding: 10px;
302
+ }
303
+ .custom_textbox,.custom_image,.custom_checkbox_group {
304
+ width: 100%;
305
+ box-sizing: border-box;
306
+ }
307
+ }
308
+ """
309
+
310
+ with gr.Blocks(css=custom_css) as demo:
311
+ make_me()
312
+ # Очередь и запуск интерфейса с параметрами
313
+ demo.queue(default_concurrency_limit=340, max_size=400)
314
+ demo.launch(max_threads=400, ssr_mode=False)
315
+
316
+
317
+ demo.queue(concurrency_count=50)
318
+ demo.launch()