fantos commited on
Commit
6a40d86
·
verified ·
1 Parent(s): 89d2c7a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -10
app.py CHANGED
@@ -175,6 +175,7 @@ def infer_canny(prompt, text_for_image, text_position, font_size,
175
  ).images[0]
176
  return [condi_img, image], seed
177
 
 
178
  css = """
179
  footer {
180
  visibility: hidden;
@@ -188,10 +189,27 @@ footer {
188
  .text-position-grid button {
189
  aspect-ratio: 1;
190
  padding: 0;
 
 
 
 
 
 
 
191
  }
192
  """
193
 
 
 
 
 
 
 
 
 
194
  with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as Kolors:
 
 
195
  with gr.Row():
196
  with gr.Column(elem_id="col-left"):
197
  with gr.Row():
@@ -210,16 +228,26 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as Kolors:
210
  with gr.Column():
211
  gr.Markdown("Text Position")
212
  with gr.Row(elem_classes="text-position-grid"):
213
- text_positions = ["top-left", "top-center", "top-right",
214
- "middle-left", "middle-center", "middle-right",
215
- "bottom-left", "bottom-center", "bottom-right"]
216
- text_position = gr.Radio(
217
- choices=text_positions,
218
- value="top-center",
219
- label="",
220
- show_label=False,
221
- elem_classes="text-position-grid"
222
- )
 
 
 
 
 
 
 
 
 
 
223
  with gr.Column():
224
  font_size = gr.Slider(
225
  label="Font Size",
@@ -294,4 +322,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as Kolors:
294
  outputs = [result, seed_used]
295
  )
296
 
 
 
 
297
  Kolors.queue().launch(debug=True, share=True)
 
175
  ).images[0]
176
  return [condi_img, image], seed
177
 
178
+
179
  css = """
180
  footer {
181
  visibility: hidden;
 
189
  .text-position-grid button {
190
  aspect-ratio: 1;
191
  padding: 0;
192
+ border: 1px solid #ccc;
193
+ background-color: #f0f0f0;
194
+ cursor: pointer;
195
+ }
196
+ .text-position-grid button.selected {
197
+ background-color: #007bff;
198
+ color: white;
199
  }
200
  """
201
 
202
+ def update_button_states(selected_position):
203
+ return [
204
+ gr.Button.update(variant="primary" if pos == selected_position else "secondary")
205
+ for pos in ["top-left", "top-center", "top-right",
206
+ "middle-left", "middle-center", "middle-right",
207
+ "bottom-left", "bottom-center", "bottom-right"]
208
+ ]
209
+
210
  with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as Kolors:
211
+ text_position = gr.State("top-center")
212
+
213
  with gr.Row():
214
  with gr.Column(elem_id="col-left"):
215
  with gr.Row():
 
228
  with gr.Column():
229
  gr.Markdown("Text Position")
230
  with gr.Row(elem_classes="text-position-grid"):
231
+ btn_top_left = gr.Button("")
232
+ btn_top_center = gr.Button("")
233
+ btn_top_right = gr.Button("")
234
+ btn_middle_left = gr.Button("←")
235
+ btn_middle_center = gr.Button("•")
236
+ btn_middle_right = gr.Button("")
237
+ btn_bottom_left = gr.Button("")
238
+ btn_bottom_center = gr.Button("↓")
239
+ btn_bottom_right = gr.Button("")
240
+
241
+ position_buttons = [btn_top_left, btn_top_center, btn_top_right,
242
+ btn_middle_left, btn_middle_center, btn_middle_right,
243
+ btn_bottom_left, btn_bottom_center, btn_bottom_right]
244
+
245
+ for btn, pos in zip(position_buttons, ["top-left", "top-center", "top-right",
246
+ "middle-left", "middle-center", "middle-right",
247
+ "bottom-left", "bottom-center", "bottom-right"]):
248
+ btn.click(lambda x, p=pos: p, outputs=text_position)
249
+ btn.click(update_button_states, inputs=[text_position], outputs=position_buttons)
250
+
251
  with gr.Column():
252
  font_size = gr.Slider(
253
  label="Font Size",
 
322
  outputs = [result, seed_used]
323
  )
324
 
325
+ # Set initial button states
326
+ Kolors.load(update_button_states, inputs=[text_position], outputs=position_buttons)
327
+
328
  Kolors.queue().launch(debug=True, share=True)