Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -518,12 +518,27 @@ with gr.Blocks(title="Microscopy Analysis Suite", theme=gr.themes.Soft()) as dem
|
|
| 518 |
label="🖼️ 上传图像",
|
| 519 |
type="filepath"
|
| 520 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 521 |
count_btn = gr.Button("▶️ 运行计数", variant="primary", size="lg")
|
| 522 |
|
| 523 |
gr.Markdown(
|
| 524 |
"""
|
| 525 |
**使用说明:**
|
| 526 |
-
1.
|
| 527 |
2. 点击 "运行计数"
|
| 528 |
3. 查看密度图和计数结果
|
| 529 |
"""
|
|
@@ -533,18 +548,60 @@ with gr.Blocks(title="Microscopy Analysis Suite", theme=gr.themes.Soft()) as dem
|
|
| 533 |
count_output = gr.Image(
|
| 534 |
label="📸 密度图",
|
| 535 |
type="filepath",
|
| 536 |
-
height=
|
| 537 |
)
|
| 538 |
count_status = gr.Textbox(
|
| 539 |
label="📊 统计信息",
|
| 540 |
lines=2
|
| 541 |
)
|
| 542 |
|
|
|
|
| 543 |
count_btn.click(
|
| 544 |
fn=count_cells_handler,
|
| 545 |
inputs=count_input,
|
| 546 |
outputs=[count_output, count_status]
|
| 547 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 548 |
|
| 549 |
# ===== Tab 3: Tracking =====
|
| 550 |
with gr.Tab("🎬 跟踪 (Tracking)"):
|
|
|
|
| 518 |
label="🖼️ 上传图像",
|
| 519 |
type="filepath"
|
| 520 |
)
|
| 521 |
+
|
| 522 |
+
# 示例图片Gallery (与Segmentation相同)
|
| 523 |
+
count_example_gallery = gr.Gallery(
|
| 524 |
+
label="📁 示例图片",
|
| 525 |
+
columns=3,
|
| 526 |
+
object_fit="cover",
|
| 527 |
+
height=150
|
| 528 |
+
)
|
| 529 |
+
|
| 530 |
+
# 上传示例图片
|
| 531 |
+
count_image_uploader = gr.Image(
|
| 532 |
+
label="➕ 上传新示例到Gallery",
|
| 533 |
+
type="filepath"
|
| 534 |
+
)
|
| 535 |
+
|
| 536 |
count_btn = gr.Button("▶️ 运行计数", variant="primary", size="lg")
|
| 537 |
|
| 538 |
gr.Markdown(
|
| 539 |
"""
|
| 540 |
**使用说明:**
|
| 541 |
+
1. 上传图像或从Gallery选择示例
|
| 542 |
2. 点击 "运行计数"
|
| 543 |
3. 查看密度图和计数结果
|
| 544 |
"""
|
|
|
|
| 548 |
count_output = gr.Image(
|
| 549 |
label="📸 密度图",
|
| 550 |
type="filepath",
|
| 551 |
+
height=400
|
| 552 |
)
|
| 553 |
count_status = gr.Textbox(
|
| 554 |
label="📊 统计信息",
|
| 555 |
lines=2
|
| 556 |
)
|
| 557 |
|
| 558 |
+
# 绑定事件
|
| 559 |
count_btn.click(
|
| 560 |
fn=count_cells_handler,
|
| 561 |
inputs=count_input,
|
| 562 |
outputs=[count_output, count_status]
|
| 563 |
)
|
| 564 |
+
|
| 565 |
+
# 初始化Gallery显示
|
| 566 |
+
demo.load(
|
| 567 |
+
fn=lambda: example_images.copy(),
|
| 568 |
+
outputs=count_example_gallery
|
| 569 |
+
)
|
| 570 |
+
|
| 571 |
+
# 绑定事件: 上传示例图片到Counting Gallery
|
| 572 |
+
count_user_examples = gr.State(example_images.copy())
|
| 573 |
+
|
| 574 |
+
def add_to_count_gallery(img_path, current_imgs):
|
| 575 |
+
if not img_path:
|
| 576 |
+
return current_imgs
|
| 577 |
+
try:
|
| 578 |
+
if img_path not in current_imgs:
|
| 579 |
+
current_imgs.append(img_path)
|
| 580 |
+
return current_imgs
|
| 581 |
+
except:
|
| 582 |
+
return current_imgs
|
| 583 |
+
|
| 584 |
+
count_image_uploader.change(
|
| 585 |
+
fn=add_to_count_gallery,
|
| 586 |
+
inputs=[count_image_uploader, count_user_examples],
|
| 587 |
+
outputs=count_user_examples
|
| 588 |
+
).then(
|
| 589 |
+
fn=lambda imgs: imgs,
|
| 590 |
+
inputs=count_user_examples,
|
| 591 |
+
outputs=count_example_gallery
|
| 592 |
+
)
|
| 593 |
+
|
| 594 |
+
# 绑定事件: 点击Gallery加载到count_input
|
| 595 |
+
def load_from_count_gallery(evt: gr.SelectData, all_imgs):
|
| 596 |
+
if evt.index is not None and evt.index < len(all_imgs):
|
| 597 |
+
return all_imgs[evt.index]
|
| 598 |
+
return None
|
| 599 |
+
|
| 600 |
+
count_example_gallery.select(
|
| 601 |
+
fn=load_from_count_gallery,
|
| 602 |
+
inputs=count_user_examples,
|
| 603 |
+
outputs=count_input
|
| 604 |
+
)
|
| 605 |
|
| 606 |
# ===== Tab 3: Tracking =====
|
| 607 |
with gr.Tab("🎬 跟踪 (Tracking)"):
|