Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -261,6 +261,7 @@ button.primary:hover {
|
|
| 261 |
"""
|
| 262 |
|
| 263 |
# UI 부분만 수정
|
|
|
|
| 264 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
| 265 |
gr.HTML("""
|
| 266 |
<div class="main-title">
|
|
@@ -269,9 +270,9 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
| 269 |
</div>
|
| 270 |
""")
|
| 271 |
|
| 272 |
-
with gr.Tabs(selected=0)
|
| 273 |
-
# Text
|
| 274 |
-
with gr.TabItem("Extract by Text")
|
| 275 |
with gr.Row():
|
| 276 |
with gr.Column(scale=1):
|
| 277 |
input_image = gr.Image(
|
|
@@ -279,17 +280,16 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
| 279 |
label="Upload Image",
|
| 280 |
interactive=True
|
| 281 |
)
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
)
|
| 293 |
process_btn = gr.Button(
|
| 294 |
"Process",
|
| 295 |
variant="primary",
|
|
@@ -297,7 +297,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
| 297 |
)
|
| 298 |
|
| 299 |
with gr.Column(scale=1):
|
| 300 |
-
output_display =
|
| 301 |
label="Results",
|
| 302 |
show_download_button=False,
|
| 303 |
visible=True
|
|
@@ -307,29 +307,19 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
| 307 |
visible=True
|
| 308 |
)
|
| 309 |
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
["examples/text.jpg", "text", "white background"],
|
| 314 |
-
["examples/black-lamp.jpg", "black lamp", "minimalist interior"]
|
| 315 |
-
],
|
| 316 |
-
inputs=[input_image, text_prompt, bg_prompt],
|
| 317 |
-
outputs=[output_display, download_btn],
|
| 318 |
-
fn=process_prompt,
|
| 319 |
-
cache_examples=True
|
| 320 |
-
)
|
| 321 |
-
|
| 322 |
-
# Box 탭
|
| 323 |
-
with gr.TabItem("Extract by Box") as box_tab:
|
| 324 |
with gr.Row():
|
| 325 |
with gr.Column(scale=1):
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
label="
|
|
|
|
| 333 |
interactive=True
|
| 334 |
)
|
| 335 |
box_btn = gr.Button(
|
|
@@ -339,42 +329,17 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
| 339 |
)
|
| 340 |
|
| 341 |
with gr.Column(scale=1):
|
| 342 |
-
box_output =
|
| 343 |
label="Results",
|
| 344 |
show_download_button=False,
|
| 345 |
visible=True
|
| 346 |
)
|
| 347 |
box_download = gr.DownloadButton(
|
| 348 |
-
"Download Result",
|
| 349 |
visible=True
|
| 350 |
)
|
| 351 |
|
| 352 |
-
|
| 353 |
-
gr.Examples(
|
| 354 |
-
examples=[
|
| 355 |
-
{
|
| 356 |
-
"image": "examples/text.jpg",
|
| 357 |
-
"boxes": [{"xmin": 51, "ymin": 511, "xmax": 639, "ymax": 1255}]
|
| 358 |
-
},
|
| 359 |
-
{
|
| 360 |
-
"image": "examples/black-lamp.jpg",
|
| 361 |
-
"boxes": [{"xmin": 88, "ymin": 148, "xmax": 700, "ymax": 1414}]
|
| 362 |
-
}
|
| 363 |
-
],
|
| 364 |
-
inputs=[box_annotator],
|
| 365 |
-
outputs=[box_output, box_download],
|
| 366 |
-
fn=process_bbox,
|
| 367 |
-
cache_examples=True
|
| 368 |
-
)
|
| 369 |
-
|
| 370 |
-
# Event handlers
|
| 371 |
-
def update_process_button(img, prompt):
|
| 372 |
-
return gr.Button.update(
|
| 373 |
-
interactive=bool(img and prompt),
|
| 374 |
-
variant="primary" if bool(img and prompt) else "secondary"
|
| 375 |
-
)
|
| 376 |
-
|
| 377 |
-
# Text tab events
|
| 378 |
input_image.change(
|
| 379 |
fn=update_process_button,
|
| 380 |
inputs=[input_image, text_prompt],
|
|
@@ -388,7 +353,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
| 388 |
outputs=process_btn,
|
| 389 |
queue=False
|
| 390 |
)
|
| 391 |
-
|
| 392 |
process_btn.click(
|
| 393 |
fn=process_prompt,
|
| 394 |
inputs=[input_image, text_prompt, bg_prompt],
|
|
@@ -396,27 +361,19 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
| 396 |
queue=True
|
| 397 |
)
|
| 398 |
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
inputs=[box_annotator],
|
| 403 |
outputs=box_btn,
|
| 404 |
queue=False
|
| 405 |
)
|
| 406 |
-
|
| 407 |
box_btn.click(
|
| 408 |
fn=process_bbox,
|
| 409 |
-
inputs=[
|
| 410 |
outputs=[box_output, box_download],
|
| 411 |
queue=True
|
| 412 |
)
|
| 413 |
-
|
| 414 |
-
# Launch settings
|
| 415 |
demo.queue(max_size=30, api_open=False)
|
| 416 |
-
demo.launch(
|
| 417 |
-
show_api=False,
|
| 418 |
-
share=False,
|
| 419 |
-
server_name="0.0.0.0",
|
| 420 |
-
server_port=7860,
|
| 421 |
-
show_error=True
|
| 422 |
-
)
|
|
|
|
| 261 |
"""
|
| 262 |
|
| 263 |
# UI 부분만 수정
|
| 264 |
+
# Main Gradio app
|
| 265 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
| 266 |
gr.HTML("""
|
| 267 |
<div class="main-title">
|
|
|
|
| 270 |
</div>
|
| 271 |
""")
|
| 272 |
|
| 273 |
+
with gr.Tabs(selected=0):
|
| 274 |
+
# Tab for Text-based Object Extraction
|
| 275 |
+
with gr.TabItem("Extract by Text"):
|
| 276 |
with gr.Row():
|
| 277 |
with gr.Column(scale=1):
|
| 278 |
input_image = gr.Image(
|
|
|
|
| 280 |
label="Upload Image",
|
| 281 |
interactive=True
|
| 282 |
)
|
| 283 |
+
text_prompt = gr.Textbox(
|
| 284 |
+
label="Object to Extract",
|
| 285 |
+
placeholder="Enter what you want to extract...",
|
| 286 |
+
interactive=True
|
| 287 |
+
)
|
| 288 |
+
bg_prompt = gr.Textbox(
|
| 289 |
+
label="Background Prompt (optional)",
|
| 290 |
+
placeholder="Describe the background...",
|
| 291 |
+
interactive=True
|
| 292 |
+
)
|
|
|
|
| 293 |
process_btn = gr.Button(
|
| 294 |
"Process",
|
| 295 |
variant="primary",
|
|
|
|
| 297 |
)
|
| 298 |
|
| 299 |
with gr.Column(scale=1):
|
| 300 |
+
output_display = gr.Gallery(
|
| 301 |
label="Results",
|
| 302 |
show_download_button=False,
|
| 303 |
visible=True
|
|
|
|
| 307 |
visible=True
|
| 308 |
)
|
| 309 |
|
| 310 |
+
|
| 311 |
+
# Tab for Box-based Object Extraction
|
| 312 |
+
with gr.TabItem("Extract by Box"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
with gr.Row():
|
| 314 |
with gr.Column(scale=1):
|
| 315 |
+
box_image = gr.Image(
|
| 316 |
+
type="pil",
|
| 317 |
+
label="Upload Image for Box",
|
| 318 |
+
interactive=True
|
| 319 |
+
)
|
| 320 |
+
box_input = gr.Textbox(
|
| 321 |
+
label="Bounding Box (xmin, ymin, xmax, ymax)",
|
| 322 |
+
placeholder="Enter bounding box coordinates as a list",
|
| 323 |
interactive=True
|
| 324 |
)
|
| 325 |
box_btn = gr.Button(
|
|
|
|
| 329 |
)
|
| 330 |
|
| 331 |
with gr.Column(scale=1):
|
| 332 |
+
box_output = gr.Gallery(
|
| 333 |
label="Results",
|
| 334 |
show_download_button=False,
|
| 335 |
visible=True
|
| 336 |
)
|
| 337 |
box_download = gr.DownloadButton(
|
| 338 |
+
"Download Box Result",
|
| 339 |
visible=True
|
| 340 |
)
|
| 341 |
|
| 342 |
+
# Event bindings
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
input_image.change(
|
| 344 |
fn=update_process_button,
|
| 345 |
inputs=[input_image, text_prompt],
|
|
|
|
| 353 |
outputs=process_btn,
|
| 354 |
queue=False
|
| 355 |
)
|
| 356 |
+
|
| 357 |
process_btn.click(
|
| 358 |
fn=process_prompt,
|
| 359 |
inputs=[input_image, text_prompt, bg_prompt],
|
|
|
|
| 361 |
queue=True
|
| 362 |
)
|
| 363 |
|
| 364 |
+
box_image.change(
|
| 365 |
+
fn=update_process_button,
|
| 366 |
+
inputs=[box_image, box_input],
|
|
|
|
| 367 |
outputs=box_btn,
|
| 368 |
queue=False
|
| 369 |
)
|
| 370 |
+
|
| 371 |
box_btn.click(
|
| 372 |
fn=process_bbox,
|
| 373 |
+
inputs=[box_image, box_input],
|
| 374 |
outputs=[box_output, box_download],
|
| 375 |
queue=True
|
| 376 |
)
|
| 377 |
+
|
|
|
|
| 378 |
demo.queue(max_size=30, api_open=False)
|
| 379 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|