2023-01-05 19:42:52 +00:00
|
|
|
/* eslint-disable no-console */
|
2023-01-05 03:55:25 +00:00
|
|
|
import { mustExist } from '@apextoaster/js-utils';
|
|
|
|
import * as React from 'react';
|
|
|
|
import ReactDOM from 'react-dom/client';
|
|
|
|
|
2023-01-05 19:42:52 +00:00
|
|
|
import { makeClient, STATUS_SUCCESS } from './api/client.js';
|
2023-01-05 16:39:46 +00:00
|
|
|
import { OnnxWeb } from './components/OnnxWeb.js';
|
|
|
|
|
|
|
|
export interface Config {
|
|
|
|
api: {
|
|
|
|
root: string;
|
2023-01-05 19:42:52 +00:00
|
|
|
};
|
2023-01-05 16:39:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function loadConfig() {
|
|
|
|
const configPath = new URL('./config.json', window.origin);
|
|
|
|
const configReq = await fetch(configPath);
|
2023-01-05 19:42:52 +00:00
|
|
|
if (configReq.status === STATUS_SUCCESS) {
|
2023-01-05 16:39:46 +00:00
|
|
|
return configReq.json();
|
|
|
|
} else {
|
|
|
|
throw new Error('could not load config');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function main() {
|
|
|
|
const config = await loadConfig();
|
|
|
|
|
2023-01-05 03:55:25 +00:00
|
|
|
const appElement = mustExist(document.getElementById('app'));
|
|
|
|
const app = ReactDOM.createRoot(appElement);
|
2023-01-05 16:39:46 +00:00
|
|
|
const client = makeClient(config.api.root);
|
2023-01-05 04:54:31 +00:00
|
|
|
app.render(<OnnxWeb client={client} />);
|
2023-01-05 03:55:25 +00:00
|
|
|
}
|
|
|
|
|
2023-01-05 16:39:46 +00:00
|
|
|
window.addEventListener('load', () => {
|
|
|
|
console.log('launching onnx-web');
|
2023-01-05 19:42:52 +00:00
|
|
|
main().catch((err) => {
|
|
|
|
console.error('error in main', err);
|
|
|
|
});
|
2023-01-05 16:39:46 +00:00
|
|
|
}, false);
|