Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -516,6 +516,13 @@ import zipfile
|
|
| 516 |
import tempfile
|
| 517 |
import shutil
|
| 518 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 519 |
def track_video_handler(zip_file_obj):
|
| 520 |
"""支持 ZIP 压缩包上传的 Tracking 处理函数"""
|
| 521 |
if zip_file_obj is None:
|
|
@@ -533,11 +540,16 @@ def track_video_handler(zip_file_obj):
|
|
| 533 |
with zipfile.ZipFile(zip_file_obj.name, 'r') as zip_ref:
|
| 534 |
zip_ref.extractall(temp_dir)
|
| 535 |
|
| 536 |
-
|
|
|
|
|
|
|
|
|
|
| 537 |
|
|
|
|
|
|
|
| 538 |
result = run_track(
|
| 539 |
TRACK_MODEL,
|
| 540 |
-
video_dir=
|
| 541 |
box=None,
|
| 542 |
device=TRACK_DEVICE,
|
| 543 |
output_dir="tracked_results"
|
|
@@ -551,17 +563,17 @@ def track_video_handler(zip_file_obj):
|
|
| 551 |
|
| 552 |
result_text = f"""✅ 跟踪完成!
|
| 553 |
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
|
| 562 |
print(f"✅ Tracking done - {num_tracks} tracks")
|
| 563 |
|
| 564 |
-
return
|
| 565 |
|
| 566 |
except zipfile.BadZipFile:
|
| 567 |
return None, "❌ 上传的文件不是有效的 ZIP 压缩包"
|
|
@@ -570,7 +582,6 @@ def track_video_handler(zip_file_obj):
|
|
| 570 |
import traceback
|
| 571 |
traceback.print_exc()
|
| 572 |
return None, f"❌ 跟踪失败: {str(e)}"
|
| 573 |
-
|
| 574 |
# ===== Gradio UI =====
|
| 575 |
with gr.Blocks(title="Microscopy Analysis Suite", theme=gr.themes.Soft()) as demo:
|
| 576 |
gr.Markdown(
|
|
|
|
| 516 |
import tempfile
|
| 517 |
import shutil
|
| 518 |
|
| 519 |
+
def find_tif_dir(root_dir):
|
| 520 |
+
"""递归查找第一个包含 .tif 文件的目录"""
|
| 521 |
+
for dirpath, _, filenames in os.walk(root_dir):
|
| 522 |
+
if any(f.lower().endswith('.tif') for f in filenames):
|
| 523 |
+
return dirpath
|
| 524 |
+
return None
|
| 525 |
+
|
| 526 |
def track_video_handler(zip_file_obj):
|
| 527 |
"""支持 ZIP 压缩包上传的 Tracking 处理函数"""
|
| 528 |
if zip_file_obj is None:
|
|
|
|
| 540 |
with zipfile.ZipFile(zip_file_obj.name, 'r') as zip_ref:
|
| 541 |
zip_ref.extractall(temp_dir)
|
| 542 |
|
| 543 |
+
# 自动查找含 .tif 的子目录
|
| 544 |
+
tif_dir = find_tif_dir(temp_dir)
|
| 545 |
+
if tif_dir is None:
|
| 546 |
+
return None, f"❌ 跟踪失败: 解压后未找到任何 .tif 图像"
|
| 547 |
|
| 548 |
+
print(f"🎬 Tracking - Found .tif in folder: {tif_dir}")
|
| 549 |
+
|
| 550 |
result = run_track(
|
| 551 |
TRACK_MODEL,
|
| 552 |
+
video_dir=tif_dir, # 使用真正含图像的目录
|
| 553 |
box=None,
|
| 554 |
device=TRACK_DEVICE,
|
| 555 |
output_dir="tracked_results"
|
|
|
|
| 563 |
|
| 564 |
result_text = f"""✅ 跟踪完成!
|
| 565 |
|
| 566 |
+
🎯 跟踪轨迹数量: {num_tracks}
|
| 567 |
+
📁 结果保存在: {output_dir}
|
| 568 |
+
|
| 569 |
+
包含的文件:
|
| 570 |
+
- res_track.txt (CTC格式轨迹)
|
| 571 |
+
- 其他跟踪数据文件
|
| 572 |
+
"""
|
| 573 |
|
| 574 |
print(f"✅ Tracking done - {num_tracks} tracks")
|
| 575 |
|
| 576 |
+
return None, result_text
|
| 577 |
|
| 578 |
except zipfile.BadZipFile:
|
| 579 |
return None, "❌ 上传的文件不是有效的 ZIP 压缩包"
|
|
|
|
| 582 |
import traceback
|
| 583 |
traceback.print_exc()
|
| 584 |
return None, f"❌ 跟踪失败: {str(e)}"
|
|
|
|
| 585 |
# ===== Gradio UI =====
|
| 586 |
with gr.Blocks(title="Microscopy Analysis Suite", theme=gr.themes.Soft()) as demo:
|
| 587 |
gr.Markdown(
|