chore: video test code
This commit is contained in:
+4
-4
@@ -79,10 +79,10 @@ export default [
|
|||||||
title: 'Video',
|
title: 'Video',
|
||||||
path: '/playground/video',
|
path: '/playground/video',
|
||||||
key: 'video',
|
key: 'video',
|
||||||
icon: 'icon-video',
|
icon: 'icon-video-outline',
|
||||||
hideInMenu: true,
|
hideInMenu: false,
|
||||||
selectedIcon: 'icon-video-filled',
|
selectedIcon: 'icon-video-filled02',
|
||||||
defaultIcon: 'icon-video',
|
defaultIcon: 'icon-video-outline',
|
||||||
component: './playground/video'
|
component: './playground/video'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { createFromIconfontCN } from '@ant-design/icons';
|
|||||||
// import './iconfont/iconfont.js';
|
// import './iconfont/iconfont.js';
|
||||||
|
|
||||||
const IconFont = createFromIconfontCN({
|
const IconFont = createFromIconfontCN({
|
||||||
scriptUrl: '//at.alicdn.com/t/c/font_4613488_h1excejg8p8.js'
|
scriptUrl: '//at.alicdn.com/t/c/font_4613488_xson4g41d39.js'
|
||||||
});
|
});
|
||||||
|
|
||||||
export default IconFont;
|
export default IconFont;
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
.logs-wrap {
|
.logs-wrap {
|
||||||
background-color: var(--color-logs-bg);
|
background-color: var(--color-logs-bg);
|
||||||
border-radius: var(--border-radius-mini);
|
border-radius: var(--border-radius-mini);
|
||||||
font-family: monospace, Menlo, Courier, 'Courier New', Consolas, Monaco,
|
font-family:
|
||||||
|
monospace, Menlo, Courier, 'Courier New', Consolas, Monaco,
|
||||||
'Liberation Mono' !important;
|
'Liberation Mono' !important;
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
@@ -35,7 +36,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
color: var(--color-logs-text);
|
color: var(--color-logs-text);
|
||||||
font-size: var(--font-size-small);
|
font-size: 12px;
|
||||||
line-height: 22px;
|
line-height: 22px;
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
background-color: var(--color-logs-bg);
|
background-color: var(--color-logs-bg);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 2px 10px;
|
padding-inline: 7px;
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
min-width: 76px;
|
min-width: 76px;
|
||||||
width: max-content;
|
width: max-content;
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
height: 20px;
|
height: 20px;
|
||||||
gap: 5px;
|
gap: 4px;
|
||||||
|
|
||||||
&.err {
|
&.err {
|
||||||
cursor: default;
|
cursor: default;
|
||||||
|
|||||||
@@ -212,6 +212,7 @@ body {
|
|||||||
// set for the non-form item
|
// set for the non-form item
|
||||||
.ant-input-outlined,
|
.ant-input-outlined,
|
||||||
.ant-input-affix-wrapper,
|
.ant-input-affix-wrapper,
|
||||||
|
.ant-select,
|
||||||
.ant-picker {
|
.ant-picker {
|
||||||
height: 40px;
|
height: 40px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,5 +161,6 @@ export default {
|
|||||||
'playground.uploadImage.url.invalid':
|
'playground.uploadImage.url.invalid':
|
||||||
'Please enter a direct image URL (e.g. https://.../image.png). Press ESC to cancel.',
|
'Please enter a direct image URL (e.g. https://.../image.png). Press ESC to cancel.',
|
||||||
'playground.uploadImage.url.holder': 'Enter an image URL',
|
'playground.uploadImage.url.holder': 'Enter an image URL',
|
||||||
'playground.uploadImage.url.button': 'Add Image from URL'
|
'playground.uploadImage.url.button': 'Add Image from URL',
|
||||||
|
'playground.params.duration': 'Duration (seconds)'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -164,7 +164,8 @@ export default {
|
|||||||
'playground.uploadImage.url.invalid':
|
'playground.uploadImage.url.invalid':
|
||||||
'Please enter a direct image URL (e.g. https://.../image.png). Press ESC to cancel.',
|
'Please enter a direct image URL (e.g. https://.../image.png). Press ESC to cancel.',
|
||||||
'playground.uploadImage.url.holder': 'Enter an image URL',
|
'playground.uploadImage.url.holder': 'Enter an image URL',
|
||||||
'playground.uploadImage.url.button': 'Add Image from URL'
|
'playground.uploadImage.url.button': 'Add Image from URL',
|
||||||
|
'playground.params.duration': 'Duration (seconds)'
|
||||||
};
|
};
|
||||||
|
|
||||||
// ========== To-Do: Translate Keys (Remove After Translation) ==========
|
// ========== To-Do: Translate Keys (Remove After Translation) ==========
|
||||||
@@ -173,5 +174,6 @@ export default {
|
|||||||
// 3. 'playground.uploadfile.sizeError': 'File size exceeds the limit. Maximum allowed: {size}.'
|
// 3. 'playground.uploadfile.sizeError': 'File size exceeds the limit. Maximum allowed: {size}.'
|
||||||
// 4. 'playground.uploadImage.url.invalid': 'Please enter a direct image URL(e.g. https://.../image.png). Press ESC to cancel.',
|
// 4. 'playground.uploadImage.url.invalid': 'Please enter a direct image URL(e.g. https://.../image.png). Press ESC to cancel.',
|
||||||
// 5. 'playground.uploadImage.url.holder': 'Enter an image URL'
|
// 5. 'playground.uploadImage.url.holder': 'Enter an image URL'
|
||||||
// 6. 'playground.uploadImage.url.button': 'Add Image from URL'
|
// 6. 'playground.uploadImage.url.button': 'Add Image from URL',
|
||||||
|
// 7. 'playground.params.duration': 'Duration (seconds)'
|
||||||
// ========== End of To-Do List ==========
|
// ========== End of To-Do List ==========
|
||||||
|
|||||||
@@ -158,11 +158,13 @@ export default {
|
|||||||
'playground.uploadImage.url.invalid':
|
'playground.uploadImage.url.invalid':
|
||||||
'Please enter a direct image URL (e.g. https://.../image.png). Press ESC to cancel.',
|
'Please enter a direct image URL (e.g. https://.../image.png). Press ESC to cancel.',
|
||||||
'playground.uploadImage.url.holder': 'Enter an image URL',
|
'playground.uploadImage.url.holder': 'Enter an image URL',
|
||||||
'playground.uploadImage.url.button': 'Add Image from URL'
|
'playground.uploadImage.url.button': 'Add Image from URL',
|
||||||
|
'playground.params.duration': 'Duration (seconds)'
|
||||||
};
|
};
|
||||||
|
|
||||||
// ========== To-Do: Translate Keys (Remove After Translation) ==========
|
// ========== To-Do: Translate Keys (Remove After Translation) ==========
|
||||||
// 1. 'playground.uploadImage.url.invalid': 'Please enter a direct image URL(e.g. https://.../image.png). Press ESC to cancel.',
|
// 1. 'playground.uploadImage.url.invalid': 'Please enter a direct image URL(e.g. https://.../image.png). Press ESC to cancel.',
|
||||||
// 2. 'playground.uploadImage.url.holder': 'Enter an image URL',
|
// 2. 'playground.uploadImage.url.holder': 'Enter an image URL',
|
||||||
// 3. 'playground.uploadImage.url.button': 'Add Image from URL'
|
// 3. 'playground.uploadImage.url.button': 'Add Image from URL',
|
||||||
|
// 4. 'playground.params.duration': 'Duration (seconds)'
|
||||||
// ========== End of To-Do List ==========
|
// ========== End of To-Do List ==========
|
||||||
|
|||||||
@@ -154,5 +154,6 @@ export default {
|
|||||||
'playground.uploadImage.url.invalid':
|
'playground.uploadImage.url.invalid':
|
||||||
'请输入直接的图片链接(例如:https://…/image.png)。按 ESC 可取消。',
|
'请输入直接的图片链接(例如:https://…/image.png)。按 ESC 可取消。',
|
||||||
'playground.uploadImage.url.holder': '请输入图片链接',
|
'playground.uploadImage.url.holder': '请输入图片链接',
|
||||||
'playground.uploadImage.url.button': '从链接添加图片'
|
'playground.uploadImage.url.button': '从链接添加图片',
|
||||||
|
'playground.params.duration': '时长 (秒)'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ const ClusterDetailModal = () => {
|
|||||||
items={[
|
items={[
|
||||||
{
|
{
|
||||||
key: 'workers',
|
key: 'workers',
|
||||||
label: `Workers (${clusterDetailData?.workers ?? 0})`,
|
label: `Workers`,
|
||||||
icon: <IconFont type="icon-resources" />,
|
icon: <IconFont type="icon-resources" />,
|
||||||
children: (
|
children: (
|
||||||
<WorkerList
|
<WorkerList
|
||||||
@@ -58,13 +58,13 @@ const ClusterDetailModal = () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'deployments',
|
key: 'deployments',
|
||||||
label: `Deployments (${clusterDetailData?.models ?? 0})`,
|
label: `Deployments`,
|
||||||
icon: <IconFont type="icon-rocket-launch1" />,
|
icon: <IconFont type="icon-rocket-launch1" />,
|
||||||
children: <Deployments clusterId={Number(id)}></Deployments>
|
children: <Deployments clusterId={Number(id)}></Deployments>
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'gpus',
|
key: 'gpus',
|
||||||
label: `GPUs (${clusterDetailData?.gpus ?? 0})`,
|
label: `GPUs`,
|
||||||
icon: <IconFont type="icon-gpu1" />,
|
icon: <IconFont type="icon-gpu1" />,
|
||||||
children: <GPUList clusterId={Number(id)} widths={{ input: 360 }} />
|
children: <GPUList clusterId={Number(id)} widths={{ input: 360 }} />
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import LabelSelector from '@/components/label-selector';
|
import LabelSelector from '@/components/label-selector';
|
||||||
import CheckboxField from '@/components/seal-form/checkbox-field';
|
import CheckboxField from '@/components/seal-form/checkbox-field';
|
||||||
import SealSelect from '@/components/seal-form/seal-select';
|
import SealSelect from '@/components/seal-form/seal-select';
|
||||||
import SealSlider from '@/components/seal-form/seal-slider';
|
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import { Form } from 'antd';
|
import { Form } from 'antd';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
@@ -68,36 +67,6 @@ const AdvanceConfig = () => {
|
|||||||
options={modelCategories}
|
options={modelCategories}
|
||||||
></SealSelect>
|
></SealSelect>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{!isGGUF && modelContextData?.native && (
|
|
||||||
<Form.Item<FormData> name="max_context_len">
|
|
||||||
<SealSlider
|
|
||||||
label={intl.formatMessage({ id: 'models.form.maxContextLength' })}
|
|
||||||
inputnumber={true}
|
|
||||||
onChange={handleContextLengthChange}
|
|
||||||
included={true}
|
|
||||||
max={modelContextData?.scaled || 163840}
|
|
||||||
tooltip={{}}
|
|
||||||
step={1024}
|
|
||||||
marks={{
|
|
||||||
[modelContextData?.scaled]: {
|
|
||||||
label: 'scaled',
|
|
||||||
style: {
|
|
||||||
transform: 'translateX(-100%)'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[modelContextData?.native]: {
|
|
||||||
label: 'native',
|
|
||||||
style: {
|
|
||||||
transform:
|
|
||||||
modelContextData?.scaled === modelContextData?.native
|
|
||||||
? 'translateX(-100%)'
|
|
||||||
: 'unset'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
></SealSlider>
|
|
||||||
</Form.Item>
|
|
||||||
)}
|
|
||||||
<BackendParametersList></BackendParametersList>
|
<BackendParametersList></BackendParametersList>
|
||||||
<Form.Item<FormData> name="env">
|
<Form.Item<FormData> name="env">
|
||||||
<LabelSelector
|
<LabelSelector
|
||||||
|
|||||||
@@ -2,10 +2,9 @@ import { setRouteCache } from '@/atoms/route-cache';
|
|||||||
import AlertInfo from '@/components/alert-info';
|
import AlertInfo from '@/components/alert-info';
|
||||||
import IconFont from '@/components/icon-font';
|
import IconFont from '@/components/icon-font';
|
||||||
import routeCachekey from '@/config/route-cachekey';
|
import routeCachekey from '@/config/route-cachekey';
|
||||||
import ThumbImg from '@/pages/playground/components/thumb-img';
|
|
||||||
import { VideoCameraOutlined } from '@ant-design/icons';
|
import { VideoCameraOutlined } from '@ant-design/icons';
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import { Button, Tooltip } from 'antd';
|
import { Button, Spin, Tooltip } from 'antd';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import 'overlayscrollbars/overlayscrollbars.css';
|
import 'overlayscrollbars/overlayscrollbars.css';
|
||||||
@@ -116,6 +115,7 @@ const GroundVideo: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
const viewCodeContent = useMemo(() => {
|
const viewCodeContent = useMemo(() => {
|
||||||
return generateCode({
|
return generateCode({
|
||||||
api: CREATE_VIDEO_API,
|
api: CREATE_VIDEO_API,
|
||||||
|
isFormdata: true,
|
||||||
parameters: {
|
parameters: {
|
||||||
...finalParameters,
|
...finalParameters,
|
||||||
prompt: currentPrompt
|
prompt: currentPrompt
|
||||||
@@ -170,22 +170,34 @@ const GroundVideo: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
>
|
>
|
||||||
<>
|
<>
|
||||||
<div className="content" style={{ height: '100%' }}>
|
<div className="content" style={{ height: '100%' }}>
|
||||||
<ThumbImg
|
{videoList.length > 0 && (
|
||||||
style={{
|
<div
|
||||||
padding: 0,
|
style={{
|
||||||
height: '100%',
|
width: '100%',
|
||||||
justifyContent: 'center',
|
maxWidth: 720,
|
||||||
flexDirection: 'column',
|
margin: '24px auto',
|
||||||
flexWrap: 'unset',
|
aspectRatio: '16 / 9',
|
||||||
alignItems: 'center'
|
background: '#000',
|
||||||
}}
|
borderRadius: 8,
|
||||||
autoBgColor={false}
|
overflow: 'hidden',
|
||||||
editable={false}
|
boxShadow: '0 4px 24px rgba(0,0,0,0.12)'
|
||||||
dataList={videoList}
|
}}
|
||||||
responseable={true}
|
>
|
||||||
gutter={[8, 16]}
|
<Spin spinning={loading}>
|
||||||
autoSize={true}
|
<video
|
||||||
></ThumbImg>
|
src={videoList[0]?.dataUrl}
|
||||||
|
poster="https://placehold.co/640x360.png?text=GPUStack"
|
||||||
|
controls
|
||||||
|
disablePictureInPicture
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
height: '100%',
|
||||||
|
objectFit: 'contain'
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Spin>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{!videoList.length && (
|
{!videoList.length && (
|
||||||
<div className="flex-column font-size-14 flex-center gap-20 justify-center hold-wrapper">
|
<div className="flex-column font-size-14 flex-center gap-20 justify-center hold-wrapper">
|
||||||
<VideoCameraOutlined className="font-size-32 text-secondary" />
|
<VideoCameraOutlined className="font-size-32 text-secondary" />
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { ParamsSchema } from './types';
|
import { ParamsSchema } from './types';
|
||||||
|
|
||||||
export interface ImageSizeItem {
|
export interface SizeOption {
|
||||||
label: string;
|
label: string;
|
||||||
value: string;
|
value: string;
|
||||||
width: number;
|
width: number;
|
||||||
@@ -504,7 +504,7 @@ export const ImageAdvancedParamsConfig: ParamsSchema[] = [
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
export const ImageCustomSizeConfig: ParamsSchema[] = [
|
export const CustomSizeConfig: ParamsSchema[] = [
|
||||||
{
|
{
|
||||||
type: 'Slider',
|
type: 'Slider',
|
||||||
name: 'width',
|
name: 'width',
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { ImageSizeItem } from './params-config';
|
import { SizeOption } from './params-config';
|
||||||
import { ParamsSchema } from './types';
|
import { ParamsSchema } from './types';
|
||||||
|
|
||||||
export const videoSizeOptions: ImageSizeItem[] = [
|
export const videoSizeOptions: SizeOption[] = [
|
||||||
{ label: '720x1280', value: '720x1280', width: 720, height: 1280 },
|
{ label: '720x1280', value: '720x1280', width: 720, height: 1280 },
|
||||||
{ label: '1280x720', value: '1280x720', width: 1280, height: 720 },
|
{ label: '1280x720', value: '1280x720', width: 1280, height: 720 },
|
||||||
{ label: '1024x1792', value: '1024x1792', width: 1024, height: 1792 },
|
{ label: '1024x1792', value: '1024x1792', width: 1024, height: 1792 },
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import useOverlayScroller from '@/hooks/use-overlay-scroller';
|
import useOverlayScroller from '@/hooks/use-overlay-scroller';
|
||||||
import {
|
import {
|
||||||
|
CustomSizeConfig,
|
||||||
ImageCountConfig,
|
ImageCountConfig,
|
||||||
ImageCustomSizeConfig,
|
|
||||||
ImageSizeConfig,
|
ImageSizeConfig,
|
||||||
ImageSizeItem,
|
|
||||||
ImageconstExtraConfig,
|
ImageconstExtraConfig,
|
||||||
ImageAdvancedParamsConfig as ImgAdvancedParamsConfig,
|
ImageAdvancedParamsConfig as ImgAdvancedParamsConfig,
|
||||||
|
SizeOption,
|
||||||
imageSizeOptions as imageSizeList
|
imageSizeOptions as imageSizeList
|
||||||
} from '@/pages/playground/config/params-config';
|
} from '@/pages/playground/config/params-config';
|
||||||
import { generateRandomNumber } from '@/utils';
|
import { generateRandomNumber } from '@/utils';
|
||||||
@@ -210,9 +210,9 @@ export const useInitImageMeta = (
|
|||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const [modelMeta, setModelMeta] = useState<any>({});
|
const [modelMeta, setModelMeta] = useState<any>({});
|
||||||
const [isOpenaiCompatible, setIsOpenaiCompatible] = useState<boolean>(false);
|
const [isOpenaiCompatible, setIsOpenaiCompatible] = useState<boolean>(false);
|
||||||
const [imageSizeOptions, setImageSizeOptions] = React.useState<
|
const [imageSizeOptions, setImageSizeOptions] = React.useState<SizeOption[]>(
|
||||||
ImageSizeItem[]
|
[]
|
||||||
>([]);
|
);
|
||||||
const [basicParamsConfig, setBasicParamsConfig] = React.useState<
|
const [basicParamsConfig, setBasicParamsConfig] = React.useState<
|
||||||
ParamsSchema[]
|
ParamsSchema[]
|
||||||
>([...ImageCountConfig, ...ImageSizeConfig]);
|
>([...ImageCountConfig, ...ImageSizeConfig]);
|
||||||
@@ -275,7 +275,7 @@ export const useInitImageMeta = (
|
|||||||
|
|
||||||
const generateImageParamsConfig = (
|
const generateImageParamsConfig = (
|
||||||
currentModel: any,
|
currentModel: any,
|
||||||
sizeOptions: ImageSizeItem[]
|
sizeOptions: SizeOption[]
|
||||||
) => {
|
) => {
|
||||||
if (sizeOptions.length) {
|
if (sizeOptions.length) {
|
||||||
const sizeConfig = ImageSizeConfig.map((item) => {
|
const sizeConfig = ImageSizeConfig.map((item) => {
|
||||||
@@ -290,18 +290,16 @@ export const useInitImageMeta = (
|
|||||||
return [...ImageCountConfig, ...sizeConfig];
|
return [...ImageCountConfig, ...sizeConfig];
|
||||||
}
|
}
|
||||||
const { max_height, max_width } = currentModel.meta || {};
|
const { max_height, max_width } = currentModel.meta || {};
|
||||||
const customSizeConfig = _.cloneDeep(ImageCustomSizeConfig).map(
|
const customSizeConfig = _.cloneDeep(CustomSizeConfig).map((item: any) => {
|
||||||
(item: any) => {
|
const max = item.name === 'height' ? max_height : max_width;
|
||||||
const max = item.name === 'height' ? max_height : max_width;
|
return {
|
||||||
return {
|
...item,
|
||||||
...item,
|
attrs: {
|
||||||
attrs: {
|
...item.attrs,
|
||||||
...item.attrs,
|
max: max || item.attrs.max
|
||||||
max: max || item.attrs.max
|
}
|
||||||
}
|
};
|
||||||
};
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
return [...ImageCountConfig, ...customSizeConfig];
|
return [...ImageCountConfig, ...customSizeConfig];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -334,7 +332,7 @@ export const useInitImageMeta = (
|
|||||||
if (values.size === 'custom') {
|
if (values.size === 'custom') {
|
||||||
return [
|
return [
|
||||||
...basicParamsConfig,
|
...basicParamsConfig,
|
||||||
...ImageCustomSizeConfig,
|
...CustomSizeConfig,
|
||||||
...(values.isOpenaiCompatible
|
...(values.isOpenaiCompatible
|
||||||
? ImageconstExtraConfig
|
? ImageconstExtraConfig
|
||||||
: ImageAdvancedParamsConfig)
|
: ImageAdvancedParamsConfig)
|
||||||
@@ -437,7 +435,7 @@ export const useInitImageMeta = (
|
|||||||
if (changeValues.size && changeValues.size === 'custom') {
|
if (changeValues.size && changeValues.size === 'custom') {
|
||||||
setParamsConfig([
|
setParamsConfig([
|
||||||
...basicParamsConfig,
|
...basicParamsConfig,
|
||||||
...ImageCustomSizeConfig,
|
...CustomSizeConfig,
|
||||||
...(!isOpenaiCompatible
|
...(!isOpenaiCompatible
|
||||||
? ImageAdvancedParamsConfig
|
? ImageAdvancedParamsConfig
|
||||||
: ImageconstExtraConfig)
|
: ImageconstExtraConfig)
|
||||||
@@ -515,7 +513,7 @@ export const useInitImageMeta = (
|
|||||||
imgInitialValues,
|
imgInitialValues,
|
||||||
ImageCountConfig,
|
ImageCountConfig,
|
||||||
ImageSizeConfig,
|
ImageSizeConfig,
|
||||||
ImageCustomSizeConfig,
|
CustomSizeConfig,
|
||||||
ImageconstExtraConfig
|
ImageconstExtraConfig
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
ImageCustomSizeConfig,
|
CustomSizeConfig,
|
||||||
ImageSizeItem
|
SizeOption
|
||||||
} from '@/pages/playground/config/params-config';
|
} from '@/pages/playground/config/params-config';
|
||||||
import { generateRandomNumber } from '@/utils';
|
import { generateRandomNumber } from '@/utils';
|
||||||
import { useSearchParams } from '@umijs/max';
|
import { useSearchParams } from '@umijs/max';
|
||||||
@@ -43,9 +43,9 @@ export const useInitVideoMeta = (
|
|||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const [modelMeta, setModelMeta] = useState<any>({});
|
const [modelMeta, setModelMeta] = useState<any>({});
|
||||||
const [isOpenaiCompatible, setIsOpenaiCompatible] = useState<boolean>(false);
|
const [isOpenaiCompatible, setIsOpenaiCompatible] = useState<boolean>(false);
|
||||||
const [videoSizeOptions, setVideoSizeOptions] = React.useState<
|
const [videoSizeOptions, setVideoSizeOptions] = React.useState<SizeOption[]>(
|
||||||
ImageSizeItem[]
|
[]
|
||||||
>([]);
|
);
|
||||||
const [basicParamsConfig, setBasicParamsConfig] = React.useState<
|
const [basicParamsConfig, setBasicParamsConfig] = React.useState<
|
||||||
ParamsSchema[]
|
ParamsSchema[]
|
||||||
>([...videoParamsConfig]);
|
>([...videoParamsConfig]);
|
||||||
@@ -107,7 +107,7 @@ export const useInitVideoMeta = (
|
|||||||
|
|
||||||
const generateParamsConfig = (
|
const generateParamsConfig = (
|
||||||
currentModel: any,
|
currentModel: any,
|
||||||
sizeOptions: ImageSizeItem[]
|
sizeOptions: SizeOption[]
|
||||||
) => {
|
) => {
|
||||||
if (sizeOptions.length) {
|
if (sizeOptions.length) {
|
||||||
const sizeConfig = videoParamsConfig.map((item) => {
|
const sizeConfig = videoParamsConfig.map((item) => {
|
||||||
@@ -120,18 +120,16 @@ export const useInitVideoMeta = (
|
|||||||
}
|
}
|
||||||
const { max_height, max_width } = currentModel.meta || {};
|
const { max_height, max_width } = currentModel.meta || {};
|
||||||
// generate custom size config
|
// generate custom size config
|
||||||
const customSizeConfig = _.cloneDeep(ImageCustomSizeConfig).map(
|
const customSizeConfig = _.cloneDeep(CustomSizeConfig).map((item: any) => {
|
||||||
(item: any) => {
|
const max = item.name === 'height' ? max_height : max_width;
|
||||||
const max = item.name === 'height' ? max_height : max_width;
|
return {
|
||||||
return {
|
...item,
|
||||||
...item,
|
attrs: {
|
||||||
attrs: {
|
...item.attrs,
|
||||||
...item.attrs,
|
max: max || item.attrs.max
|
||||||
max: max || item.attrs.max
|
}
|
||||||
}
|
};
|
||||||
};
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
return [...customSizeConfig];
|
return [...customSizeConfig];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -163,7 +161,7 @@ export const useInitVideoMeta = (
|
|||||||
if (values.size === 'custom') {
|
if (values.size === 'custom') {
|
||||||
return [
|
return [
|
||||||
...basicParamsConfig,
|
...basicParamsConfig,
|
||||||
...ImageCustomSizeConfig,
|
...CustomSizeConfig,
|
||||||
...(values.isOpenaiCompatible
|
...(values.isOpenaiCompatible
|
||||||
? videoExtraConfig
|
? videoExtraConfig
|
||||||
: videoAdvancedParamsConfig)
|
: videoAdvancedParamsConfig)
|
||||||
@@ -266,7 +264,7 @@ export const useInitVideoMeta = (
|
|||||||
if (changeValues.size && changeValues.size === 'custom') {
|
if (changeValues.size && changeValues.size === 'custom') {
|
||||||
setParamsConfig([
|
setParamsConfig([
|
||||||
...basicParamsConfig,
|
...basicParamsConfig,
|
||||||
...ImageCustomSizeConfig,
|
...CustomSizeConfig,
|
||||||
...(!isOpenaiCompatible
|
...(!isOpenaiCompatible
|
||||||
? videoAdvancedParamsConfig
|
? videoAdvancedParamsConfig
|
||||||
: videoExtraConfig)
|
: videoExtraConfig)
|
||||||
@@ -342,7 +340,7 @@ export const useInitVideoMeta = (
|
|||||||
videoAdvancedDefaultValues,
|
videoAdvancedDefaultValues,
|
||||||
videoAdvancedParamsConfig,
|
videoAdvancedParamsConfig,
|
||||||
videoInitialValues,
|
videoInitialValues,
|
||||||
ImageCustomSizeConfig,
|
CustomSizeConfig,
|
||||||
videoExtraConfig
|
videoExtraConfig
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,10 +13,6 @@ export default function useTextVideo(props: any) {
|
|||||||
const [videoList, setVideoList] = useState<
|
const [videoList, setVideoList] = useState<
|
||||||
{
|
{
|
||||||
dataUrl: string;
|
dataUrl: string;
|
||||||
height: number | string;
|
|
||||||
width: string | number;
|
|
||||||
maxHeight: string | number;
|
|
||||||
maxWidth: string | number;
|
|
||||||
uid: number;
|
uid: number;
|
||||||
span?: number;
|
span?: number;
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
@@ -47,29 +43,6 @@ export default function useTextVideo(props: any) {
|
|||||||
return requestIdRef.current;
|
return requestIdRef.current;
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeBase64Suffix = (str: string, suffix: string) => {
|
|
||||||
return str.endsWith(suffix) ? str.slice(0, -suffix.length) : str;
|
|
||||||
};
|
|
||||||
|
|
||||||
const setImageSize = (parameters: any) => {
|
|
||||||
let size: Record<string, string | number> = {
|
|
||||||
span: 12
|
|
||||||
};
|
|
||||||
if (parameters.n === 1) {
|
|
||||||
size.span = 24;
|
|
||||||
}
|
|
||||||
if (parameters.n === 2) {
|
|
||||||
size.span = 12;
|
|
||||||
}
|
|
||||||
if (parameters.n === 3) {
|
|
||||||
size.span = 12;
|
|
||||||
}
|
|
||||||
if (parameters.n === 4) {
|
|
||||||
size.span = 12;
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
};
|
|
||||||
|
|
||||||
const setMessageId = () => {
|
const setMessageId = () => {
|
||||||
messageId.current = messageId.current + 1;
|
messageId.current = messageId.current + 1;
|
||||||
return messageId.current;
|
return messageId.current;
|
||||||
@@ -91,31 +64,21 @@ export default function useTextVideo(props: any) {
|
|||||||
requestToken.current?.abort?.('cancel');
|
requestToken.current?.abort?.('cancel');
|
||||||
requestToken.current = new AbortController();
|
requestToken.current = new AbortController();
|
||||||
const currentRequestId = updateRequestId();
|
const currentRequestId = updateRequestId();
|
||||||
const size: any = setImageSize(parameters);
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setMessageId();
|
setMessageId();
|
||||||
setTokenResult(null);
|
setTokenResult(null);
|
||||||
|
|
||||||
const imgSize = _.split(parameters.size, 'x').map((item: string) =>
|
const newList = [
|
||||||
_.toNumber(item)
|
{
|
||||||
);
|
dataUrl: '',
|
||||||
|
progress: 0,
|
||||||
|
loading: true,
|
||||||
|
preview: false,
|
||||||
|
uid: setMessageId()
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
let newImageList = Array(parameters.n)
|
setVideoList(newList);
|
||||||
.fill({})
|
|
||||||
.map((item, index: number) => {
|
|
||||||
return {
|
|
||||||
dataUrl: 'data:image/png;base64,',
|
|
||||||
...size,
|
|
||||||
progress: 0,
|
|
||||||
height: imgSize[1],
|
|
||||||
width: imgSize[0],
|
|
||||||
loading: true,
|
|
||||||
progressType: 'dashboard',
|
|
||||||
preview: false,
|
|
||||||
uid: setMessageId()
|
|
||||||
};
|
|
||||||
});
|
|
||||||
setVideoList(newImageList);
|
|
||||||
|
|
||||||
const result = await createVideo({
|
const result = await createVideo({
|
||||||
data: parameters,
|
data: parameters,
|
||||||
@@ -145,28 +108,15 @@ export default function useTextVideo(props: any) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result?.data?.forEach((item: any, index: number) => {
|
newList[0] = {
|
||||||
const imgItem = newImageList[index];
|
...newList[0],
|
||||||
|
dataUrl: result?.id,
|
||||||
|
loading: false,
|
||||||
|
progress: 100
|
||||||
|
};
|
||||||
|
|
||||||
if (item.b64_json) {
|
console.log('newList:', newList);
|
||||||
imgItem.dataUrl = `data:image/png;base64,${item.b64_json}`;
|
setVideoList([...newList]);
|
||||||
}
|
|
||||||
|
|
||||||
newImageList[index] = {
|
|
||||||
dataUrl: imgItem.dataUrl,
|
|
||||||
height: imgSize[1],
|
|
||||||
width: imgSize[0],
|
|
||||||
maxHeight: `${imgSize[1]}px`,
|
|
||||||
maxWidth: `${imgSize[0]}px`,
|
|
||||||
uid: imgItem.uid,
|
|
||||||
span: imgItem.span,
|
|
||||||
loading: false,
|
|
||||||
preview: true,
|
|
||||||
progress: 100
|
|
||||||
};
|
|
||||||
});
|
|
||||||
console.log('newImageList:', newImageList);
|
|
||||||
setVideoList([...newImageList]);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('error:', error);
|
console.log('error:', error);
|
||||||
updateRequestId();
|
updateRequestId();
|
||||||
|
|||||||
@@ -17,32 +17,30 @@ import './style/play-ground.less';
|
|||||||
|
|
||||||
const PlaygroundRerank: React.FC = () => {
|
const PlaygroundRerank: React.FC = () => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const groundRerankerRef = useRef<any>(null);
|
const groundVideoRef = useRef<any>(null);
|
||||||
const [rerankerModelList, setRerankerModelList] = useState<
|
const [modelList, setModelList] = useState<Global.BaseOption<string>[]>([]);
|
||||||
Global.BaseOption<string>[]
|
|
||||||
>([]);
|
|
||||||
const [loaded, setLoaded] = useState(false);
|
const [loaded, setLoaded] = useState(false);
|
||||||
|
|
||||||
useCollapseLayout({
|
useCollapseLayout({
|
||||||
handler: () => {
|
handler: () => {
|
||||||
groundRerankerRef.current?.setCollapse?.();
|
groundVideoRef.current?.setCollapse?.();
|
||||||
},
|
},
|
||||||
triggeredRef: groundRerankerRef.current
|
triggeredRef: groundVideoRef.current
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleViewCode = useMemoizedFn(() => {
|
const handleViewCode = useMemoizedFn(() => {
|
||||||
groundRerankerRef.current?.viewCode?.();
|
groundVideoRef.current?.viewCode?.();
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleToggleCollapse = useMemoizedFn(() => {
|
const handleToggleCollapse = useMemoizedFn(() => {
|
||||||
groundRerankerRef.current?.setCollapse?.();
|
groundVideoRef.current?.setCollapse?.();
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const getModelListByReranker = async () => {
|
const getModelList = async () => {
|
||||||
try {
|
try {
|
||||||
const params = {
|
const params = {
|
||||||
categories: modelCategoriesMap.reranker,
|
categories: modelCategoriesMap.llm,
|
||||||
with_meta: true
|
with_meta: true
|
||||||
};
|
};
|
||||||
const res = await queryModelsList(params);
|
const res = await queryModelsList(params);
|
||||||
@@ -61,10 +59,8 @@ const PlaygroundRerank: React.FC = () => {
|
|||||||
};
|
};
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
try {
|
try {
|
||||||
const [rerankerModelList] = await Promise.all([
|
const [modelList] = await Promise.all([getModelList()]);
|
||||||
getModelListByReranker()
|
setModelList(modelList);
|
||||||
]);
|
|
||||||
setRerankerModelList(rerankerModelList);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setLoaded(true);
|
setLoaded(true);
|
||||||
}
|
}
|
||||||
@@ -75,7 +71,7 @@ const PlaygroundRerank: React.FC = () => {
|
|||||||
useHotkeys(
|
useHotkeys(
|
||||||
HotKeys.RIGHT.join(','),
|
HotKeys.RIGHT.join(','),
|
||||||
() => {
|
() => {
|
||||||
groundRerankerRef.current?.setCollapse?.();
|
groundVideoRef.current?.setCollapse?.();
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
preventDefault: true
|
preventDefault: true
|
||||||
@@ -103,8 +99,8 @@ const PlaygroundRerank: React.FC = () => {
|
|||||||
<div className="play-ground">
|
<div className="play-ground">
|
||||||
<div className="chat">
|
<div className="chat">
|
||||||
<GroundVideo
|
<GroundVideo
|
||||||
ref={groundRerankerRef}
|
ref={groundVideoRef}
|
||||||
modelList={rerankerModelList}
|
modelList={modelList}
|
||||||
loaded={loaded}
|
loaded={loaded}
|
||||||
></GroundVideo>
|
></GroundVideo>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { MODEL_PROXY } from '../apis';
|
import { MODEL_PROXY, OPENAI_COMPATIBLE } from '../apis';
|
||||||
import { fomatNodeJsParams, formatCurlArgs } from './utils';
|
import { fomatNodeJsParams, formatCurlArgs, formatPyParams } from './utils';
|
||||||
|
|
||||||
export const generateCurlCode = ({
|
export const generateCurlCode = ({
|
||||||
api: url,
|
api: url,
|
||||||
@@ -13,23 +13,14 @@ export const generateCurlCode = ({
|
|||||||
const api = modelProxy ? `${MODEL_PROXY}/\${YOUR_API_PATH}` : url;
|
const api = modelProxy ? `${MODEL_PROXY}/\${YOUR_API_PATH}` : url;
|
||||||
|
|
||||||
// ========================= Curl =========================
|
// ========================= Curl =========================
|
||||||
let curlCode = `
|
|
||||||
curl ${host}${api} \\
|
|
||||||
-H "Content-Type: application/json" \\
|
|
||||||
-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\${modelProxy ? `\n-H "X-GPUStack-Model: ${parameters.model}" \\` : ''}
|
|
||||||
${formatCurlArgs(parameters, isFormdata)}`.trim();
|
|
||||||
|
|
||||||
if (edit) {
|
const curlCode = `
|
||||||
curlCode = `
|
|
||||||
curl ${host}${api} \\
|
curl ${host}${api} \\
|
||||||
-H "Content-Type: multipart/form-data" \\
|
-H "Content-Type: multipart/form-data" \\
|
||||||
-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\${modelProxy ? `\n-H "X-GPUStack-Model: ${parameters.model}" \\` : ''}
|
-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\${modelProxy ? `\n-H "X-GPUStack-Model: ${parameters.model}" \\` : ''}
|
||||||
-F image="@image.png" \\
|
|
||||||
-F mask="@mask.png" \\
|
|
||||||
${formatCurlArgs(_.omit(parameters, ['mask', 'image']), isFormdata)}`
|
${formatCurlArgs(_.omit(parameters, ['mask', 'image']), isFormdata)}`
|
||||||
.trim()
|
.trim()
|
||||||
.replace(/\\$/, '');
|
.replace(/\\$/, '');
|
||||||
}
|
|
||||||
|
|
||||||
return curlCode;
|
return curlCode;
|
||||||
};
|
};
|
||||||
@@ -37,8 +28,7 @@ ${formatCurlArgs(_.omit(parameters, ['mask', 'image']), isFormdata)}`
|
|||||||
export const generateCode = ({
|
export const generateCode = ({
|
||||||
api: url,
|
api: url,
|
||||||
parameters,
|
parameters,
|
||||||
isFormdata = false,
|
isFormdata = false
|
||||||
edit = false
|
|
||||||
}: Record<string, any>) => {
|
}: Record<string, any>) => {
|
||||||
const host = window.location.origin;
|
const host = window.location.origin;
|
||||||
const api = url;
|
const api = url;
|
||||||
@@ -47,36 +37,39 @@ export const generateCode = ({
|
|||||||
let curlCode = generateCurlCode({
|
let curlCode = generateCurlCode({
|
||||||
api: url,
|
api: url,
|
||||||
parameters,
|
parameters,
|
||||||
isFormdata,
|
isFormdata
|
||||||
edit
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// ========================= Python =========================
|
// ========================= Python =========================
|
||||||
const pythonCode = `
|
const pythonCode = `
|
||||||
import requests\n
|
from openai import OpenAI\n
|
||||||
url="${host}${api}"
|
client = OpenAI(
|
||||||
headers = {
|
base_url="${host}/${OPENAI_COMPATIBLE}",
|
||||||
"Content-type": "application/json",
|
api_key="YOUR_GPUSTACK_API_KEY"
|
||||||
"Authorization": "Bearer $\{YOUR_GPUSTACK_API_KEY}"
|
)
|
||||||
}
|
|
||||||
data = ${JSON.stringify(parameters, null, 2).replace(/null/g, 'None')}\n
|
video = client.videos.create(\n${formatPyParams({ ...parameters })})\n
|
||||||
response = requests.post(url, headers=headers, json=data)
|
print(video.id)`.trim();
|
||||||
print(response.json()['data']['object'])`.trim();
|
|
||||||
|
|
||||||
// ========================= Node.js =========================
|
// ========================= Node.js =========================
|
||||||
|
const params = fomatNodeJsParams({
|
||||||
|
...parameters
|
||||||
|
});
|
||||||
|
|
||||||
const nodeJsCode = `
|
const nodeJsCode = `
|
||||||
const axios = require('axios');
|
const OpenAI = require("openai");
|
||||||
|
|
||||||
const url = "${host}${api}";
|
const openai = new OpenAI({
|
||||||
const headers = {
|
"apiKey": "YOUR_GPUSTACK_API_KEY",
|
||||||
"Content-type": "application/json",
|
"baseURL": "${host}/${OPENAI_COMPATIBLE}"
|
||||||
"Authorization": "Bearer $\{YOUR_GPUSTACK_API_KEY}"
|
});
|
||||||
};
|
|
||||||
const data = ${fomatNodeJsParams(parameters)};
|
|
||||||
|
|
||||||
axios.post(url, data, { headers }).then((response) => {
|
async function main() {
|
||||||
console.log(response.data.object);
|
const params = ${params};
|
||||||
});`.trim();
|
const video = await openai.videos.create(params);
|
||||||
|
console.log(video.id);
|
||||||
|
}
|
||||||
|
main();`.trim();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
curlCode,
|
curlCode,
|
||||||
|
|||||||
Reference in New Issue
Block a user