DazDin commited on
Commit
20cbff0
Β·
verified Β·
1 Parent(s): 5a044c1
Files changed (1) hide show
  1. app.py +43 -241
app.py CHANGED
@@ -1,264 +1,66 @@
1
  import gradio as gr
2
  from random import randint
3
  from all_models import models
 
4
 
5
- def load_fn(models):
6
- global models_load
7
- models_load = {}
8
- for model in models:
9
- if model not in models_load.keys():
10
- try:
11
- m = gr.load(f'models/{model}')
12
- except Exception as error:
13
- m = gr.Interface(lambda txt: None, ['text'], ['image'])
14
- models_load.update({model: m})
15
-
16
- load_fn(models)
17
 
18
- num_models = len(models)
19
- default_models = models[:num_models]
 
 
 
 
20
 
21
- def extend_choices(choices):
22
- return choices + (num_models - len(choices)) * ['NA']
23
 
24
  def update_imgbox(choices):
25
  choices_plus = extend_choices(choices)
26
- return [gr.Image(None, label=m, visible=(m != 'NA'), elem_id="custom_image") for m in choices_plus]
27
 
28
  def gen_fn(model_str, prompt):
29
  if model_str == 'NA':
30
  return None
31
- noise = str(randint(0, 9999999))
32
  return models_load[model_str](f'{prompt} {noise}')
33
 
34
  def make_me():
