From 0c0d16c846d882ae1eea916e413779778d6bb272 Mon Sep 17 00:00:00 2001 From: Andre Henriques Date: Sat, 11 May 2024 01:11:07 +0100 Subject: [PATCH] multiple fixes --- logic/models/data.go | 9 +- logic/models/run.go | 4 +- logic/models/train/train.go | 6 - webpage/.eslintrc.cjs | 8 +- webpage/src/lib/FileUpload.svelte | 4 +- webpage/src/lib/MessageSimple.svelte | 57 ------ webpage/src/lib/Tooltip.svelte | 10 +- webpage/src/lib/utils.ts | 6 + webpage/src/routes/admin/runners/+page.svelte | 2 +- webpage/src/routes/login/+page.svelte | 3 +- webpage/src/routes/models/+page.svelte | 7 - webpage/src/routes/models/add/+page.svelte | 3 +- webpage/src/routes/models/edit/+page.svelte | 43 ++--- .../routes/models/edit/BaseModelInfo.svelte | 2 +- .../src/routes/models/edit/DeleteModel.svelte | 18 +- .../src/routes/models/edit/DeleteZip.svelte | 33 ++-- .../src/routes/models/edit/ModelData.svelte | 76 +++----- .../routes/models/edit/ModelDataPage.svelte | 15 +- .../edit/ModelDataPageStatsGraph.svelte | 2 +- .../src/routes/models/edit/ModelTable.svelte | 99 +++++------ .../src/routes/models/edit/RunModel.svelte | 24 +-- .../routes/models/edit/TasksDataPage.svelte | 3 +- .../src/routes/models/edit/TrainModel.svelte | 44 ++--- .../models/edit/api/CreateNewClass.svelte | 27 +++ .../src/routes/models/edit/tasks/Stats.svelte | 3 +- .../models/edit/tasks/TasksTable.svelte | 15 +- webpage/src/routes/models/edit/types.ts | 13 ++ webpage/src/routes/register/+page.svelte | 3 +- webpage/src/routes/user/info/+page.svelte | 41 ++--- webpage/src/routes/user/info/AddToken.svelte | 167 +++++++++--------- .../src/routes/user/info/DeleteUser.svelte | 3 +- .../src/routes/user/info/TokenTable.svelte | 26 +-- webpage/src/styles/app.css | 10 ++ webpage/svelte.config.js | 8 +- 34 files changed, 340 insertions(+), 454 deletions(-) delete mode 100644 webpage/src/lib/MessageSimple.svelte create mode 100644 webpage/src/lib/utils.ts create mode 100644 webpage/src/routes/models/edit/api/CreateNewClass.svelte diff --git a/logic/models/data.go b/logic/models/data.go index 1e6a89c..cebdeab 100644 --- a/logic/models/data.go +++ b/logic/models/data.go @@ -136,17 +136,16 @@ func processZipFile(c *Context, model *BaseModel) { return } - if paths[0] != "training" { + if paths[0] == "training" { training = InsertIfNotPresent(training, paths[1]) - } else if paths[0] != "testing" { + } else if paths[0] == "testing" { testing = InsertIfNotPresent(testing, paths[1]) } } if !reflect.DeepEqual(testing, training) { - c.Logger.Info("Diff", "testing", testing, "training", training) - failed("Testing and Training datesets are diferent") - return + c.Logger.Warn("Diff", "testing", testing, "training", training) + c.Logger.Warn("Testing and traing datasets differ") } base_path := path.Join("savedData", model.Id, "data") diff --git a/logic/models/run.go b/logic/models/run.go index d6c1954..ee2aec0 100644 --- a/logic/models/run.go +++ b/logic/models/run.go @@ -37,7 +37,7 @@ func ReadJPG(scope *op.Scope, imagePath string, channels int64) *image.Image { return image.Scale(0, 255) } -func runModelNormal(base BasePack, model *BaseModel, def_id string, inputImage *tf.Tensor) (order int, confidence float32, err error) { +func runModelNormal(model *BaseModel, def_id string, inputImage *tf.Tensor) (order int, confidence float32, err error) { order = 0 err = nil @@ -193,7 +193,7 @@ func ClassifyTask(base BasePack, task Task) (err error) { } } else { base.GetLogger().Info("Running model normal", "model", model.Id, "def", def_id) - vi, confidence, err = runModelNormal(base, model, def_id, inputImage) + vi, confidence, err = runModelNormal(model, def_id, inputImage) if err != nil { task.UpdateStatusLog(base, TASK_FAILED_RUNNING, "Failed to run model") return diff --git a/logic/models/train/train.go b/logic/models/train/train.go index e45553a..c8b7162 100644 --- a/logic/models/train/train.go +++ b/logic/models/train/train.go @@ -1298,12 +1298,6 @@ func generateExpandableDefinition(c BasePack, model *BaseModel, target_accuracy order++ - // handle the errors inside the pervious if block - if err != nil { - failed() - return - } - // Create the blocks loop := int((math.Log(float64(model.Width)) / math.Log(float64(10)))) diff --git a/webpage/.eslintrc.cjs b/webpage/.eslintrc.cjs index 0b75758..6763c53 100644 --- a/webpage/.eslintrc.cjs +++ b/webpage/.eslintrc.cjs @@ -27,5 +27,11 @@ module.exports = { parser: '@typescript-eslint/parser' } } - ] + ], + rules: { + 'svelte/no-at-html-tags': 'off', + + // TODO remove this + '@typescript-eslint/no-explicit-any': 'off' + } }; diff --git a/webpage/src/lib/FileUpload.svelte b/webpage/src/lib/FileUpload.svelte index 70967b3..d3e27e6 100644 --- a/webpage/src/lib/FileUpload.svelte +++ b/webpage/src/lib/FileUpload.svelte @@ -36,7 +36,7 @@ class="icon" class:adapt={replace_slot && file && !notExpand} type="button" - on:click={() => fileInput.click()} + onclick={() => fileInput.click()} > {#if replace_slot && file} @@ -54,6 +54,6 @@ required {accept} bind:this={fileInput} - on:change={onChange} + onchange={onChange} /> diff --git a/webpage/src/lib/MessageSimple.svelte b/webpage/src/lib/MessageSimple.svelte deleted file mode 100644 index 16602db..0000000 --- a/webpage/src/lib/MessageSimple.svelte +++ /dev/null @@ -1,57 +0,0 @@ - - - - -{#if message} -
- {message} -
-{/if} diff --git a/webpage/src/lib/Tooltip.svelte b/webpage/src/lib/Tooltip.svelte index a32084c..7e8e480 100644 --- a/webpage/src/lib/Tooltip.svelte +++ b/webpage/src/lib/Tooltip.svelte @@ -1,5 +1,5 @@
diff --git a/webpage/src/routes/models/edit/DeleteModel.svelte b/webpage/src/routes/models/edit/DeleteModel.svelte index 01e0bcd..b89b674 100644 --- a/webpage/src/routes/models/edit/DeleteModel.svelte +++ b/webpage/src/routes/models/edit/DeleteModel.svelte @@ -1,39 +1,31 @@ -
+
- diff --git a/webpage/src/routes/models/edit/DeleteZip.svelte b/webpage/src/routes/models/edit/DeleteZip.svelte index 119d62f..41aada7 100644 --- a/webpage/src/routes/models/edit/DeleteZip.svelte +++ b/webpage/src/routes/models/edit/DeleteZip.svelte @@ -1,32 +1,30 @@ -
+ {#if expand} Failed to proccess the zip file.
Delete file and upload a correct version do add more classes.
@@ -37,6 +35,5 @@
{/if}
- diff --git a/webpage/src/routes/models/edit/ModelData.svelte b/webpage/src/routes/models/edit/ModelData.svelte index bc1a7d0..3210058 100644 --- a/webpage/src/routes/models/edit/ModelData.svelte +++ b/webpage/src/routes/models/edit/ModelData.svelte @@ -1,38 +1,29 @@ - - @@ -80,22 +67,22 @@

You need to upload data so the model can train.

- -
-
+
@@ -115,7 +102,6 @@
- {#if file} {#await uploading} @@ -126,7 +112,7 @@
- dispatch('reload')} /> +
TODO
@@ -139,33 +125,11 @@ These images will be delete when the model trains.

{/if} - -
- - -
-
- dispatch('reload')} /> -
-
TODO
-
+ {/if}
{/if} {#if classes.some((item) => item.status == 1) && ![-6, 6].includes(model.status)} - dispatch('reload')} - /> + {/if} diff --git a/webpage/src/routes/models/edit/ModelDataPage.svelte b/webpage/src/routes/models/edit/ModelDataPage.svelte index 6bfb64c..7102cad 100644 --- a/webpage/src/routes/models/edit/ModelDataPage.svelte +++ b/webpage/src/routes/models/edit/ModelDataPage.svelte @@ -1,5 +1,4 @@ -
+
diff --git a/webpage/src/routes/models/edit/RunModel.svelte b/webpage/src/routes/models/edit/RunModel.svelte index 73b648d..787a882 100644 --- a/webpage/src/routes/models/edit/RunModel.svelte +++ b/webpage/src/routes/models/edit/RunModel.svelte @@ -2,20 +2,22 @@ import { post, postFormData, showMessage } from 'src/lib/requests.svelte'; import type { Model } from './+page.svelte'; import FileUpload from 'src/lib/FileUpload.svelte'; - import MessageSimple from 'src/lib/MessageSimple.svelte'; - import { createEventDispatcher, onDestroy } from 'svelte'; + import { onDestroy } from 'svelte'; import Spinner from 'src/lib/Spinner.svelte'; - import type { Task } from './tasks/TasksTable.svelte'; + import type { Task } from './tasks/types'; import Tabs from 'src/lib/Tabs.svelte'; import hljs from 'highlight.js'; import { notificationStore } from 'src/lib/NotificationsStore.svelte'; + import { preventDefault } from 'src/lib/utils'; - let { model } = $props<{ model: Model }>(); + let { + model, + onupload = () => {}, + ontaskReload = () => {} + }: { model: Model; onupload?: () => void; ontaskReload?: () => void } = $props(); let file: File | undefined = $state(); - const dispatch = createEventDispatcher<{ upload: void; taskReload: void }>(); - let _result: Promise = $state(new Promise(() => {})); let run = $state(false); @@ -32,7 +34,7 @@ const r = await post('tasks/task', { id: last_task }); if ([0, 1, 2, 3].includes(r.status)) { setTimeout(reloadLastTimeout, 500); - setTimeout(() => dispatch('taskReload'), 500); + setTimeout(ontaskReload, 500); } else { _result = Promise.resolve(r); } @@ -59,7 +61,7 @@ showMessage(e, notificationStore, 'Could not run the model'); } - dispatch('upload'); + onupload(); } onDestroy(() => { @@ -71,10 +73,10 @@
- - +
@@ -134,7 +136,7 @@ const r = await fetch('${window.location.protocol}//${window.location.hostname}/
-
+
Run image through them model and get the result
diff --git a/webpage/src/routes/models/edit/TasksDataPage.svelte b/webpage/src/routes/models/edit/TasksDataPage.svelte index 204abc6..66ce925 100644 --- a/webpage/src/routes/models/edit/TasksDataPage.svelte +++ b/webpage/src/routes/models/edit/TasksDataPage.svelte @@ -1,5 +1,4 @@ {#if model.status == 2} - + {#if has_data} {#if number_of_invalid_images > 0}

@@ -65,7 +57,6 @@ These images will be delete when the model trains.

{/if} -
Model Type @@ -111,7 +102,7 @@ {/if} {:else} -
+ {#if has_data}

This model has new classes and can be expanded

{#if number_of_invalid_images > 0} @@ -120,7 +111,6 @@ These images will be delete when the model trains.

{/if} - {:else}

To train the model please provide data to the model first

diff --git a/webpage/src/routes/models/edit/api/CreateNewClass.svelte b/webpage/src/routes/models/edit/api/CreateNewClass.svelte new file mode 100644 index 0000000..21c9481 --- /dev/null +++ b/webpage/src/routes/models/edit/api/CreateNewClass.svelte @@ -0,0 +1,27 @@ + + +To create a new class via the API you can: +
{@html hljs.highlight(
+		`let form = new FormData();
+form.append('json_data', JSON.stringify({
+	id: '${model.id}',
+	name: 'New class name'
+}));
+form.append('file', file, 'file');
+
+const headers = new Headers();
+headers.append('response-type', 'application/json');
+headers.append('token', token);
+
+const r = await fetch('${window.location.protocol}//${window.location.hostname}/models/data/class/new', {
+	method: 'POST',
+	headers: headers,
+	body: form
+});`,
+		{ language: 'javascript' }
+	).value}
diff --git a/webpage/src/routes/models/edit/tasks/Stats.svelte b/webpage/src/routes/models/edit/tasks/Stats.svelte index 98055c6..7479c57 100644 --- a/webpage/src/routes/models/edit/tasks/Stats.svelte +++ b/webpage/src/routes/models/edit/tasks/Stats.svelte @@ -1,5 +1,5 @@ @@ -80,15 +77,14 @@