From bb8d121991b48ee04ddee2f303d8f4fd0209f1cf Mon Sep 17 00:00:00 2001 From: josc146 Date: Fri, 19 May 2023 10:08:28 +0800 Subject: [PATCH] update --- frontend/src/_locales/zh-hans/main.json | 5 ++- frontend/src/components/ConfigSelector.tsx | 18 ++++++++ frontend/src/components/RunButton.tsx | 42 ++++++++++++++----- frontend/src/components/ToolTipButton.tsx | 11 ++++- frontend/src/pages/Chat.tsx | 49 ++++++++++++++++++---- frontend/src/pages/Home.tsx | 16 ++----- frontend/src/pages/Models.tsx | 2 +- 7 files changed, 107 insertions(+), 36 deletions(-) create mode 100644 frontend/src/components/ConfigSelector.tsx diff --git a/frontend/src/_locales/zh-hans/main.json b/frontend/src/_locales/zh-hans/main.json index 94188cc..b20c438 100644 --- a/frontend/src/_locales/zh-hans/main.json +++ b/frontend/src/_locales/zh-hans/main.json @@ -7,8 +7,10 @@ "Manage your configs": "管理你的配置", "Manage models": "管理模型", "Run": "运行", + "Offline": "离线", "Starting": "启动中", "Loading": "读取模型中", + "Working": "运行中", "Stop": "停止", "Enable High Precision For Last Layer": "输出层使用高精度", "Stored Layers": "载入显存层数", @@ -60,5 +62,6 @@ "Start Converting": "开始转换", "Convert Success": "转换成功", "Convert Failed": "转换失败", - "Model Not Found": "模型不存在" + "Model Not Found": "模型不存在", + "Model Status": "模型状态" } \ No newline at end of file diff --git a/frontend/src/components/ConfigSelector.tsx b/frontend/src/components/ConfigSelector.tsx new file mode 100644 index 0000000..b916ad5 --- /dev/null +++ b/frontend/src/components/ConfigSelector.tsx @@ -0,0 +1,18 @@ +import {FC} from 'react'; +import {observer} from 'mobx-react-lite'; +import {Dropdown, Option} from '@fluentui/react-components'; +import commonStore from '../stores/commonStore'; + +export const ConfigSelector: FC<{ size?: 'small' | 'medium' | 'large' }> = observer(({size}) => { + return { + if (data.optionValue) + commonStore.setCurrentConfigIndex(Number(data.optionValue)); + }}> + {commonStore.modelConfigs.map((config, index) => + + )} + ; +}); \ No newline at end of file diff --git a/frontend/src/components/RunButton.tsx b/frontend/src/components/RunButton.tsx index b601d07..63bfdef 100644 --- a/frontend/src/components/RunButton.tsx +++ b/frontend/src/components/RunButton.tsx @@ -1,4 +1,4 @@ -import React, {FC, MouseEventHandler} from 'react'; +import React, {FC, MouseEventHandler, ReactElement} from 'react'; import commonStore, {ModelStatus} from '../stores/commonStore'; import {StartServer} from '../../wailsjs/go/backend_golang/App'; import {Button} from '@fluentui/react-components'; @@ -9,6 +9,8 @@ import manifest from '../../../manifest.json'; import {getStrategy} from '../utils'; import {useTranslation} from 'react-i18next'; import {t} from 'i18next'; +import {ToolTipButton} from './ToolTipButton'; +import {Play16Regular, Stop16Regular} from '@fluentui/react-icons'; const mainButtonText = { [ModelStatus.Offline]: 'Run', @@ -17,6 +19,13 @@ const mainButtonText = { [ModelStatus.Working]: 'Stop' }; +const iconModeButtonIcon: { [modelStatus: number]: ReactElement } = { + [ModelStatus.Offline]: , + [ModelStatus.Starting]: , + [ModelStatus.Loading]: , + [ModelStatus.Working]: +}; + const onClickMainButton = async () => { const modelConfig = commonStore.getCurrentModelConfig(); const port = modelConfig.apiParameters.apiPort; @@ -74,17 +83,28 @@ const onClickMainButton = async () => { } }; -export const RunButton: FC<{ onClickRun?: MouseEventHandler }> = observer(({onClickRun}) => { +export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean }> + = observer(({ + onClickRun, + iconMode + }) => { const {t} = useTranslation(); - return ( - + const onClick = async (e: any) => { + if (commonStore.modelStatus === ModelStatus.Offline) + await onClickRun?.(e); + await onClickMainButton(); + }; + + return (iconMode ? + + : + ); }); diff --git a/frontend/src/components/ToolTipButton.tsx b/frontend/src/components/ToolTipButton.tsx index 993ed46..ef00322 100644 --- a/frontend/src/components/ToolTipButton.tsx +++ b/frontend/src/components/ToolTipButton.tsx @@ -2,16 +2,23 @@ import React, {FC, MouseEventHandler, ReactElement} from 'react'; import {Button, Tooltip} from '@fluentui/react-components'; export const ToolTipButton: FC<{ - text?: string | null, desc: string, icon?: ReactElement, onClick?: MouseEventHandler + text?: string | null, + desc: string, + icon?: ReactElement, + size?: 'small' | 'medium' | 'large', + disabled?: boolean, + onClick?: MouseEventHandler }> = ({ text, desc, icon, + size, + disabled, onClick }) => { return ( - + ); }; diff --git a/frontend/src/pages/Chat.tsx b/frontend/src/pages/Chat.tsx index e64caa3..4e85c9d 100644 --- a/frontend/src/pages/Chat.tsx +++ b/frontend/src/pages/Chat.tsx @@ -1,16 +1,49 @@ import React, {FC} from 'react'; -import {Page} from '../components/Page'; -import {PresenceBadge} from '@fluentui/react-components'; import {useTranslation} from 'react-i18next'; +import {RunButton} from '../components/RunButton'; +import {Divider, PresenceBadge, Text} from '@fluentui/react-components'; +import commonStore, {ModelStatus} from '../stores/commonStore'; +import {observer} from 'mobx-react-lite'; +import {PresenceBadgeStatus} from '@fluentui/react-badge'; +import {ConfigSelector} from '../components/ConfigSelector'; -export const Chat: FC = () => { +const ChatPanel: FC = () => { + return ( +
+ ); +}; + +const statusText = { + [ModelStatus.Offline]: 'Offline', + [ModelStatus.Starting]: 'Starting', + [ModelStatus.Loading]: 'Loading', + [ModelStatus.Working]: 'Working' +}; + +const badgeStatus: { [modelStatus: number]: PresenceBadgeStatus } = { + [ModelStatus.Offline]: 'unknown', + [ModelStatus.Starting]: 'away', + [ModelStatus.Loading]: 'away', + [ModelStatus.Working]: 'available' +}; + +export const Chat: FC = observer(() => { const {t} = useTranslation(); return ( - - +
+
+
+ + {t('Model Status') + ': ' + t(statusText[commonStore.modelStatus])} +
+
+ + +
- }/> + + +
); -}; +}); diff --git a/frontend/src/pages/Home.tsx b/frontend/src/pages/Home.tsx index f9f0489..44705e3 100644 --- a/frontend/src/pages/Home.tsx +++ b/frontend/src/pages/Home.tsx @@ -1,4 +1,4 @@ -import {CompoundButton, Dropdown, Link, Option, Text} from '@fluentui/react-components'; +import {CompoundButton, Link, Text} from '@fluentui/react-components'; import React, {FC, ReactElement} from 'react'; import banner from '../assets/images/banner.jpg'; import { @@ -8,12 +8,12 @@ import { Storage20Regular } from '@fluentui/react-icons'; import {useNavigate} from 'react-router'; -import commonStore from '../stores/commonStore'; import {observer} from 'mobx-react-lite'; import {RunButton} from '../components/RunButton'; import manifest from '../../../manifest.json'; import {BrowserOpenURL} from '../../wailsjs/runtime'; import {useTranslation} from 'react-i18next'; +import {ConfigSelector} from '../components/ConfigSelector'; type NavCard = { label: string; @@ -78,17 +78,7 @@ export const Home: FC = observer(() => {
- { - if (data.optionValue) - commonStore.setCurrentConfigIndex(Number(data.optionValue)); - }}> - {commonStore.modelConfigs.map((config, index) => - - )} - +
diff --git a/frontend/src/pages/Models.tsx b/frontend/src/pages/Models.tsx index 210b411..d1b6ff0 100644 --- a/frontend/src/pages/Models.tsx +++ b/frontend/src/pages/Models.tsx @@ -149,7 +149,7 @@ export const Models: FC = observer(() => {
-
+
{t('Model Source Manifest List')} } onClick={() => { refreshModels(false);