ginipick commited on
Commit
df5b718
·
verified ·
1 Parent(s): 1160b91

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -101
app.py CHANGED
@@ -315,94 +315,53 @@ button.primary:hover {
315
  }
316
  """
317
 
318
- # UI 부분만 수정
319
- # Main Gradio app
320
  # UI 부분 수정
321
  with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
322
  gr.HTML("""
323
  <div class="main-title">
324
  <h1>🎨 Image Object Extractor</h1>
325
- <p>Extract objects from images using text prompts or bounding boxes</p>
326
  </div>
327
  """)
328
 
329
- with gr.Tabs(selected=0):
330
- # Text-based extraction tab
331
- with gr.TabItem("Extract by Text"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
332
  with gr.Row():
333
- with gr.Column(scale=1):
334
- input_image = gr.Image(
335
- type="pil",
336
- label="Upload Image",
337
- interactive=True
338
- )
339
- text_prompt = gr.Textbox(
340
- label="Object to Extract",
341
- placeholder="Enter what you want to extract...",
342
- interactive=True
343
- )
344
- bg_prompt = gr.Textbox(
345
- label="Background Prompt (optional)",
346
- placeholder="Describe the background...",
347
- interactive=True
348
- )
349
- process_btn = gr.Button(
350
- "Process",
351
- variant="primary",
352
- interactive=False
353
- )
354
-
355
- with gr.Column(scale=1):
356
- with gr.Row():
357
- combined_image = gr.Image(
358
- label="Combined Result",
359
- show_download_button=True,
360
- type="pil",
361
- height=512
362
- )
363
- with gr.Row():
364
- extracted_image = gr.Image(
365
- label="Extracted Object",
366
- show_download_button=True,
367
- type="pil",
368
- height=256
369
- )
370
-
371
- # Box-based extraction tab
372
- with gr.TabItem("Extract by Box"):
373
  with gr.Row():
374
- with gr.Column(scale=1):
375
- box_image = gr.Image(
376
- type="pil",
377
- label="Upload Image for Box",
378
- interactive=True
379
- )
380
- box_input = gr.Textbox(
381
- label="Bounding Box (xmin, ymin, xmax, ymax)",
382
- placeholder="Enter coordinates as [x1, y1, x2, y2]",
383
- interactive=True
384
- )
385
- box_btn = gr.Button(
386
- "Extract Selection",
387
- variant="primary",
388
- interactive=False
389
- )
390
-
391
- with gr.Column(scale=1):
392
- with gr.Row():
393
- box_combined_image = gr.Image(
394
- label="Combined Result",
395
- show_download_button=True,
396
- type="pil",
397
- height=512
398
- )
399
- with gr.Row():
400
- box_extracted_image = gr.Image(
401
- label="Extracted Object",
402
- show_download_button=True,
403
- type="pil",
404
- height=256
405
- )
406
 
407
  # Event bindings
408
  input_image.change(
@@ -422,30 +381,9 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
422
  process_btn.click(
423
  fn=process_prompt,
424
  inputs=[input_image, text_prompt, bg_prompt],
425
- outputs=[combined_image, extracted_image], # 출력 변경
426
- queue=True
427
- )
428
-
429
- box_image.change(
430
- fn=update_box_button,
431
- inputs=[box_image, box_input],
432
- outputs=box_btn,
433
- queue=False
434
- )
435
-
436
- box_input.change(
437
- fn=update_box_button,
438
- inputs=[box_image, box_input],
439
- outputs=box_btn,
440
- queue=False
441
- )
442
-
443
- box_btn.click(
444
- fn=process_bbox,
445
- inputs=[box_image, box_input],
446
- outputs=[box_combined_image, box_extracted_image], # 출력 변경
447
  queue=True
448
  )
449
 
450
  demo.queue(max_size=30, api_open=False)
451
- demo.launch()
 
315
  }
316
  """
317
 
 
 
318
  # UI 부분 수정
319
  with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
320
  gr.HTML("""
321
  <div class="main-title">
322
  <h1>🎨 Image Object Extractor</h1>
323
+ <p>Extract objects from images using text prompts</p>
324
  </div>
325
  """)
326
 
327
+ with gr.Row():
328
+ with gr.Column(scale=1):
329
+ input_image = gr.Image(
330
+ type="pil",
331
+ label="Upload Image",
332
+ interactive=True
333
+ )
334
+ text_prompt = gr.Textbox(
335
+ label="Object to Extract",
336
+ placeholder="Enter what you want to extract...",
337
+ interactive=True
338
+ )
339
+ bg_prompt = gr.Textbox(
340
+ label="Background Prompt (optional)",
341
+ placeholder="Describe the background...",
342
+ interactive=True
343
+ )
344
+ process_btn = gr.Button(
345
+ "Process",
346
+ variant="primary",
347
+ interactive=False
348
+ )
349
+
350
+ with gr.Column(scale=1):
351
  with gr.Row():
352
+ combined_image = gr.Image(
353
+ label="Combined Result",
354
+ show_download_button=True,
355
+ type="pil",
356
+ height=512
357
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
  with gr.Row():
359
+ extracted_image = gr.Image(
360
+ label="Extracted Object",
361
+ show_download_button=True,
362
+ type="pil",
363
+ height=256
364
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
365
 
366
  # Event bindings
367
  input_image.change(
 
381
  process_btn.click(
382
  fn=process_prompt,
383
  inputs=[input_image, text_prompt, bg_prompt],
384
+ outputs=[combined_image, extracted_image],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
385
  queue=True
386
  )
387
 
388
  demo.queue(max_size=30, api_open=False)
389
+ demo.launch()