From 3101be8b789fd8c9952c958b7a5308143ed99c07 Mon Sep 17 00:00:00 2001 From: Sean Sube Date: Mon, 8 Jan 2024 21:03:48 -0600 Subject: [PATCH] feat: add motd to server config, show in web UI --- api/onnx_web/worker/command.py | 3 --- api/params.json | 6 ++++++ gui/src/Motd.tsx | 30 ++++++++++++++++++++++++++++++ gui/src/components/OnnxWeb.tsx | 12 +++++++++--- gui/src/config.json | 6 ++++++ gui/src/config.ts | 1 + gui/src/main.tsx | 11 +++++++++-- 7 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 gui/src/Motd.tsx diff --git a/api/onnx_web/worker/command.py b/api/onnx_web/worker/command.py index 698bad22..70ac11ad 100644 --- a/api/onnx_web/worker/command.py +++ b/api/onnx_web/worker/command.py @@ -36,9 +36,6 @@ class Progress: self.current = current self.total = total - def __repr__(self) -> str: - return "Progress(%d, %d)" % (self.current, self.total) - def __str__(self) -> str: return "%s/%s" % (self.current, self.total) diff --git a/api/params.json b/api/params.json index 7f7d5e76..7dc18e02 100644 --- a/api/params.json +++ b/api/params.json @@ -1,5 +1,11 @@ { "version": "0.12.0", + "motd": { + "de": "Willkommen bei onnx-web!", + "en": "Welcome to onnx-web!", + "es": "Bienvenido a onnx-web!", + "fr": "Bienvenue sur onnx-web!" + }, "batch": { "default": 1, "min": 1, diff --git a/gui/src/Motd.tsx b/gui/src/Motd.tsx new file mode 100644 index 00000000..f0feb728 --- /dev/null +++ b/gui/src/Motd.tsx @@ -0,0 +1,30 @@ +import React, { useState } from 'react'; +import { Alert, Collapse, IconButton } from '@mui/material'; +import { Close } from '@mui/icons-material'; +import { useTranslation } from 'react-i18next'; + +export function Motd() { + const [open, setOpen] = useState(true); + const { t } = useTranslation(); + + return + { + setOpen(false); + }} + > + + + } + severity='info' + sx={{ mb: 2 }} + > + {t('motd')} + + ; +} diff --git a/gui/src/components/OnnxWeb.tsx b/gui/src/components/OnnxWeb.tsx index 69c2db20..a593b002 100644 --- a/gui/src/components/OnnxWeb.tsx +++ b/gui/src/components/OnnxWeb.tsx @@ -1,7 +1,7 @@ import { mustExist } from '@apextoaster/js-utils'; import { TabContext, TabList, TabPanel } from '@mui/lab'; import { Box, Container, CssBaseline, Divider, Tab, useMediaQuery } from '@mui/material'; -import { createTheme, ThemeProvider } from '@mui/material/styles'; +import { ThemeProvider, createTheme } from '@mui/material/styles'; import * as React from 'react'; import { useContext, useMemo } from 'react'; import { useHash } from 'react-use/lib/useHash'; @@ -17,9 +17,14 @@ import { Models } from './tab/Models.js'; import { Settings } from './tab/Settings.js'; import { Txt2Img } from './tab/Txt2Img.js'; import { Upscale } from './tab/Upscale.js'; -import { getTab, getTheme, TAB_LABELS } from './utils.js'; +import { TAB_LABELS, getTab, getTheme } from './utils.js'; +import { Motd } from '../Motd.js'; -export function OnnxWeb() { +export interface OnnxWebProps { + motd: boolean; +} + +export function OnnxWeb(props: OnnxWebProps) { /* checks for system light/dark mode preference */ const prefersDarkMode = useMediaQuery('(prefers-color-scheme: dark)'); const store = mustExist(useContext(StateContext)); @@ -43,6 +48,7 @@ export function OnnxWeb() { + {props.motd && } { diff --git a/gui/src/config.json b/gui/src/config.json index 6306150f..c567a3e2 100644 --- a/gui/src/config.json +++ b/gui/src/config.json @@ -4,6 +4,12 @@ }, "params": { "version": "0.12.0", + "motd": { + "de": "Willkommen bei onnx-web!", + "en": "Welcome to onnx-web!", + "es": "Bienvenido a onnx-web!", + "fr": "Bienvenue sur onnx-web!" + }, "batch": { "default": 1, "min": 1, diff --git a/gui/src/config.ts b/gui/src/config.ts index 08b3ebe8..514e72af 100644 --- a/gui/src/config.ts +++ b/gui/src/config.ts @@ -71,6 +71,7 @@ export type ServerParams = ConfigRanges> & { + motd?: Record; version: string; }; /* eslint-enable */ diff --git a/gui/src/main.tsx b/gui/src/main.tsx index 81aeecf0..8d367782 100644 --- a/gui/src/main.tsx +++ b/gui/src/main.tsx @@ -1,4 +1,4 @@ -import { mustDefault, mustExist, timeout, TimeoutError } from '@apextoaster/js-utils'; +import { doesExist, mustDefault, mustExist, timeout, TimeoutError } from '@apextoaster/js-utils'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { createLogger, Logger } from 'browser-bunyan'; import i18n from 'i18next'; @@ -46,6 +46,13 @@ export async function renderApp(config: Config, params: ServerParams, logger: Lo } } + if (doesExist(params.motd)) { + logger.debug({ motd: params.motd }, 'adding server motd strings'); + for (const [lang, message] of Object.entries(params.motd)) { + i18n.addResource(lang, 'translation', 'motd', message); + } + } + // prep zustand with a slice for each tab, using local storage const { createDefaultSlice, @@ -116,7 +123,7 @@ export async function renderApp(config: Config, params: ServerParams, logger: Lo - +