Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -279,13 +279,6 @@ def on_change_prompt(img: Image.Image | None, prompt: str | None, bg_prompt: str
|
|
| 279 |
return gr.update(interactive=bool(img and prompt))
|
| 280 |
|
| 281 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
| 282 |
-
gr.HTML("""
|
| 283 |
-
<div class="main-title">
|
| 284 |
-
<h1>๐จ Advanced Image Object Extractor</h1>
|
| 285 |
-
<p>Extract objects from images using text prompts or bounding boxes</p>
|
| 286 |
-
</div>
|
| 287 |
-
""")
|
| 288 |
-
|
| 289 |
with gr.Tabs() as tabs:
|
| 290 |
with gr.Tab("โจ Extract by Text", id="tab_prompt"):
|
| 291 |
with gr.Row(equal_height=True):
|
|
@@ -323,19 +316,36 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
| 323 |
|
| 324 |
with gr.Accordion("๐ Examples", open=False):
|
| 325 |
examples = [
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
]
|
| 331 |
ex = gr.Examples(
|
| 332 |
examples=examples,
|
| 333 |
-
inputs=[iimg, prompt],
|
| 334 |
outputs=[oimg, dlbt],
|
| 335 |
fn=process_prompt,
|
| 336 |
cache_examples=True
|
| 337 |
)
|
| 338 |
|
|
|
|
| 339 |
with gr.Tab("๐ Extract by Box", id="tab_bb"):
|
| 340 |
with gr.Row(equal_height=True):
|
| 341 |
with gr.Column(scale=1, min_width=400):
|
|
@@ -369,32 +379,24 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
| 369 |
examples_bb = [
|
| 370 |
{
|
| 371 |
"image": "examples/text.jpg",
|
| 372 |
-
"boxes": [{"xmin": 51, "ymin": 511, "xmax": 639, "ymax": 1255}]
|
| 373 |
-
"white background" # bg_prompt ์์ ์ถ๊ฐ
|
| 374 |
-
|
| 375 |
},
|
| 376 |
{
|
| 377 |
"image": "examples/potted-plant.jpg",
|
| 378 |
-
"boxes": [{"xmin": 51, "ymin": 511, "xmax": 639, "ymax": 1255}]
|
| 379 |
-
"natural garden background"
|
| 380 |
},
|
| 381 |
{
|
| 382 |
"image": "examples/chair.jpg",
|
| 383 |
-
"boxes": [{"xmin": 98, "ymin": 330, "xmax": 973, "ymax": 1468}]
|
| 384 |
-
"modern living room"
|
| 385 |
},
|
| 386 |
{
|
| 387 |
"image": "examples/black-lamp.jpg",
|
| 388 |
-
"boxes": [{"xmin": 88, "ymin": 148, "xmax": 700, "ymax": 1414}]
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
},
|
| 392 |
]
|
| 393 |
ex_bb = gr.Examples(
|
| 394 |
examples=examples_bb,
|
| 395 |
-
|
| 396 |
-
inputs=[iimg, prompt, bg_prompt], # bg_prompt ์ถ๊ฐ
|
| 397 |
-
|
| 398 |
outputs=[oimg_bb, dlbt_bb],
|
| 399 |
fn=process_bbox,
|
| 400 |
cache_examples=True
|
|
@@ -405,14 +407,12 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
| 405 |
for inp in [iimg, prompt]:
|
| 406 |
inp.change(
|
| 407 |
fn=on_change_prompt,
|
| 408 |
-
|
| 409 |
-
inputs=[iimg, prompt, bg_prompt], # bg_prompt ์ถ๊ฐ
|
| 410 |
-
|
| 411 |
outputs=[btn],
|
| 412 |
)
|
| 413 |
btn.click(
|
| 414 |
fn=process_prompt,
|
| 415 |
-
inputs=[iimg, prompt, bg_prompt],
|
| 416 |
outputs=[oimg, dlbt],
|
| 417 |
api_name=False,
|
| 418 |
)
|
|
@@ -430,35 +430,6 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
| 430 |
api_name=False,
|
| 431 |
)
|
| 432 |
|
| 433 |
-
# CSS ์คํ์ผ ์ ์
|
| 434 |
-
css = """
|
| 435 |
-
footer {display: none}
|
| 436 |
-
.main-title {
|
| 437 |
-
text-align: center;
|
| 438 |
-
margin: 2em 0;
|
| 439 |
-
}
|
| 440 |
-
.main-title h1 {
|
| 441 |
-
color: #2196F3;
|
| 442 |
-
font-size: 2.5em;
|
| 443 |
-
}
|
| 444 |
-
.container {
|
| 445 |
-
max-width: 1200px;
|
| 446 |
-
margin: auto;
|
| 447 |
-
padding: 20px;
|
| 448 |
-
}
|
| 449 |
-
"""
|
| 450 |
-
|
| 451 |
-
# Launch settings
|
| 452 |
-
demo.queue(max_size=30, api_open=False)
|
| 453 |
-
demo.launch(
|
| 454 |
-
show_api=False,
|
| 455 |
-
share=False,
|
| 456 |
-
server_name="0.0.0.0",
|
| 457 |
-
server_port=7860,
|
| 458 |
-
show_error=True
|
| 459 |
-
)
|
| 460 |
-
|
| 461 |
-
# Launch settings
|
| 462 |
demo.queue(max_size=30, api_open=False)
|
| 463 |
demo.launch(
|
| 464 |
show_api=False,
|
|
@@ -466,4 +437,4 @@ demo.launch(
|
|
| 466 |
server_name="0.0.0.0",
|
| 467 |
server_port=7860,
|
| 468 |
show_error=True
|
| 469 |
-
)
|
|
|
|
| 279 |
return gr.update(interactive=bool(img and prompt))
|
| 280 |
|
| 281 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
with gr.Tabs() as tabs:
|
| 283 |
with gr.Tab("โจ Extract by Text", id="tab_prompt"):
|
| 284 |
with gr.Row(equal_height=True):
|
|
|
|
| 316 |
|
| 317 |
with gr.Accordion("๐ Examples", open=False):
|
| 318 |
examples = [
|
| 319 |
+
{
|
| 320 |
+
"image": "examples/text.jpg",
|
| 321 |
+
"prompt": "text",
|
| 322 |
+
"bg_prompt": "white background"
|
| 323 |
+
},
|
| 324 |
+
{
|
| 325 |
+
"image": "examples/potted-plant.jpg",
|
| 326 |
+
"prompt": "potted plant",
|
| 327 |
+
"bg_prompt": "natural garden background"
|
| 328 |
+
},
|
| 329 |
+
{
|
| 330 |
+
"image": "examples/chair.jpg",
|
| 331 |
+
"prompt": "chair",
|
| 332 |
+
"bg_prompt": "modern living room"
|
| 333 |
+
},
|
| 334 |
+
{
|
| 335 |
+
"image": "examples/black-lamp.jpg",
|
| 336 |
+
"prompt": "black lamp",
|
| 337 |
+
"bg_prompt": "minimalist interior"
|
| 338 |
+
}
|
| 339 |
]
|
| 340 |
ex = gr.Examples(
|
| 341 |
examples=examples,
|
| 342 |
+
inputs=[iimg, prompt, bg_prompt],
|
| 343 |
outputs=[oimg, dlbt],
|
| 344 |
fn=process_prompt,
|
| 345 |
cache_examples=True
|
| 346 |
)
|
| 347 |
|
| 348 |
+
# Bounding Box ํญ
|
| 349 |
with gr.Tab("๐ Extract by Box", id="tab_bb"):
|
| 350 |
with gr.Row(equal_height=True):
|
| 351 |
with gr.Column(scale=1, min_width=400):
|
|
|
|
| 379 |
examples_bb = [
|
| 380 |
{
|
| 381 |
"image": "examples/text.jpg",
|
| 382 |
+
"boxes": [{"xmin": 51, "ymin": 511, "xmax": 639, "ymax": 1255}]
|
|
|
|
|
|
|
| 383 |
},
|
| 384 |
{
|
| 385 |
"image": "examples/potted-plant.jpg",
|
| 386 |
+
"boxes": [{"xmin": 51, "ymin": 511, "xmax": 639, "ymax": 1255}]
|
|
|
|
| 387 |
},
|
| 388 |
{
|
| 389 |
"image": "examples/chair.jpg",
|
| 390 |
+
"boxes": [{"xmin": 98, "ymin": 330, "xmax": 973, "ymax": 1468}]
|
|
|
|
| 391 |
},
|
| 392 |
{
|
| 393 |
"image": "examples/black-lamp.jpg",
|
| 394 |
+
"boxes": [{"xmin": 88, "ymin": 148, "xmax": 700, "ymax": 1414}]
|
| 395 |
+
}
|
|
|
|
|
|
|
| 396 |
]
|
| 397 |
ex_bb = gr.Examples(
|
| 398 |
examples=examples_bb,
|
| 399 |
+
inputs=[annotator],
|
|
|
|
|
|
|
| 400 |
outputs=[oimg_bb, dlbt_bb],
|
| 401 |
fn=process_bbox,
|
| 402 |
cache_examples=True
|
|
|
|
| 407 |
for inp in [iimg, prompt]:
|
| 408 |
inp.change(
|
| 409 |
fn=on_change_prompt,
|
| 410 |
+
inputs=[iimg, prompt, bg_prompt],
|
|
|
|
|
|
|
| 411 |
outputs=[btn],
|
| 412 |
)
|
| 413 |
btn.click(
|
| 414 |
fn=process_prompt,
|
| 415 |
+
inputs=[iimg, prompt, bg_prompt],
|
| 416 |
outputs=[oimg, dlbt],
|
| 417 |
api_name=False,
|
| 418 |
)
|
|
|
|
| 430 |
api_name=False,
|
| 431 |
)
|
| 432 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 433 |
demo.queue(max_size=30, api_open=False)
|
| 434 |
demo.launch(
|
| 435 |
show_api=False,
|
|
|
|
| 437 |
server_name="0.0.0.0",
|
| 438 |
server_port=7860,
|
| 439 |
show_error=True
|
| 440 |
+
)
|