johann-foerster commited on
Commit
c06c3fc
·
1 Parent(s): f72182b

limit greet box in the most backendy way possible

Browse files
Files changed (1) hide show
  1. webui.py +6 -2
webui.py CHANGED
@@ -67,6 +67,11 @@ def debounce():
67
  time.sleep(0.5)
68
  return
69
 
 
 
 
 
 
70
  def overlay_image(image_path, toggle_greet, greet):
71
  image = ImageDraw.Draw(Image.open(image_path), "RGBA")
72
  HEIGHT, TEXT_PADDING, TEXTBOX_HEIGHT = 100, 32, 56
@@ -144,8 +149,6 @@ with shared.gradio_root:
144
  greet = gr.Textbox(value=EXAMPLE_GREETINGS[0], placeholder="", interactive=True, container=False, lines=2, max_lines=2, show_label=False)
145
  greet_active = gr.Textbox(value=EXAMPLE_GREETINGS[0], visible=False, container=False, show_label=False)
146
  greet_examples = gr.Examples(elem_id="greet-examples", examples=EXAMPLE_GREETINGS, inputs=[greet])
147
-
148
-
149
  generated_image = gr.Image(visible=False, type='pil', label="Erstelle Weihnachtskarte...", elem_classes="generated-image", width=1280,
150
  value=INIT_IMAGE_PATH, interactive=False, show_share_button=False, show_download_button=False)
151
  generated_image_overlayed = gr.Image(label="Weihnachtskarte", type='pil', elem_classes="generated-image", width=1280,
@@ -157,6 +160,7 @@ with shared.gradio_root:
157
  .then(fn=make_overlay, inputs=[generated_image_path, toggle_greet, greet], outputs=[generated_image_overlayed, greet_active], show_progress=False, queue=False)
158
  greet.change(fn=debounce, queue=False, show_progress=False)\
159
  .then(fn=make_overlay, inputs=[generated_image_path, toggle_greet, greet], outputs=[generated_image_overlayed, greet_active], queue=False, show_progress=False)
 
160
  greet_active.change(fn=verify_latest_overlay, inputs=[generated_image_path, toggle_greet, greet, greet_active], outputs=[generated_image_overlayed, greet_active], queue=False, show_progress=False)
161
  run_button.click(fn=prepare_generate, outputs=[generated_image, generated_image_overlayed, run_button], queue=False)\
162
  .then(fn=generate, inputs=[prompt, style_selection], outputs=[progress_html, generated_image, generated_image_path], queue=True)\
 
67
  time.sleep(0.5)
68
  return
69
 
70
+ def greet_limit_max_lines(greet):
71
+ if len(greet.split('\n')) > 2:
72
+ return gr.Textbox(value='\n'.join(greet.split('\n')[0:2]))
73
+ return gr.Textbox()
74
+
75
  def overlay_image(image_path, toggle_greet, greet):
76
  image = ImageDraw.Draw(Image.open(image_path), "RGBA")
77
  HEIGHT, TEXT_PADDING, TEXTBOX_HEIGHT = 100, 32, 56
 
149
  greet = gr.Textbox(value=EXAMPLE_GREETINGS[0], placeholder="", interactive=True, container=False, lines=2, max_lines=2, show_label=False)
150
  greet_active = gr.Textbox(value=EXAMPLE_GREETINGS[0], visible=False, container=False, show_label=False)
151
  greet_examples = gr.Examples(elem_id="greet-examples", examples=EXAMPLE_GREETINGS, inputs=[greet])
 
 
152
  generated_image = gr.Image(visible=False, type='pil', label="Erstelle Weihnachtskarte...", elem_classes="generated-image", width=1280,
153
  value=INIT_IMAGE_PATH, interactive=False, show_share_button=False, show_download_button=False)
154
  generated_image_overlayed = gr.Image(label="Weihnachtskarte", type='pil', elem_classes="generated-image", width=1280,
 
160
  .then(fn=make_overlay, inputs=[generated_image_path, toggle_greet, greet], outputs=[generated_image_overlayed, greet_active], show_progress=False, queue=False)
161
  greet.change(fn=debounce, queue=False, show_progress=False)\
162
  .then(fn=make_overlay, inputs=[generated_image_path, toggle_greet, greet], outputs=[generated_image_overlayed, greet_active], queue=False, show_progress=False)
163
+ greet.change(fn=greet_limit_max_lines, inputs=[greet], outputs=[greet], queue=False, show_progress=False)
164
  greet_active.change(fn=verify_latest_overlay, inputs=[generated_image_path, toggle_greet, greet, greet_active], outputs=[generated_image_overlayed, greet_active], queue=False, show_progress=False)
165
  run_button.click(fn=prepare_generate, outputs=[generated_image, generated_image_overlayed, run_button], queue=False)\
166
  .then(fn=generate, inputs=[prompt, style_selection], outputs=[progress_html, generated_image, generated_image_path], queue=True)\