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