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

Delete app.py

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