ginipick commited on
Commit
2dfb3f5
·
verified ·
1 Parent(s): e87b1f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -7
app.py CHANGED
@@ -197,16 +197,28 @@ def process_bbox(prompts: dict[str, Any]) -> tuple[tuple[Image.Image, Image.Imag
197
  def on_change_bbox(prompts: dict[str, Any] | None):
198
  return gr.update(interactive=prompts is not None)
199
 
200
- def process_prompt(img: Image.Image, prompt: str, bg_prompt: str | None = None) -> tuple[tuple[Image.Image, Image.Image], gr.DownloadButton]:
201
- return _process(img, prompt, bg_prompt)
202
 
203
  def on_change_prompt(img: Image.Image | None, prompt: str | None, bg_prompt: str | None = None):
204
  return gr.update(interactive=bool(img and prompt))
205
 
206
- def update_button_state(img, prompt):
207
- return gr.Button.update(interactive=bool(img and prompt))
208
 
209
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
  # 맨 앞부분에 CSS 정의 추가
211
  css = """
212
  footer {display: none}
@@ -362,7 +374,14 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
362
  )
363
 
364
  box_image.change(
365
- fn=update_process_button,
 
 
 
 
 
 
 
366
  inputs=[box_image, box_input],
367
  outputs=box_btn,
368
  queue=False
@@ -374,6 +393,6 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
374
  outputs=[box_output, box_download],
375
  queue=True
376
  )
377
-
378
  demo.queue(max_size=30, api_open=False)
379
- demo.launch()
 
197
  def on_change_bbox(prompts: dict[str, Any] | None):
198
  return gr.update(interactive=prompts is not None)
199
 
 
 
200
 
201
  def on_change_prompt(img: Image.Image | None, prompt: str | None, bg_prompt: str | None = None):
202
  return gr.update(interactive=bool(img and prompt))
203
 
 
 
204
 
205
 
206
+ # Event handler functions
207
+ def update_process_button(img, prompt):
208
+ return gr.Button.update(
209
+ interactive=bool(img and prompt),
210
+ variant="primary" if bool(img and prompt) else "secondary"
211
+ )
212
+
213
+ def update_box_button(img, box_input):
214
+ try:
215
+ if img and box_input:
216
+ coords = eval(box_input)
217
+ if isinstance(coords, list) and len(coords) == 4:
218
+ return gr.Button.update(interactive=True, variant="primary")
219
+ return gr.Button.update(interactive=False, variant="secondary")
220
+ except:
221
+ return gr.Button.update(interactive=False, variant="secondary")
222
  # 맨 앞부분에 CSS 정의 추가
223
  css = """
224
  footer {display: none}
 
374
  )
375
 
376
  box_image.change(
377
+ fn=update_box_button,
378
+ inputs=[box_image, box_input],
379
+ outputs=box_btn,
380
+ queue=False
381
+ )
382
+
383
+ box_input.change(
384
+ fn=update_box_button,
385
  inputs=[box_image, box_input],
386
  outputs=box_btn,
387
  queue=False
 
393
  outputs=[box_output, box_download],
394
  queue=True
395
  )
396
+
397
  demo.queue(max_size=30, api_open=False)
398
+ demo.launch()