DazDin commited on
Commit
4c967c0
·
verified ·
1 Parent(s): 8c58efd
Files changed (1) hide show
  1. app.py +182 -48
app.py CHANGED
@@ -31,65 +31,199 @@ def extend_choices(choices):
31
 
32
  def update_imgbox(choices):
33
  choices_plus = extend_choices(choices)
34
- return [gr.Image(None, label=m, visible=(m != 'NA')) for m in choices_plus]
35
 
36
  def gen_fn(model_str, prompt):
37
  if model_str == 'NA':
38
  return None
39
- noise = str(randint(0, 9999))
40
  return models_load[model_str](f'{prompt} {noise}')
41
 
42
  def make_me():
43
- with gr.Row():
44
- txt_input = gr.Textbox(label='Your prompt:', lines=3, width=800, max_height=100)
45
-
46
- gen_button = gr.Button('Generate images', width=30, height=30)
47
- stop_button = gr.Button('Stop', variant='secondary', interactive=False, width=30, height=30)
48
- gen_button.click(lambda s: gr.update(interactive=True), None, stop_button)
49
- gr.HTML("""
50
- <div style="text-align: center; max-width: 100%; margin: 0 auto;">
51
- <body>
52
- </body>
53
- </div>
54
- """)
55
- with gr.Row():
56
- output = [gr.Image(label=m, min_width=250, height=250) for m in default_models]
57
- current_models = [gr.Textbox(m, visible=False) for m in default_models]
58
- for m, o in zip(current_models, output):
59
- gen_event = gen_button.click(gen_fn, [m, txt_input], o)
60
- stop_button.click(lambda s: gr.update(interactive=False), None, stop_button, cancels=[gen_event])
61
- with gr.Accordion('Model selection'):
62
- 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)
63
- model_choice.change(update_imgbox, model_choice, output)
64
- model_choice.change(extend_choices, model_choice, current_models)
65
- with gr.Row():
66
- gr.HTML()
67
-
68
-
69
-
70
- js_code = """
71
 
72
- console.log('ghgh');
73
- """
74
- css = """
75
- body, .gradio-container, .gradio-app, .gradio-interface, .gr-box, .gr-row, .gr-column, .gr-textbox, .gr-button, .gr-image, .gr-accordion, .gr-checkbox-group, .gr-html {
76
- background-color: black !important;
77
- color: white !important; /* Optional: Set text color to white for better visibility */
78
- }
79
- div.float.svelte-1mwvhlq {
80
- position: absolute;
81
- top: var(--block-label-margin);
82
- left: var(--block-label-margin);
83
- background: none;
84
- border: none;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  }
86
  """
87
 
88
- with gr.Blocks(css=css) as demo:
89
- gr.Markdown("<script>" + js_code + "</script>")
90
  make_me()
91
 
92
-
93
-
94
- demo.queue(concurrency_count=100)
95
  demo.launch()
 
31
 
32
  def update_imgbox(choices):
33
  choices_plus = extend_choices(choices)
34
+ return [gr.Image(None, label=m, visible=(m != 'NA'), elem_id="custom_image") for m in choices_plus]
35
 
36
  def gen_fn(model_str, prompt):
37
  if model_str == 'NA':
38
  return None
39
+ noise = str(randint(0, 9999999))
40
  return models_load[model_str](f'{prompt} {noise}')
41
 
42
  def make_me():
