From 03c484aa0725ce04fe0143d51fb67ebe506ee91b Mon Sep 17 00:00:00 2001 From: ClovertaTheTrilobita Date: Tue, 16 Sep 2025 22:14:17 +0300 Subject: [PATCH] =?UTF-8?q?feature(frontend):=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E5=89=8D=E7=AB=AF=20refactor:=20?= =?UTF-8?q?=E9=87=8D=E6=9E=84=E9=A1=B9=E7=9B=AE=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore => backend/.gitignore | 3 ++- cp_run.py => backend/cp_run.py | 0 cp_train.py => backend/cp_train.py | 0 flaskApp.py => backend/flaskApp.py | 18 ++++++++++------- main.py => backend/main.py | 0 backend/requirements.txt | 6 ++++++ frontend/index.html | 31 ++++++++++++++++++++++++++++++ 7 files changed, 50 insertions(+), 8 deletions(-) rename .gitignore => backend/.gitignore (74%) rename cp_run.py => backend/cp_run.py (100%) rename cp_train.py => backend/cp_train.py (100%) rename flaskApp.py => backend/flaskApp.py (60%) rename main.py => backend/main.py (100%) create mode 100644 backend/requirements.txt create mode 100644 frontend/index.html diff --git a/.gitignore b/backend/.gitignore similarity index 74% rename from .gitignore rename to backend/.gitignore index 11cf02a..c5713f2 100644 --- a/.gitignore +++ b/backend/.gitignore @@ -2,4 +2,5 @@ test_output test_output/* test_tif -output \ No newline at end of file +output +uploads \ No newline at end of file diff --git a/cp_run.py b/backend/cp_run.py similarity index 100% rename from cp_run.py rename to backend/cp_run.py diff --git a/cp_train.py b/backend/cp_train.py similarity index 100% rename from cp_train.py rename to backend/cp_train.py diff --git a/flaskApp.py b/backend/flaskApp.py similarity index 60% rename from flaskApp.py rename to backend/flaskApp.py index 762b714..f6a6f2c 100644 --- a/flaskApp.py +++ b/backend/flaskApp.py @@ -1,9 +1,13 @@ from flask import Flask, send_from_directory, request, jsonify import os, shutil, time, threading from werkzeug.utils import secure_filename +from flask_cors import CORS +from pathlib import Path app = Flask(__name__) -UPLOAD_DIR = "./uploads" +CORS(app) +BASE_DIR = Path(__file__).resolve().parent +UPLOAD_DIR = BASE_DIR / "uploads" os.makedirs(UPLOAD_DIR, exist_ok=True) def run_flask(): @@ -15,21 +19,21 @@ def index(): @app.route("/testdl") def test_download(): - return send_from_directory("./test_output/2025-09-16-20-03-51", "img_overlay.png", as_attachment=True) + return send_from_directory("test_output/2025-09-16-20-03-51", "img_overlay.png", as_attachment=True) @app.route("/dl/") def download(timestamp): - input_dir = os.path.join("./output", timestamp) - output_dir = os.path.join("./output/tmp", timestamp) # 不要加 .zip,make_archive 会自动加 - os.makedirs("./output/tmp", exist_ok=True) # 确保 tmp 存在 + input_dir = os.path.join("output", timestamp) + output_dir = os.path.join("output/tmp", timestamp) # 不要加 .zip,make_archive 会自动加 + os.makedirs("output/tmp", exist_ok=True) # 确保 tmp 存在 shutil.make_archive(output_dir, 'zip', input_dir) print(f"压缩完成: {output_dir}.zip") - return send_from_directory("./output/tmp", f"{timestamp}.zip", as_attachment=True) + return send_from_directory("output/tmp", f"{timestamp}.zip", as_attachment=True) @app.post("/upload") def upload(): - files = request.files.getlist("files") # ← 前端用同一个键名多次 append + files = request.files.getlist("files") saved = [] for f in files: if not f or f.filename == "": diff --git a/main.py b/backend/main.py similarity index 100% rename from main.py rename to backend/main.py diff --git a/backend/requirements.txt b/backend/requirements.txt new file mode 100644 index 0000000..3ddb55f --- /dev/null +++ b/backend/requirements.txt @@ -0,0 +1,6 @@ +numpy~=2.1.2 +cellpose~=4.0.6 +pillow~=11.0.0 +sympy~=1.13.3 +flask~=3.1.2 +werkzeug~=3.1.3 \ No newline at end of file diff --git a/frontend/index.html b/frontend/index.html new file mode 100644 index 0000000..63398b8 --- /dev/null +++ b/frontend/index.html @@ -0,0 +1,31 @@ + + + + + +