feature(run): 添加参数

This commit is contained in:
ClovertaTheTrilobita 2025-09-18 16:57:14 +03:00
parent 6f81e0d07a
commit 3ebc7ca909
2 changed files with 56 additions and 22 deletions

View file

@ -69,6 +69,9 @@ def upload():
diameter_raw = request.args.get("diameter") or request.form.get("diameter") diameter_raw = request.args.get("diameter") or request.form.get("diameter")
diameter = _to_float(diameter_raw, None) if diameter_raw not in (None, "") else None diameter = _to_float(diameter_raw, None) if diameter_raw not in (None, "") else None
print("cpt:" + str(cellprob_threshold))
print("flow:" + str(flow_threshold))
# 将文件保存在本地目录中 # 将文件保存在本地目录中
ts = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + f"-{int(time.time()*1000)%1000:03d}" ts = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + f"-{int(time.time()*1000)%1000:03d}"
os.makedirs(UPLOAD_DIR / ts, exist_ok=True) os.makedirs(UPLOAD_DIR / ts, exist_ok=True)

View file

@ -2,32 +2,63 @@
<input id="fileInput" type="file" multiple /> <input id="fileInput" type="file" multiple />
<button id="uploadBtn">Upload</button> <button id="uploadBtn">Upload</button>
<progress id="bar" max="100" value="0" style="width:300px;"></progress> <progress id="bar" max="100" value="0" style="width:300px;"></progress>
<br><br><br>
<label>flow_threshold:
<input id="flow" type="text" placeholder="" />
</label>
<br><br>
<label>cellprob_threshold:
<input id="cellprob" type="text" placeholder="" />
</label>
<br><br>
<label>模型(下拉单选):
<select id="model">
<option value="cpsam">cpsam</option>
</select>
</label>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script> <script>
const API = "http://10.147.18.141:5000/upload"; const API = "http://10.147.18.141:5000/upload";
document.getElementById("uploadBtn").addEventListener("click", async () => { function buildUrl() {
const input = document.getElementById("fileInput"); // 读单选:取 name="mode" 被勾选的那个
if (!input.files.length) return alert("请选择文件"); const model = document.getElementById('model')?.value;
const flow = (document.getElementById('flow')?.value || '').trim();
const cellp = (document.getElementById('cellprob')?.value || '').trim();
const fd = new FormData(); // 用 URLSearchParams 组装查询串(避免多 ? 以及手写 &
for (const f of input.files) fd.append("files", f); const qs = new URLSearchParams({
model: model,
const bar = document.getElementById("bar"); flow_threshold: flow,
try { cellprob_threshold: cellp
const res = await axios.post(API, fd, {
onUploadProgress: (e) => {
if (e.total) bar.value = Math.round((e.loaded * 100) / e.total);
},
// 不要显式设置 Content-Type
}); });
alert("上传成功:" + JSON.stringify(res.data));
window.location.href = `preview.html?id=${encodeURIComponent(res.data['id'])}`; return `${API}?${qs.toString()}`;
} catch (e) {
alert("上传失败:" + (e.response?.data?.message || e.message));
} finally {
bar.value = 0;
} }
});
</script> document.getElementById("uploadBtn").addEventListener("click", async () => {
const input = document.getElementById("fileInput");
if (!input.files.length) return alert("请选择文件");
const fd = new FormData();
for (const f of input.files) fd.append("files", f);
const bar = document.getElementById("bar");
try {
const URL = buildUrl();
const res = await axios.post(URL, fd, {
onUploadProgress: (e) => {
if (e.total) bar.value = Math.round((e.loaded * 100) / e.total);
},
// 不要显式设置 Content-Type
});
alert("上传成功:" + JSON.stringify(res.data));
window.location.href = `preview.html?id=${encodeURIComponent(res.data['id'])}`;
} catch (e) {
alert("上传失败:" + (e.response?.data?.message || e.message));
} finally {
bar.value = 0;
}
});
</script>