From 90d23a70b3a636b4599197e84bcd73d59cc9f9ec Mon Sep 17 00:00:00 2001 From: Justin Georgi Date: Mon, 25 Mar 2024 21:03:56 -0700 Subject: [PATCH] Improve model location determination (#148) Vite and cordova properties now automatically determine the path to the models. Reviewed-on: https://gitea.azgeorgis.net/ALVINN/ALVINN_f7/pulls/148 --- src/pages/detect.vue | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/pages/detect.vue b/src/pages/detect.vue index e11076d..3a9468e 100644 --- a/src/pages/detect.vue +++ b/src/pages/detect.vue @@ -163,28 +163,17 @@ return store() }, created () { - var loadOtherSettings = localStorage.getItem('otherSettings') + let loadOtherSettings = localStorage.getItem('otherSettings') if (loadOtherSettings) this.otherSettings = JSON.parse(loadOtherSettings) + let modelRoot = this.isCordova ? 'https://localhost' : (import.meta.env.PROD ? '.' : '..') switch (this.f7route.params.region) { case 'thorax': this.activeRegion = 0 this.detectorName = 'thorax' - /* VITE setting */ - this.modelLocation = `../models/thorax${this.otherSettings.mini ? '-mini' : ''}/model.json` - this.miniLocation = `../models/thorax-mini/model.json` - /* PWA Build setting */ - //this.modelLocation = `./models/thorax${this.otherSettings.mini ? '-mini' : ''}/model.json` - this.modelLocationCordova = `https://localhost/models/thorax${this.otherSettings.mini ? '-mini' : ''}/model.json` break; case 'abdomen': this.activeRegion = 1 this.detectorName = 'abdomen' - /* VITE setting */ - this.modelLocation = `../models/abdomen${this.otherSettings.mini ? '-mini' : ''}/model.json` - this.miniLocation = `../models/abdomen-mini/model.json` - /* PWA Build setting */ - //this.modelLocation = `./models/abdomen${this.otherSettings.mini ? '-mini' : ''}/model.json` - this.modelLocationCordova = `https://localhost/models/abdomen${this.otherSettings.mini ? '-mini' : ''}/model.json` break; case 'limbs': this.activeRegion = 2 @@ -194,6 +183,8 @@ this.activeRegion = 3 break; } + this.modelLocation = `${modelRoot}/models/${this.detectorName}${this.otherSettings.mini ? '-mini' : ''}/model.json` + this.miniLocation = `${modelRoot}/models/${this.detectorName}-mini/model.json` import(`../models/${this.detectorName}/classes.json`).then((mod) => { this.classesList = mod.default this.detectorLabels = this.classesList.map( l => { return {'name': l, 'detect': true} } ) @@ -207,7 +198,7 @@ this.modelLoading = false } else { this.modelLoading = true - this.loadModel(this.isCordova ? this.modelLocationCordova : this.modelLocation, true).then(() => { + this.loadModel(this.modelLocation, true).then(() => { this.modelLoading = false }).catch((e) => { console.log(e.message) @@ -267,7 +258,7 @@ }, async setData () { if (this.reloadModel) { - await this.loadModel(this.isCordova ? this.modelLocationCordova : this.modelLocation) + await this.loadModel(this.modelLocation) this.reloadModel = false } if (this.serverSettings && this.serverSettings.use) {