35
- with gr.Row():
36
- with gr.Column(scale=1):
37
- txt_input = gr.Textbox(label='Your prompt:', lines=3, container=False, elem_id="custom_textbox")
38
- with gr.Row():
39
- gen_button = gr.Button('Generate images', elem_id="custom_gen_button")
40
- stop_button = gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
41
-
42
- def on_generate_click():
43
- return gr.Button('Generate images', elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=True, elem_id="custom_stop_button")
44
-
45
- def on_stop_click():
46
- return gr.Button('Generate images', elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
47
-
48
- gen_button.click(on_generate_click, inputs=None, outputs=[gen_button, stop_button])
49
- stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button])
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
- with gr.Row():
52
- output = [gr.Image(label=m, min_width=250, height=250, elem_id="custom_image") for m in default_models]
53
- current_models = [gr.Textbox(m, visible=False) for m in default_models]
54
- for m, o in zip(current_models, output):
55
- gen_event = gen_button.click(gen_fn, [m, txt_input], o)
56
- stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button], cancels=[gen_event])
57
-
58
- with gr.Accordion('Model selection', elem_id="custom_accordion"):
59
- model_choice = gr.CheckboxGroup(models, label=f'{num_models} different models selected', value=default_models, interactive=True, elem_id="custom_checkbox_group")
60
- model_choice.change(update_imgbox, model_choice, output)
61
- model_choice.change(extend_choices, model_choice, current_models)
62
-
63
- with gr.Row():
64
- gr.HTML("")
65
-
66
- # Inject JavaScript to handle accordion toggle
67
- js_code = """
68
- <script>
69
- document.addEventListener('DOMContentLoaded', function() {
70
- const accordionHeaders = document.querySelectorAll('.gr-accordion-header');
71
- accordionHeaders.forEach(header => {
72
- header.addEventListener('click', function() {
73
- const content = this.nextElementSibling;
74
- if (content.classList.contains('open')) {
75
- content.classList.remove('open');
76
- } else {
77
- content.classList.add('open');
78
- }
79
- });
80
- });
81
- });
82
- </script>
83
- """
84
- gr.HTML(js_code)
85
-
86
- custom_css = """
87
- /* General Styles */
88
- body {
89
- background-color: #1a242e;
90
- color: #c5c6c7;
91
- margin: 0;
92
- padding: 0;
93
- font-family: Arial, sans-serif;
94
- display: flex;
95
- justify-content: center;
96
- align-items: center; /* Align items from the center */
97
- height: 100vh;
98
- overflow-y: auto;
99
- }
100
-
101
- /* Container Styles */
102
- .gradio-container {
103
- background-color: #1a242e;
104
- color: #c5c6c7;
105
- padding: 20px;
106
- border-radius: 8px;
107
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
108
- width: 100%;
109
- max-width: 1200px;
110
- margin: 20px;
111
- display: flex;
112
- flex-direction: column;
113
- align-items: center; /* Center items horizontally */
114
- min-height: 100vh; /* Adjust the height of the container */
115
- }
116
-
117
- /* Header Styles */
118
- .app_title {
119
- background-color: #1a242e;
120
- color: #c5c6c7;
121
- padding: 10px 20px;
122
- border-bottom: 1px solid #3b4252;
123
- text-align: center;
124
- font-size: 24px;
125
- font-weight: bold;
126
- width: 100%;
127
- box-sizing: border-box;
128
- margin-bottom: 20px; /* Add margin to separate the header from content */
129
- }
130
-
131
- /* Textbox Styles */
132
- .custom_textbox {
133
- background-color: #2d343f;
134
- border: 1px solid #3b4252;
135
- color: #c5c6c7;
136
- padding: 10px;
137
- border-radius: 4px;
138
- margin-bottom: 10px;
139
- width: 100%;
140
- box-sizing: border-box;
141
- }
142
-
143
- /* Button Styles */
144
- .custom_gen_button {
145
- background-color: #4a90e2;
146
- border: none;
147
- color: white;
148
- padding: 15px 32px;
149
- text-align: center;
150
- text-decoration: none;
151
- display: inline-block;
152
- font-size: 16px;
153
- margin: 4px 2px;
154
- cursor: pointer;
155
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
156
- transition: transform 0.2s, box-shadow 0.2s;
157
- border-radius: 4px;
158
- }
159
- .custom_gen_button:hover {
160
- transform: translateY(-2px);
161
- box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3);
162
- }
163
- .custom_stop_button {
164
- background-color: #6200ea;
165
- border: none;
166
- color: white;
167
- padding: 15px 32px;
168
- text-align: center;
169
- text-decoration: none;
170
- display: inline-block;
171
- font-size: 16px;
172
- margin: 4px 2px;
173
- cursor: pointer;
174
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
175
- transition: transform 0.2s, box-shadow 0.2s;
176
- border-radius: 4px;
177
- }
178
- .custom_stop_button:hover {
179
- transform: translateY(-2px);
180
- box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3);
181
- }
182
-
183
- /* Image Styles */
184
- .custom_image {
185
- border: 1px solid #3b4252;
186
- background-color: #2d343f;
187
- border-radius: 4px;
188
- margin: 10px;
189
- max-width: 100%;
190
- box-sizing: border-box;
191
- }
192
-
193
- /* Accordion Styles */
194
- .custom_accordion {
195
- background-color: #1a242e;
196
- color: #c5c6c7;
197
- border: 1px solid #3b4252;
198
- border-radius: 4px;
199
- margin-top: 20px;
200
- width: 100%;
201
- box-sizing: border-box;
202
- transition: margin 0.3s ease; /* Smooth transition for margin */
203
- }
204
-
205
- .custom_accordion .gr-accordion-header {
206
- background-color: #3b4252;
207
- color: #c5c6c7;
208
- padding: 10px 20px;
209
- border-bottom: 1px solid #5b6270;
210
- cursor: pointer;
211
- font-size: 18px;
212
- font-weight: bold;
213
- height: 40px; /* Fixed height for the header */
214
- display: flex;
215
- align-items: center;
216
- }
217
-
218
- .custom_accordion .gr-accordion-header:hover {
219
- background-color: #4b5260;
220
- }
221
-
222
- .custom_accordion .gr-accordion-content {
223
- padding: 10px 20px;
224
- background-color: #2d343f;
225
- border-top: 1px solid #5b6270;
226
- max-height: 0; /* Start with no height */
227
- overflow: hidden;
228
- transition: max-height 0.3s ease; /* Smooth transition for height */
229
- }
230
-
231
- .custom_accordion .gr-accordion-content.open {
232
- max-height: 500px; /* Set a reasonable max height */
233
- }
234
-
235
- /* Checkbox Group Styles */
236
- .custom_checkbox_group {
237
- background-color: #2d343f;
238
- border: 1px solid #3b4252;
239
- color: #c5c6c7;
240
- border-radius: 4px;
241
- padding: 10px;
242
- width: 100%;
243
- box-sizing: border-box;
244
- }
245
 
246
- /* Responsive Design */
247
- @media (max-width: 768px) {
248
- .gradio-container {
249
- width: 100%;
250
- margin: 0;
251
- padding: 10px;
252
- }
253
- .custom_textbox,.custom_image,.custom_checkbox_group {
254
- width: 100%;
255
- box-sizing: border-box;
256
- }
257
- }
258
  """
