From 0867b974537800c71f24980c45b426f6fb635b3e Mon Sep 17 00:00:00 2001 From: ClovertaTheTrilobita Date: Wed, 17 Sep 2025 23:46:25 +0300 Subject: [PATCH] =?UTF-8?q?feature(preview):=20=E5=A2=9E=E5=8A=A0=E9=A2=84?= =?UTF-8?q?=E8=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- backend/cp_run.py | 4 ++-- backend/flaskApp.py | 27 ++++++++++++++++++++++++++- frontend/preview.html | 43 ++++++++++++++++++++++++++++--------------- 4 files changed, 57 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 4988be3..5abc406 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ *.png backend/test_output -test_output/* +test_output/ test_tif output uploads diff --git a/backend/cp_run.py b/backend/cp_run.py index 1b8bd72..857914f 100644 --- a/backend/cp_run.py +++ b/backend/cp_run.py @@ -41,8 +41,8 @@ class Cprun: time: str | None = None, model: str = "cpsam", diameter: float | None = None, - flow_threshold: float | float = 0.4, - cellprob_threshold: float | float = 0.0, ): + flow_threshold: float = 0.4, + cellprob_threshold: float = 0.0, ): if time is None: return [False, "No time received"] diff --git a/backend/flaskApp.py b/backend/flaskApp.py index 73c5856..ef300d6 100644 --- a/backend/flaskApp.py +++ b/backend/flaskApp.py @@ -1,4 +1,5 @@ import asyncio +import base64 from concurrent.futures import ThreadPoolExecutor from flask import Flask, send_from_directory, request, jsonify import os, shutil, time, threading, datetime, json, redis @@ -103,7 +104,7 @@ def upload(): return jsonify({"ok": True, "count": len(saved), "id": ts}) -@app.get("/status/") +@app.get("/status") def status(): """ 检查某一cellpose任务是否完成 @@ -115,3 +116,27 @@ def status(): if not st: return jsonify({"ok": True, "exists": False, "status": "not_found"}), 200 return jsonify({"ok": True, "exists": True, **st}), 200 + +@app.get("/preview") +def preview(): + task_id = request.args.get('id') + task_dir = BASE_DIR / "output" / task_id + if not task_dir.exists(): + return jsonify({"ok": False, "error": "task not found"}), 200 + + # 找出所有 *_overlay.png 文件 + files = sorted(task_dir.glob("*_overlay.png")) + + if not files: + return jsonify({"ok": False, "error": "no overlay images"}), 200 + + result = [] + for path in files: + data = path.read_bytes() + encoded = base64.b64encode(data).decode("utf-8") + result.append({ + "filename": path.name, + "image": encoded + }) + + return jsonify({"ok": True, "count": len(result), "images": result}) \ No newline at end of file diff --git a/frontend/preview.html b/frontend/preview.html index 6278803..724be7a 100644 --- a/frontend/preview.html +++ b/frontend/preview.html @@ -1,35 +1,48 @@

This is preview

- + +