Add default verification model config in system settings and always pass model to v5/qr_verify

This commit is contained in:
Fam Zheng 2025-11-25 23:34:21 +00:00
parent 97649c81b1
commit 9060186edb
2 changed files with 54 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import time
import base64
import hashlib
import mimetypes
import json
from collections import defaultdict
from tastypie.resources import ModelResource
from .models import *
@ -678,12 +679,29 @@ def get_code_from_url(url):
class QrVerifyView(BaseView):
name = 'qr-verify'
def get_default_verification_model_name(self):
"""Get default verification model name from global config"""
try:
gc = GlobalConfig.objects.filter(name='default_verification_model').first()
if gc and gc.value:
model_id = json.loads(gc.value)
if model_id:
vm = VerificationModel.objects.filter(pk=model_id).first()
if vm:
return vm.name
except Exception:
pass
return None
def do_v5_qr_verify(self, imgs, messages, model_name=None):
files = {}
for i, img in enumerate(imgs):
files[f'frame_{i}_{img[1]}'] = img[0]
data = {}
# Always pass model - use provided model_name or get default from global config
if not model_name:
model_name = self.get_default_verification_model_name()
if model_name:
data['model'] = model_name
@ -742,7 +760,10 @@ class QrVerifyView(BaseView):
t = threading.Thread(target=oss_put, args=(image_name, img_data))
t.run()
if sc.batch.feature_comparison_threshold > 0.01:
# Get model from batch, or fall back to default from global config
model_name = sc.batch.verification_model.name if sc.batch.verification_model else None
if not model_name:
model_name = self.get_default_verification_model_name()
used_model = self.do_v5_qr_verify(imgs, messages, model_name=model_name)
sd.verification_model = used_model if used_model else None
else:

View File

@ -17,6 +17,17 @@
</div>
<button class="my-1 btn btn-primary" @click="save_debug_upload_configs">保存</button>
</div>
<div class="section mb-2">
<h4>默认验证模型配置</h4>
<div>
默认验证模型
<select class="form-control" v-model="default_verification_model_id">
<option value="">使用服务器默认</option>
<option v-for="vm in verification_models" :key="vm.id" :value="vm.id">{{ vm.name }}</option>
</select>
</div>
<button class="my-1 btn btn-primary" @click="save_default_verification_model">保存</button>
</div>
</div>
<div class="fade-in">
<div class="section">
@ -47,6 +58,8 @@ export default {
return {
debug_upload_dir: '',
debug_upload_neg_or_pos: '',
verification_models: [],
default_verification_model_id: '',
};
},
computed: {
@ -58,6 +71,18 @@ export default {
r = await this.$root.api_get("/api/v1/global-config/?name=debug_upload_neg_or_pos");
this.debug_upload_neg_or_pos = r.data.value || '';
// Load verification models
r = await this.$root.api_get_all("/api/v1/verification-model/");
this.verification_models = r;
// Load default verification model
try {
r = await this.$root.api_get("/api/v1/global-config/?name=default_verification_model");
this.default_verification_model_id = r.data.value || '';
} catch (e) {
this.default_verification_model_id = '';
}
},
async save_debug_upload_configs() {
await this.$root.api_post("/api/v1/global-config/", {
@ -71,6 +96,14 @@ export default {
await this.reload();
this.$root.notify("保存成功", "数据采集模式配置已更新");
},
async save_default_verification_model() {
await this.$root.api_post("/api/v1/global-config/", {
name: 'default_verification_model',
value: this.default_verification_model_id || '',
});
await this.reload();
this.$root.notify("保存成功", "默认验证模型配置已更新");
},
},
mounted() {
this.reload();