diff --git a/api/products/views.py b/api/products/views.py index 0e507ea..494d017 100644 --- a/api/products/views.py +++ b/api/products/views.py @@ -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: diff --git a/web/src/views/system-settings.vue b/web/src/views/system-settings.vue index f2760ee..4fc3a24 100644 --- a/web/src/views/system-settings.vue +++ b/web/src/views/system-settings.vue @@ -17,6 +17,17 @@ +
+

默认验证模型配置

+
+ 默认验证模型: + +
+ +
@@ -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();