43
+ with gr.Row():
44
+ with gr.Column(scale=1):
45
+ txt_input = gr.Textbox(label='Your prompt:', lines=3, container=False, elem_id="custom_textbox", placeholder="Prompt")
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
+ with gr.Row():
60
+ output = [gr.Image(label=m, min_width=250, height=250, elem_id="custom_image") for m in default_models]
61
+ current_models = [gr.Textbox(m, visible=False) for m in default_models]
62
+ for m, o in zip(current_models, output):
63
+ gen_event = gen_button.click(gen_fn, [m, txt_input], o)
64
+ stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button], cancels=[gen_event])
65
+
66
+ with gr.Accordion('Model selection', elem_id="custom_accordion"):
67
+ model_choice = gr.CheckboxGroup(models, label=f'{num_models} different models selected', value=default_models, interactive=True, elem_id="custom_checkbox_group")
68
+ model_choice.change(update_imgbox, model_choice, output)
69
+ model_choice.change(extend_choices, model_choice, current_models)
70
+
71
+ with gr.Row():
72
+ gr.HTML("")
73
+
74
+ custom_css = """
75
+ :root {
76
+ --body-background-fill: #2d3d4f;
77
+ }
78
+ body {
79
+ background-color: var(--body-background-fill) !important;
80
+ color: #2d3d4f;
81
+ margin: 0;
82
+ padding: 0;
83
+ font-family: Arial, sans-serif;
84
+ height: 100vh;
85
+ overflow-y: auto;
86
+ }
87
+ .gradio-container {
88
+ background-color: #2d3d4f;
89
+ color: #c5c6c7;
90
+ padding: 20px;
91
+ border-radius: 8px;
92
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
93
+ width: 100%;
94
+ max-width: 1200px;
95
+ margin: 20px auto; /* Center the container horizontally */
96
+ display: block; /* Ensure it's a block element */
97
+ min-height: 100vh; /* Adjust the height of the container */
98
+ }
99
+ .app_title {
100
+ background-color: #2d3d4f;
101
+ color: #c5c6c7;
102
+ padding: 10px 20px;
103
+ border-bottom: 1px solid #3b4252;
104
+ text-align: center;
105
+ font-size: 24px;
106
+ font-weight: bold;
107
+ width: 100%;
108
+ box-sizing: border-box;
109
+ margin-bottom: 20px; /* Add margin to separate the header from content */
110
+ }
111
+ .custom_textbox {
112
+ background-color: #2d343f;
113
+ border: 1px solid #3b4252;
114
+ color: #7f8184;
115
+ padding: 10px;
116
+ border-radius: 4px;
117
+ margin-bottom: 10px;
118
+ width: 100%;
119
+ box-sizing: border-box;
120
+ }
121
+ .custom_gen_button {
122
+ background-color: #8b38ff;
123
+ border: 1px solid #ffffff;
124
+ color: blue;
125
+ padding: 15px 32px;
126
+ text-align: center;
127
+ text-decoration: none;
128
+ display: inline-block;
129
+ font-size: 16px;
130
+ margin: 4px 2px;
131
+ cursor: pointer;
132
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
133
+ transition: transform 0.2s, box-shadow 0.2s;
134
+ border-radius: 4px;
135
+ }
136
+ .custom_gen_button:hover {
137
+ transform: translateY(-2px);
138
+ box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3);
139
+ }
140
+ .custom_stop_button {
141
+ background-color: #6200ea;
142
+ border: 1px solid #ffffff;
143
+ color: blue;
144
+ padding: 15px 32px;
145
+ text-align: center;
146
+ text-decoration: none;
147
+ display: inline-block;
148
+ font-size: 16px;
149
+ margin: 4px 2px;
150
+ cursor: pointer;
151
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
152
+ transition: transform 0.2s, box-shadow 0.2s;
153
+ border-radius: 4px;
154
+ }
155
+ .custom_stop_button:hover {
156
+ transform: translateY(-2px);
157
+ box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3);
158
+ }
159
+ .custom_image {
160
+ border: 1px solid #3b4252;
161
+ background-color: #2d343f;
162
+ border-radius: 4px;
163
+ margin: 10px;
164
+ max-width: 100%;
165
+ box-sizing: border-box;
166
+ }
167
+ .custom_accordion {
168
+ background-color: #2d3d4f;
169
+ color: #7f8184;
170
+ border: 1px solid #3b4252;
171
+ border-radius: 4px;
172
+ margin-top: 20px;
173
+ width: 100%;
174
+ box-sizing: border-box;
175
+ transition: margin 0.2s ease; /* Smooth transition for margin */
176
+ }
177
+ .custom_accordion .gr-accordion-header {
178
+ background-color: #2d3d4f;
179
+ color: #7f8184;
180
+ padding: 10px 20px;
181
+ border-bottom: 1px solid #5b6270;
182
+ cursor: pointer;
183
+ font-size: 18px;
184
+ font-weight: bold;
185
+ height: 40px; /* Fixed height for the header */
186
+ display: flex;
187
+ align-items: center;
188
+ }
189
+ .custom_accordion .gr-accordion-header:hover {
190
+ background-color: #2d3d4f;
191
+ }
192
+ .custom_accordion .gr-accordion-content {
193
+ padding: 10px 20px;
194
+ background-color: #2d3d4f;
195
+ border-top: 1px solid #5b6270;
196
+ max-height: 0; /* Start with no height */
197
+ overflow: hidden;
198
+ transition: max-height 0.2s ease;
199
+ }
200
+ .custom_accordion .gr-accordion-content.open {
201
+ max-height: 500px;
202
+ }
203
+ .custom_checkbox_group {
204
+ background-color: #2d343f;
205
+ border: 1px solid #3b4252;
206
+ color: #7f8184;
207
+ border-radius: 4px;
208
+ padding: 10px;
209
+ width: 100%;
210
+ box-sizing: border-box;
211
+ }
212
+ @media (max-width: 768px) {
213
+ .gradio-container {
214
+ width: 100%;
215
+ margin: 0;
216
+ padding: 10px;
217
+ }
218
+ .custom_textbox,.custom_image,.custom_checkbox_group {
219
+ width: 100%;
220
+ box-sizing: border-box;
221
+ }
222
  }
223
  """
224
 
225
+ with gr.Blocks(css=custom_css) as demo:
 
226
  make_me()
227
 
228
+ demo.queue(concurrency_count=200)
 
 
229
  demo.launch()