259
 
260
- with gr.Blocks(css=custom_css) as demo:
 
261
  make_me()
262
 
263
- demo.queue(concurrency_count=200)
264
  demo.launch()
 
1
  import gradio as gr
2
  from random import randint
3
  from all_models import models
4
+ from datetime import datetime
5
 
6
+ now2 = 0
 
 
 
 
 
 
 
 
 
 
 
7
 
8
+ def get_current_time():
9
+ now = datetime.now()
10
+ now2 = now
11
+ current_time = now2.strftime("%Y-%m-%d %H:%M:%S")
12
+ ki = f'{kii} {current_time}'
13
+ return ki
14
 
15
+ def load_fn(models):
16
+ global models_load
17
 
18
  def update_imgbox(choices):
19
  choices_plus = extend_choices(choices)
20
+ return [gr.Image(None, label=m, visible=(m != 'NA')) for m in choices_plus]
21
 
22
  def gen_fn(model_str, prompt):
23
  if model_str == 'NA':
24
  return None
25
+ noise = str(randint(0, 9999))
26
  return models_load[model_str](f'{prompt} {noise}')
27
 
28
  def make_me():
29
+ with gr.Row():
30
+ txt_input = gr.Textbox(label='Your prompt:', lines=3, width=800, max_height=100)
31
+
32
+ gen_button = gr.Button('Generate images', width=30, height=30)
33
+ stop_button = gr.Button('Stop', variant='secondary', interactive=False, width=30, height=30)
34
+ gen_button.click(lambda s: gr.update(interactive=True), None, stop_button)
35
+ gr.HTML("""
36
+ <div style="text-align: center; max-width: 100%; margin: 0 auto;">
37
+ <body>
38
+ </body>
39
+ </div>
40
+ """)
41
+ with gr.Row():
42
+ output = [gr.Image(label=m, min_width=250, height=250) for m in default_models]
43
+ current_models = [gr.Textbox(m, visible=False) for m in default_models]
44
+ for m, o in zip(current_models, output):
45
+ gen_event = gen_button.click(gen_fn, [m, txt_input], o)
46
+ stop_button.click(lambda s: gr.update(interactive=False), None, stop_button, cancels=[gen_event])
47
+ with gr.Accordion('Model selection'):
48
+ model_choice = gr.CheckboxGroup(models, label=f' {num_models} different models selected', value=default_models, multiselect=True, max_choices=num_models, interactive=True, filterable=False)
49
+ model_choice.change(update_imgbox, model_choice, output)
50
+ model_choice.change(extend_choices, model_choice, current_models)
51
+ with gr.Row():
52
+ gr.HTML()
53
+
54
+
55
+ js_code = """
56
 
57
+ console.log('ghgh');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  """
60
 
61
+ with gr.Blocks(css="div.float.svelte-1mwvhlq { position: absolute; top: var(--block-label-margin); left: var(--block-label-margin); background: none; border: none;}") as demo:
62
+ gr.Markdown("<script>" + js_code + "</script>")
63
  make_me()
64
 
65
+ demo.queue(concurrency_count=100)
66
  demo.launch()