Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -268,44 +268,45 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
268 |
</div>
|
269 |
""")
|
270 |
|
271 |
-
with gr.Tabs() as tabs:
|
272 |
# Text 탭
|
273 |
-
with gr.
|
274 |
with gr.Row():
|
275 |
-
with gr.Column():
|
276 |
input_image = gr.Image(
|
277 |
type="pil",
|
278 |
label="Upload Image",
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
text_prompt = gr.Textbox(
|
283 |
-
label="Object to Extract",
|
284 |
-
placeholder="Enter what you want to extract...",
|
285 |
-
interactive=True,
|
286 |
-
elem_id="text_prompt"
|
287 |
-
)
|
288 |
-
bg_prompt = gr.Textbox(
|
289 |
-
label="Background Prompt (optional)",
|
290 |
-
placeholder="Describe the background...",
|
291 |
-
interactive=True,
|
292 |
-
elem_id="bg_prompt"
|
293 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
294 |
process_btn = gr.Button(
|
295 |
"Process",
|
296 |
variant="primary",
|
297 |
-
|
298 |
)
|
299 |
|
300 |
-
with gr.Column():
|
301 |
output_display = ImageSlider(
|
302 |
label="Results",
|
303 |
show_download_button=False,
|
304 |
-
|
|
|
305 |
)
|
306 |
download_btn = gr.DownloadButton(
|
307 |
"Download Result",
|
308 |
-
|
309 |
)
|
310 |
|
311 |
with gr.Accordion("Examples", open=False):
|
@@ -321,34 +322,35 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
321 |
)
|
322 |
|
323 |
# Box 탭
|
324 |
-
with gr.
|
325 |
with gr.Row():
|
326 |
-
with gr.Column():
|
327 |
box_annotator = image_annotator(
|
328 |
image_type="pil",
|
|
|
329 |
disable_edit_boxes=False,
|
330 |
show_download_button=False,
|
331 |
show_share_button=False,
|
332 |
single_box=True,
|
333 |
label="Draw Box Around Object",
|
334 |
-
interactive=True
|
335 |
-
elem_id="box_annotator"
|
336 |
)
|
337 |
box_btn = gr.Button(
|
338 |
"Extract Selection",
|
339 |
variant="primary",
|
340 |
-
|
341 |
)
|
342 |
|
343 |
-
with gr.Column():
|
344 |
box_output = ImageSlider(
|
345 |
label="Results",
|
346 |
show_download_button=False,
|
347 |
-
|
|
|
348 |
)
|
349 |
box_download = gr.DownloadButton(
|
350 |
"Download Result",
|
351 |
-
|
352 |
)
|
353 |
|
354 |
with gr.Accordion("Examples", open=False):
|
@@ -371,38 +373,49 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
371 |
|
372 |
# Event handlers
|
373 |
def update_process_button(img, prompt):
|
374 |
-
return gr.Button.update(
|
|
|
|
|
|
|
375 |
|
376 |
# Text tab events
|
377 |
input_image.change(
|
378 |
fn=update_process_button,
|
379 |
inputs=[input_image, text_prompt],
|
380 |
-
outputs=process_btn
|
|
|
381 |
)
|
|
|
382 |
text_prompt.change(
|
383 |
fn=update_process_button,
|
384 |
inputs=[input_image, text_prompt],
|
385 |
-
outputs=process_btn
|
|
|
386 |
)
|
|
|
387 |
process_btn.click(
|
388 |
fn=process_prompt,
|
389 |
inputs=[input_image, text_prompt, bg_prompt],
|
390 |
-
outputs=[output_display, download_btn]
|
|
|
391 |
)
|
392 |
|
393 |
# Box tab events
|
394 |
box_annotator.change(
|
395 |
fn=lambda x: gr.Button.update(interactive=bool(x)),
|
396 |
inputs=[box_annotator],
|
397 |
-
outputs=box_btn
|
|
|
398 |
)
|
|
|
399 |
box_btn.click(
|
400 |
fn=process_bbox,
|
401 |
inputs=[box_annotator],
|
402 |
-
outputs=[box_output, box_download]
|
|
|
403 |
)
|
404 |
|
405 |
-
# Launch
|
406 |
demo.queue(max_size=30, api_open=False)
|
407 |
demo.launch(
|
408 |
show_api=False,
|
|
|
268 |
</div>
|
269 |
""")
|
270 |
|
271 |
+
with gr.Tabs(selected=0) as tabs:
|
272 |
# Text 탭
|
273 |
+
with gr.TabItem("Extract by Text") as text_tab:
|
274 |
with gr.Row():
|
275 |
+
with gr.Column(scale=1):
|
276 |
input_image = gr.Image(
|
277 |
type="pil",
|
278 |
label="Upload Image",
|
279 |
+
tool="select",
|
280 |
+
height=400,
|
281 |
+
interactive=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
282 |
)
|
283 |
+
with gr.Row():
|
284 |
+
text_prompt = gr.Textbox(
|
285 |
+
label="Object to Extract",
|
286 |
+
placeholder="Enter what you want to extract...",
|
287 |
+
interactive=True
|
288 |
+
)
|
289 |
+
bg_prompt = gr.Textbox(
|
290 |
+
label="Background Prompt (optional)",
|
291 |
+
placeholder="Describe the background...",
|
292 |
+
interactive=True
|
293 |
+
)
|
294 |
process_btn = gr.Button(
|
295 |
"Process",
|
296 |
variant="primary",
|
297 |
+
interactive=False
|
298 |
)
|
299 |
|
300 |
+
with gr.Column(scale=1):
|
301 |
output_display = ImageSlider(
|
302 |
label="Results",
|
303 |
show_download_button=False,
|
304 |
+
height=400,
|
305 |
+
visible=True
|
306 |
)
|
307 |
download_btn = gr.DownloadButton(
|
308 |
"Download Result",
|
309 |
+
visible=True
|
310 |
)
|
311 |
|
312 |
with gr.Accordion("Examples", open=False):
|
|
|
322 |
)
|
323 |
|
324 |
# Box 탭
|
325 |
+
with gr.TabItem("Extract by Box") as box_tab:
|
326 |
with gr.Row():
|
327 |
+
with gr.Column(scale=1):
|
328 |
box_annotator = image_annotator(
|
329 |
image_type="pil",
|
330 |
+
height=400,
|
331 |
disable_edit_boxes=False,
|
332 |
show_download_button=False,
|
333 |
show_share_button=False,
|
334 |
single_box=True,
|
335 |
label="Draw Box Around Object",
|
336 |
+
interactive=True
|
|
|
337 |
)
|
338 |
box_btn = gr.Button(
|
339 |
"Extract Selection",
|
340 |
variant="primary",
|
341 |
+
interactive=False
|
342 |
)
|
343 |
|
344 |
+
with gr.Column(scale=1):
|
345 |
box_output = ImageSlider(
|
346 |
label="Results",
|
347 |
show_download_button=False,
|
348 |
+
height=400,
|
349 |
+
visible=True
|
350 |
)
|
351 |
box_download = gr.DownloadButton(
|
352 |
"Download Result",
|
353 |
+
visible=True
|
354 |
)
|
355 |
|
356 |
with gr.Accordion("Examples", open=False):
|
|
|
373 |
|
374 |
# Event handlers
|
375 |
def update_process_button(img, prompt):
|
376 |
+
return gr.Button.update(
|
377 |
+
interactive=bool(img and prompt),
|
378 |
+
variant="primary" if bool(img and prompt) else "secondary"
|
379 |
+
)
|
380 |
|
381 |
# Text tab events
|
382 |
input_image.change(
|
383 |
fn=update_process_button,
|
384 |
inputs=[input_image, text_prompt],
|
385 |
+
outputs=process_btn,
|
386 |
+
queue=False
|
387 |
)
|
388 |
+
|
389 |
text_prompt.change(
|
390 |
fn=update_process_button,
|
391 |
inputs=[input_image, text_prompt],
|
392 |
+
outputs=process_btn,
|
393 |
+
queue=False
|
394 |
)
|
395 |
+
|
396 |
process_btn.click(
|
397 |
fn=process_prompt,
|
398 |
inputs=[input_image, text_prompt, bg_prompt],
|
399 |
+
outputs=[output_display, download_btn],
|
400 |
+
queue=True
|
401 |
)
|
402 |
|
403 |
# Box tab events
|
404 |
box_annotator.change(
|
405 |
fn=lambda x: gr.Button.update(interactive=bool(x)),
|
406 |
inputs=[box_annotator],
|
407 |
+
outputs=box_btn,
|
408 |
+
queue=False
|
409 |
)
|
410 |
+
|
411 |
box_btn.click(
|
412 |
fn=process_bbox,
|
413 |
inputs=[box_annotator],
|
414 |
+
outputs=[box_output, box_download],
|
415 |
+
queue=True
|
416 |
)
|
417 |
|
418 |
+
# Launch settings
|
419 |
demo.queue(max_size=30, api_open=False)
|
420 |
demo.launch(
|
421 |
show_api=False,
|