297 lines
9.0 KiB
React
297 lines
9.0 KiB
React
/*
|
||
Copyright (C) 2025 QuantumNous
|
||
|
||
This program is free software: you can redistribute it and/or modify
|
||
it under the terms of the GNU Affero General Public License as
|
||
published by the Free Software Foundation, either version 3 of the
|
||
License, or (at your option) any later version.
|
||
|
||
This program is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
GNU Affero General Public License for more details.
|
||
|
||
You should have received a copy of the GNU Affero General Public License
|
||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||
|
||
For commercial licensing, please contact support@quantumnous.com
|
||
*/
|
||
|
||
import React, { useState, useEffect } from 'react';
|
||
import {
|
||
Modal,
|
||
Form,
|
||
Select,
|
||
Input,
|
||
InputNumber,
|
||
Switch,
|
||
Space,
|
||
Typography,
|
||
} from '@douyinfe/semi-ui';
|
||
import { useTranslation } from 'react-i18next';
|
||
import { useIsMobile } from '../../../../../hooks/common/useIsMobile';
|
||
import ModelSelector from '../../../../../components/common/ModelSelector';
|
||
import { MODEL_CATEGORY } from '../../../../../constants';
|
||
import { buildVideoRegenerateRequest } from '../../../../../helpers/videoTask';
|
||
|
||
const { TextArea } = Input;
|
||
const { Text } = Typography;
|
||
|
||
const VideoRegenerateModal = ({ visible, onCancel, onConfirm, task }) => {
|
||
const isNarrow = useIsMobile();
|
||
const { t } = useTranslation();
|
||
const [formData, setFormData] = useState({
|
||
mode: 'text2video',
|
||
prompt: '',
|
||
negative_prompt: '',
|
||
resolution: '1080P',
|
||
duration: 5,
|
||
fps: 30,
|
||
ratio: '16:9',
|
||
audio: false,
|
||
seed: -1,
|
||
prompt_extend: false,
|
||
watermark: false,
|
||
image: '',
|
||
});
|
||
const [selectedModel, setSelectedModel] = useState('');
|
||
|
||
// 从任务数据中提取参数
|
||
useEffect(() => {
|
||
if (task && visible) {
|
||
const taskData = task.request || {};
|
||
const mode = taskData.mode || 'text2video';
|
||
const prompt = taskData.prompt || '';
|
||
const negativePrompt = taskData.negative_prompt || '';
|
||
const resolution = taskData.resolution || '1080P';
|
||
const duration = taskData.duration || 5;
|
||
const fps = taskData.fps || 30;
|
||
const ratio = taskData.ratio || '16:9';
|
||
const audio = taskData.audio === true;
|
||
const seed = taskData.seed ?? -1;
|
||
const promptExtend = taskData.prompt_extend === true;
|
||
const watermark = taskData.watermark === true;
|
||
const image = taskData.image || '';
|
||
const model = taskData.model || '';
|
||
|
||
setFormData({
|
||
mode,
|
||
prompt,
|
||
negative_prompt: negativePrompt,
|
||
resolution,
|
||
duration,
|
||
fps,
|
||
ratio,
|
||
audio,
|
||
seed,
|
||
prompt_extend: promptExtend,
|
||
watermark,
|
||
image,
|
||
});
|
||
|
||
setSelectedModel(model);
|
||
}
|
||
}, [task, visible]);
|
||
|
||
// 处理表单提交
|
||
const handleSubmit = () => {
|
||
if (!selectedModel || typeof selectedModel !== 'object') {
|
||
return;
|
||
}
|
||
|
||
// 构建请求数据
|
||
onConfirm(buildVideoRegenerateRequest(formData, selectedModel));
|
||
};
|
||
|
||
return (
|
||
<Modal
|
||
title={t('再生成视频')}
|
||
visible={visible}
|
||
onCancel={onCancel}
|
||
onOk={handleSubmit}
|
||
okText={t('确认生成')}
|
||
cancelText={t('取消')}
|
||
width={700}
|
||
bodyStyle={{
|
||
maxHeight: '70vh',
|
||
overflowX: 'hidden',
|
||
overflowY: 'auto',
|
||
}}
|
||
>
|
||
<Form
|
||
// 窄屏改为标签在上:labelWidth=120 在 ~294px 的弹窗体里要吃掉 41%,
|
||
// 剩给控件的宽度放不下 seed 输入框和它的说明文案
|
||
labelPosition={isNarrow ? 'top' : 'left'}
|
||
labelAlign='right'
|
||
labelWidth={isNarrow ? undefined : 120}
|
||
>
|
||
{/* 生成模式 */}
|
||
<Form.Label>
|
||
<Text strong>{t('生成模式')}</Text>
|
||
</Form.Label>
|
||
<Form.Input>
|
||
<Select
|
||
value={formData.mode}
|
||
onChange={(value) => {
|
||
setFormData({ ...formData, mode: value });
|
||
setSelectedModel('');
|
||
}}
|
||
style={{ width: '100%' }}
|
||
>
|
||
<Select.Option value='text2video'>{t('文生视频')}</Select.Option>
|
||
<Select.Option value='image2video'>{t('图生视频')}</Select.Option>
|
||
</Select>
|
||
</Form.Input>
|
||
|
||
{/* 模型选择 */}
|
||
<Form.Label required>
|
||
<Text strong>{t('选择模型')}</Text>
|
||
</Form.Label>
|
||
<Form.Input>
|
||
<ModelSelector
|
||
key={formData.mode}
|
||
category={
|
||
formData.mode === 'text2video'
|
||
? MODEL_CATEGORY.TEXT_TO_VIDEO
|
||
: MODEL_CATEGORY.IMAGE_TO_VIDEO
|
||
}
|
||
value={
|
||
selectedModel?.id || selectedModel?.model_name || selectedModel
|
||
}
|
||
onChange={setSelectedModel}
|
||
placeholder={t('请选择模型')}
|
||
autoSelectFirst={false}
|
||
onModelsLoaded={(models) => {
|
||
if (typeof selectedModel !== 'string' || !selectedModel) return;
|
||
const match = models.find(
|
||
(model) => model.model_name === selectedModel,
|
||
);
|
||
setSelectedModel(match || '');
|
||
}}
|
||
/>
|
||
</Form.Input>
|
||
|
||
{/* 提示词 */}
|
||
<Form.Label required>
|
||
<Text strong>{t('提示词')}</Text>
|
||
</Form.Label>
|
||
<Form.Input>
|
||
<TextArea
|
||
value={formData.prompt}
|
||
onChange={(value) => setFormData({ ...formData, prompt: value })}
|
||
placeholder={t('描述你想生成的视频内容')}
|
||
rows={3}
|
||
maxLength={2000}
|
||
showClear
|
||
/>
|
||
</Form.Input>
|
||
|
||
{/* 反向提示词 */}
|
||
<Form.Label>
|
||
<Text strong>{t('反向提示词')}</Text>
|
||
</Form.Label>
|
||
<Form.Input>
|
||
<TextArea
|
||
value={formData.negative_prompt}
|
||
onChange={(value) =>
|
||
setFormData({ ...formData, negative_prompt: value })
|
||
}
|
||
placeholder={t('描述不想出现的内容')}
|
||
rows={2}
|
||
maxLength={1000}
|
||
showClear
|
||
/>
|
||
</Form.Input>
|
||
|
||
{/* 分辨率 */}
|
||
<Form.Label>
|
||
<Text strong>{t('分辨率')}</Text>
|
||
</Form.Label>
|
||
<Form.Input>
|
||
<Select
|
||
value={formData.resolution}
|
||
onChange={(value) =>
|
||
setFormData({ ...formData, resolution: value })
|
||
}
|
||
style={{ width: '100%' }}
|
||
>
|
||
<Select.Option value='480P'>480P (832*480)</Select.Option>
|
||
<Select.Option value='720P'>720P (1280*720)</Select.Option>
|
||
<Select.Option value='1080P'>1080P (1920*1080)</Select.Option>
|
||
</Select>
|
||
</Form.Input>
|
||
|
||
{/* 时长 */}
|
||
<Form.Label>
|
||
<Text strong>{t('视频时长')}</Text>
|
||
</Form.Label>
|
||
<Form.Input>
|
||
<InputNumber
|
||
value={formData.duration}
|
||
onChange={(value) => setFormData({ ...formData, duration: value })}
|
||
min={3}
|
||
max={10}
|
||
suffix={t('秒')}
|
||
style={{ width: '100%' }}
|
||
/>
|
||
</Form.Input>
|
||
|
||
{/* 宽高比 */}
|
||
<Form.Label>
|
||
<Text strong>{t('宽高比')}</Text>
|
||
</Form.Label>
|
||
<Form.Input>
|
||
<Select
|
||
value={formData.ratio}
|
||
onChange={(value) => setFormData({ ...formData, ratio: value })}
|
||
style={{ width: '100%' }}
|
||
>
|
||
<Select.Option value='16:9'>{t('16:9 (横屏)')}</Select.Option>
|
||
<Select.Option value='9:16'>{t('9:16 (竖屏)')}</Select.Option>
|
||
<Select.Option value='1:1'>{t('1:1 (方形)')}</Select.Option>
|
||
</Select>
|
||
</Form.Input>
|
||
|
||
{/* 高级选项 */}
|
||
<Form.Label>
|
||
<Text strong>{t('高级选项')}</Text>
|
||
</Form.Label>
|
||
<Form.Input>
|
||
<Space vertical align='start' style={{ width: '100%' }}>
|
||
<Space>
|
||
<Switch
|
||
checked={formData.audio}
|
||
onChange={(checked) =>
|
||
setFormData({ ...formData, audio: checked })
|
||
}
|
||
/>
|
||
<Text>{t('生成音频')}</Text>
|
||
</Space>
|
||
<Space>
|
||
<Switch
|
||
checked={formData.prompt_extend}
|
||
onChange={(checked) =>
|
||
setFormData({ ...formData, prompt_extend: checked })
|
||
}
|
||
/>
|
||
<Text>{t('提示词扩展')}</Text>
|
||
</Space>
|
||
<Space>
|
||
<InputNumber
|
||
value={formData.seed}
|
||
onChange={(value) => setFormData({ ...formData, seed: value })}
|
||
placeholder={t('随机种子(可选)')}
|
||
min={0}
|
||
style={{ width: '100%', maxWidth: 200 }}
|
||
/>
|
||
<Text type='tertiary'>{t('固定种子可复现结果')}</Text>
|
||
</Space>
|
||
</Space>
|
||
</Form.Input>
|
||
</Form>
|
||
</Modal>
|
||
);
|
||
};
|
||
|
||
export default VideoRegenerateModal;
|