chore: improve the result in classification closes #34
This commit is contained in:
parent
3f828ab855
commit
f8bc8ad85a
@ -8,6 +8,26 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func handleList(handler *Handle) {
|
func handleList(handler *Handle) {
|
||||||
|
|
||||||
|
handler.PostAuth("/tasks/task", 1, func(c *Context) *Error {
|
||||||
|
var getId JustId
|
||||||
|
if _err := c.ToJSON(&getId); _err != nil {
|
||||||
|
return _err
|
||||||
|
}
|
||||||
|
|
||||||
|
var task Task
|
||||||
|
|
||||||
|
err := GetDBOnce(c, &task, "tasks where id=$1;", getId.Id)
|
||||||
|
if err == NotFoundError {
|
||||||
|
return c.JsonBadRequest("Did not found task id")
|
||||||
|
} else if err != nil {
|
||||||
|
return c.E500M("Faied to get task", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.ShowMessage = false
|
||||||
|
return c.SendJSON(task)
|
||||||
|
})
|
||||||
|
|
||||||
handler.PostAuth("/tasks/list", 1, func(c *Context) *Error {
|
handler.PostAuth("/tasks/list", 1, func(c *Context) *Error {
|
||||||
var err error = nil
|
var err error = nil
|
||||||
|
|
||||||
|
4
main.go
4
main.go
@ -8,10 +8,10 @@ import (
|
|||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
|
|
||||||
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/models"
|
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/models"
|
||||||
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/tasks"
|
|
||||||
models_utils "git.andr3h3nriqu3s.com/andr3/fyp/logic/models/utils"
|
models_utils "git.andr3h3nriqu3s.com/andr3/fyp/logic/models/utils"
|
||||||
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
|
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/tasks"
|
||||||
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/tasks/runner"
|
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/tasks/runner"
|
||||||
|
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
34
webpage/src/lib/Spinner.svelte
Normal file
34
webpage/src/lib/Spinner.svelte
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<svg width="24" height="24" stroke="#000" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<style>
|
||||||
|
.spinner_V8m1 {
|
||||||
|
transform-origin: center;
|
||||||
|
animation: spinner_zKoa 2s linear infinite;
|
||||||
|
}
|
||||||
|
.spinner_V8m1 circle {
|
||||||
|
stroke-linecap: round;
|
||||||
|
animation: spinner_YpZS 1.5s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
@keyframes spinner_zKoa {
|
||||||
|
100% {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@keyframes spinner_YpZS {
|
||||||
|
0% {
|
||||||
|
stroke-dasharray: 0 150;
|
||||||
|
stroke-dashoffset: 0;
|
||||||
|
}
|
||||||
|
47.5% {
|
||||||
|
stroke-dasharray: 42 150;
|
||||||
|
stroke-dashoffset: -16;
|
||||||
|
}
|
||||||
|
95%,
|
||||||
|
100% {
|
||||||
|
stroke-dasharray: 42 150;
|
||||||
|
stroke-dashoffset: -59;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style><g class="spinner_V8m1"
|
||||||
|
><circle cx="12" cy="12" r="9.5" fill="none" stroke-width="3"></circle></g
|
||||||
|
>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 767 B |
@ -1,93 +1,109 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { postFormData } from "src/lib/requests.svelte";
|
import { post, postFormData } from 'src/lib/requests.svelte';
|
||||||
import type { Model } from "./+page.svelte";
|
import type { Model } from './+page.svelte';
|
||||||
import FileUpload from "src/lib/FileUpload.svelte";
|
import FileUpload from 'src/lib/FileUpload.svelte';
|
||||||
import MessageSimple from "src/lib/MessageSimple.svelte";
|
import MessageSimple from 'src/lib/MessageSimple.svelte';
|
||||||
import { createEventDispatcher } from "svelte";
|
import { createEventDispatcher, onDestroy } from 'svelte';
|
||||||
|
import Spinner from 'src/lib/Spinner.svelte';
|
||||||
|
import type { Task } from './TasksTable.svelte';
|
||||||
|
|
||||||
let { model } = $props<{ model: Model }>();
|
let { model } = $props<{ model: Model }>();
|
||||||
|
|
||||||
let file: File | undefined = $state();
|
let file: File | undefined = $state();
|
||||||
|
|
||||||
const dispatch = createEventDispatcher<{ upload: void }>();
|
const dispatch = createEventDispatcher<{ upload: void; taskReload: void }>();
|
||||||
|
|
||||||
type Result = {
|
let _result: Promise<Task> = $state(new Promise(() => {}));
|
||||||
class: string,
|
|
||||||
confidence: number,
|
|
||||||
}
|
|
||||||
|
|
||||||
let _result: Promise<Result | undefined> = $state(new Promise(() => {}));
|
|
||||||
let run = $state(false);
|
let run = $state(false);
|
||||||
|
|
||||||
let last_task: string | undefined = $state();
|
let last_task: string | undefined = $state();
|
||||||
|
let last_task_timeout: number | null = null;
|
||||||
|
|
||||||
let messages: MessageSimple;
|
let messages: MessageSimple;
|
||||||
|
|
||||||
|
async function reloadLastTimeout() {
|
||||||
|
if (!last_task) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
last_task_timeout = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const r = await post('tasks/task', { id: last_task });
|
||||||
|
if ([0, 1, 2, 3].includes(r.status)) {
|
||||||
|
setTimeout(reloadLastTimeout, 500);
|
||||||
|
setTimeout(() => dispatch('taskReload'), 500);
|
||||||
|
} else {
|
||||||
|
_result = Promise.resolve(r);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to get data');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
if (!file) return;
|
if (!file) return;
|
||||||
messages.clear();
|
messages.clear();
|
||||||
|
|
||||||
let form = new FormData();
|
let form = new FormData();
|
||||||
form.append("json_data", JSON.stringify({id: model.id}));
|
form.append('json_data', JSON.stringify({ id: model.id }));
|
||||||
form.append("file", file, "file");
|
form.append('file', file, 'file');
|
||||||
|
|
||||||
run = true;
|
run = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const r = await postFormData('tasks/start/image', form);
|
const r = await postFormData('tasks/start/image', form);
|
||||||
last_task = r.id
|
last_task = r.id;
|
||||||
file = undefined;
|
file = undefined;
|
||||||
|
last_task_timeout = setTimeout(() => reloadLastTimeout());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof Response) {
|
if (e instanceof Response) {
|
||||||
messages.display(await e.json());
|
messages.display(await e.json());
|
||||||
} else {
|
} else {
|
||||||
messages.display("Could not run the model");
|
messages.display('Could not run the model');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch('upload');
|
dispatch('upload');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
if (last_task_timeout) {
|
||||||
|
clearTimeout(last_task_timeout);
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form on:submit|preventDefault={submit}>
|
<form on:submit|preventDefault={submit}>
|
||||||
<fieldset class="file-upload">
|
<fieldset class="file-upload">
|
||||||
<label for="file">Image</label>
|
<label for="file">Image</label>
|
||||||
<div class="form-msg">
|
<div class="form-msg">Run image through them model and get the result</div>
|
||||||
Run image through them model and get the result
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<FileUpload replace_slot bind:file accept="image/*">
|
<FileUpload replace_slot bind:file accept="image/*">
|
||||||
<img src="/imgs/upload-icon.png" alt="" />
|
<img src="/imgs/upload-icon.png" alt="" />
|
||||||
<span>
|
<span> Upload image </span>
|
||||||
Upload image
|
|
||||||
</span>
|
|
||||||
<div slot="replaced-name">
|
<div slot="replaced-name">
|
||||||
<span>
|
<span> Image selected </span>
|
||||||
Image selected
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
</FileUpload>
|
</FileUpload>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<MessageSimple bind:this={messages} />
|
<MessageSimple bind:this={messages} />
|
||||||
<button>
|
<button> Run </button>
|
||||||
Run
|
|
||||||
</button>
|
|
||||||
{#if run}
|
{#if run}
|
||||||
{#await _result}
|
{#await _result}
|
||||||
<h1>
|
<h1>
|
||||||
Processing Image {last_task}
|
Processing Image! <Spinner />
|
||||||
</h1>
|
</h1>
|
||||||
{:then result}
|
{:then result}
|
||||||
{#if !result}
|
{#if result.status == 4}
|
||||||
<div class="result">
|
{@const res = JSON.parse(result.result)}
|
||||||
<h1>
|
<div>
|
||||||
The class was not found
|
<h1>Result</h1>
|
||||||
</h1>
|
The image was classified as {res.class} with confidence: {res.confidence}
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<div>
|
<div class="result">
|
||||||
<h1>
|
<h1>There was a problem running the task:</h1>
|
||||||
Result
|
{result?.status_message}
|
||||||
</h1>
|
|
||||||
The image was classified as {result.class} with confidence: {result.confidence}
|
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{/await}
|
{/await}
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { post } from "src/lib/requests.svelte";
|
import { post } from 'src/lib/requests.svelte';
|
||||||
import type { Model } from "src/routes/models/edit/+page.svelte";
|
import type { Model } from 'src/routes/models/edit/+page.svelte';
|
||||||
import RunModel from "./RunModel.svelte";
|
import RunModel from './RunModel.svelte';
|
||||||
import TasksTable from "./TasksTable.svelte";
|
import TasksTable from './TasksTable.svelte';
|
||||||
|
|
||||||
const { active, model } = $props<{ active?: boolean, model: Model }>();
|
const { active, model } = $props<{ active?: boolean; model: Model }>();
|
||||||
|
|
||||||
let table: TasksTable;
|
let table: TasksTable;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
<div class="content" class:selected={active}>
|
<div class="content" class:selected={active}>
|
||||||
<RunModel model={model} on:upload={() => table.getList()} />
|
<RunModel {model} on:upload={() => table.getList()} on:taskReload={() => table.getList()} />
|
||||||
<TasksTable model={model} bind:this={table} />
|
<TasksTable {model} bind:this={table} />
|
||||||
</div>
|
</div>
|
||||||
|
@ -11,13 +11,31 @@
|
|||||||
created: string;
|
created: string;
|
||||||
result: string;
|
result: string;
|
||||||
};
|
};
|
||||||
|
export const TaskType = {
|
||||||
|
TASK_FAILED_RUNNING: -2,
|
||||||
|
TASK_FAILED_CREATION: -1,
|
||||||
|
TASK_PREPARING: 0,
|
||||||
|
TASK_TODO: 1,
|
||||||
|
TASK_PICKED_UP: 2,
|
||||||
|
TASK_RUNNING: 3,
|
||||||
|
TASK_DONE: 4
|
||||||
|
};
|
||||||
|
export const TaskTypeStrings: Record<number, string> = {
|
||||||
|
[-2]: 'Task failed running',
|
||||||
|
[-1]: 'Failed to create task',
|
||||||
|
0: 'Preparing task',
|
||||||
|
1: 'Task to do',
|
||||||
|
2: 'Task picked up by a runner',
|
||||||
|
3: 'Task running',
|
||||||
|
4: 'Task complete'
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { post } from 'src/lib/requests.svelte';
|
import { post } from 'src/lib/requests.svelte';
|
||||||
import type { Model } from './+page.svelte';
|
import type { Model } from './+page.svelte';
|
||||||
|
|
||||||
let { model } = $props<{ model: Model, uploadCounter?: number }>();
|
let { model } = $props<{ model: Model; uploadCounter?: number }>();
|
||||||
|
|
||||||
let page = $state(0);
|
let page = $state(0);
|
||||||
let showNext = $state(false);
|
let showNext = $state(false);
|
||||||
@ -27,7 +45,7 @@
|
|||||||
try {
|
try {
|
||||||
const res = await post('tasks/list', {
|
const res = await post('tasks/list', {
|
||||||
id: model.id,
|
id: model.id,
|
||||||
page: page,
|
page: page
|
||||||
});
|
});
|
||||||
showNext = res.show_next;
|
showNext = res.show_next;
|
||||||
task_list = res.task_list;
|
task_list = res.task_list;
|
||||||
@ -38,9 +56,9 @@
|
|||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (model) {
|
if (model) {
|
||||||
getList()
|
getList();
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
@ -112,13 +130,13 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{task.status}
|
{TaskTypeStrings[task.status]}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{task.status_message}
|
{task.status_message}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{(new Date(task.created)).toLocaleString()}
|
{new Date(task.created).toLocaleString()}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/each}
|
{/each}
|
||||||
|
Loading…
Reference in New Issue
Block a user