✨ add more topk choice
This commit is contained in:
parent
b71b8c1b23
commit
7969226a6a
@ -356,7 +356,11 @@
|
|||||||
<option value="3">Top 3</option>
|
<option value="3">Top 3</option>
|
||||||
<option value="5" selected>Top 5</option>
|
<option value="5" selected>Top 5</option>
|
||||||
<option value="10">Top 10</option>
|
<option value="10">Top 10</option>
|
||||||
|
<option value="50">Top 50</option>
|
||||||
|
<option value="100">Top 100</option>
|
||||||
|
<option value="custom">自定义</option>
|
||||||
</select>
|
</select>
|
||||||
|
<input id="textTopKCustom" type="number" min="1" max="1000" placeholder="自定义K" class="form-control mt-2" style="display:none;" />
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-2">
|
<div class="col-md-2">
|
||||||
<button id="textSearchBtn" class="btn btn-primary w-100">
|
<button id="textSearchBtn" class="btn btn-primary w-100">
|
||||||
@ -382,7 +386,11 @@
|
|||||||
<option value="3">Top 3</option>
|
<option value="3">Top 3</option>
|
||||||
<option value="5" selected>Top 5</option>
|
<option value="5" selected>Top 5</option>
|
||||||
<option value="10">Top 10</option>
|
<option value="10">Top 10</option>
|
||||||
|
<option value="50">Top 50</option>
|
||||||
|
<option value="100">Top 100</option>
|
||||||
|
<option value="custom">自定义</option>
|
||||||
</select>
|
</select>
|
||||||
|
<input id="imageTopKCustom" type="number" min="1" max="1000" placeholder="自定义K" class="form-control mt-2" style="display:none;" />
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-2">
|
<div class="col-md-2">
|
||||||
<button id="imageSearchBtn" class="btn btn-primary w-100" disabled>
|
<button id="imageSearchBtn" class="btn btn-primary w-100" disabled>
|
||||||
@ -481,9 +489,34 @@
|
|||||||
if (e.key === 'Enter') performTextSearch();
|
if (e.key === 'Enter') performTextSearch();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TopK 自定义输入显隐
|
||||||
|
const textTopKSel = document.getElementById('textTopK');
|
||||||
|
const textTopKCustom = document.getElementById('textTopKCustom');
|
||||||
|
const imageTopKSel = document.getElementById('imageTopK');
|
||||||
|
const imageTopKCustom = document.getElementById('imageTopKCustom');
|
||||||
|
textTopKSel.addEventListener('change', () => {
|
||||||
|
textTopKCustom.style.display = textTopKSel.value === 'custom' ? 'block' : 'none';
|
||||||
|
});
|
||||||
|
imageTopKSel.addEventListener('change', () => {
|
||||||
|
imageTopKCustom.style.display = imageTopKSel.value === 'custom' ? 'block' : 'none';
|
||||||
|
});
|
||||||
|
|
||||||
|
function resolveTopK(selectEl, customEl) {
|
||||||
|
let v = selectEl.value;
|
||||||
|
if (v === 'custom') {
|
||||||
|
const n = parseInt(customEl.value, 10);
|
||||||
|
if (!Number.isFinite(n) || n <= 0) {
|
||||||
|
showAlert('warning', '请输入有效的自定义 Top K 数值');
|
||||||
|
throw new Error('Invalid custom TopK');
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
return parseInt(v, 10);
|
||||||
|
}
|
||||||
|
|
||||||
async function performTextSearch() {
|
async function performTextSearch() {
|
||||||
const query = document.getElementById('textQuery').value.trim();
|
const query = document.getElementById('textQuery').value.trim();
|
||||||
const topK = parseInt(document.getElementById('textTopK').value);
|
const topK = resolveTopK(textTopKSel, textTopKCustom);
|
||||||
|
|
||||||
if (!query) {
|
if (!query) {
|
||||||
showAlert('warning', '请输入搜索文本');
|
showAlert('warning', '请输入搜索文本');
|
||||||
@ -563,7 +596,7 @@
|
|||||||
// 图片搜索
|
// 图片搜索
|
||||||
document.getElementById('imageSearchBtn').addEventListener('click', async function() {
|
document.getElementById('imageSearchBtn').addEventListener('click', async function() {
|
||||||
const file = imageFile.files[0];
|
const file = imageFile.files[0];
|
||||||
const topK = parseInt(document.getElementById('imageTopK').value);
|
const topK = resolveTopK(imageTopKSel, imageTopKCustom);
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
showAlert('warning', '请选择图片文件');
|
showAlert('warning', '请选择图片文件');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user