MrDrmm commited on
Commit
4f68540
·
verified ·
1 Parent(s): 1b93962

Delete app.py

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