Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -475,6 +475,43 @@ def segment_with_choice(use_box_choice, annot_value, mode="Overlay"):
|
|
| 475 |
return Image.fromarray(overlay), result_text
|
| 476 |
|
| 477 |
# ===== 计数功能 =====
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 478 |
import zipfile
|
| 479 |
import tempfile
|
| 480 |
import shutil
|
|
|
|
| 475 |
return Image.fromarray(overlay), result_text
|
| 476 |
|
| 477 |
# ===== 计数功能 =====
|
| 478 |
+
def count_cells_handler(image_path):
|
| 479 |
+
"""计数处理函数"""
|
| 480 |
+
if image_path is None:
|
| 481 |
+
return None, "⚠️ 请先上传图像"
|
| 482 |
+
|
| 483 |
+
if COUNT_MODEL is None:
|
| 484 |
+
return None, "❌ 计数模型未加载"
|
| 485 |
+
|
| 486 |
+
try:
|
| 487 |
+
print(f"🔢 Counting - Image: {image_path}")
|
| 488 |
+
|
| 489 |
+
result = run_count(
|
| 490 |
+
COUNT_MODEL,
|
| 491 |
+
image_path,
|
| 492 |
+
box=None,
|
| 493 |
+
device=COUNT_DEVICE,
|
| 494 |
+
visualize=True
|
| 495 |
+
)
|
| 496 |
+
|
| 497 |
+
if 'error' in result:
|
| 498 |
+
return None, f"❌ 计数失败: {result['error']}"
|
| 499 |
+
|
| 500 |
+
count = result['count']
|
| 501 |
+
viz_path = result['visualized_path']
|
| 502 |
+
result_text = f"✅ 检测到 {count:.1f} 个细胞"
|
| 503 |
+
|
| 504 |
+
print(f"✅ Counting done - Count: {count:.1f}")
|
| 505 |
+
|
| 506 |
+
return viz_path, result_text
|
| 507 |
+
|
| 508 |
+
except Exception as e:
|
| 509 |
+
print(f"❌ Counting error: {e}")
|
| 510 |
+
import traceback
|
| 511 |
+
traceback.print_exc()
|
| 512 |
+
return None, f"❌ 计数失败: {str(e)}"
|
| 513 |
+
|
| 514 |
+
# ===== 跟踪功能 =====
|
| 515 |
import zipfile
|
| 516 |
import tempfile
|
| 517 |
import shutil
|