/*
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 .
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 (
{t('生成模式')}
{/* 模型选择 */}
{t('选择模型')}
{
if (typeof selectedModel !== 'string' || !selectedModel) return;
const match = models.find(
(model) => model.model_name === selectedModel,
);
setSelectedModel(match || '');
}}
/>
{/* 提示词 */}
{t('提示词')}
{/* 反向提示词 */}
{t('反向提示词')}
{/* 分辨率 */}
{t('分辨率')}
{/* 时长 */}
{t('视频时长')}
setFormData({ ...formData, duration: value })}
min={3}
max={10}
suffix={t('秒')}
style={{ width: '100%' }}
/>
{/* 宽高比 */}
{t('宽高比')}
{/* 高级选项 */}
{t('高级选项')}
setFormData({ ...formData, audio: checked })
}
/>
{t('生成音频')}
setFormData({ ...formData, prompt_extend: checked })
}
/>
{t('提示词扩展')}
setFormData({ ...formData, seed: value })}
placeholder={t('随机种子(可选)')}
min={0}
style={{ width: '100%', maxWidth: 200 }}
/>
{t('固定种子可复现结果')}
);
};
export default VideoRegenerateModal;