179 lines
4.7 KiB
JavaScript
179 lines
4.7 KiB
JavaScript
// components/PhoneInput.tsx
|
||
import {
|
||
Button,
|
||
Divider,
|
||
FormControl,
|
||
FormLabel,
|
||
HStack,
|
||
Icon,
|
||
Input,
|
||
Table,
|
||
TableContainer,
|
||
Tbody,
|
||
Textarea,
|
||
Th,
|
||
Thead,
|
||
Tr,
|
||
VStack,
|
||
} from "@chakra-ui/react";
|
||
import { TbFrame } from "react-icons/tb";
|
||
import { TbArrowGuide } from "react-icons/tb";
|
||
import { TbPrompt } from "react-icons/tb";
|
||
import { FaDraft2Digital, FaPlay } from "react-icons/fa";
|
||
import { useForm } from "react-hook-form";
|
||
import ResultBox from "../ui/ResultBox";
|
||
import axiosInstance, { baseUrl } from "@/lib/api";
|
||
import useSWRMutation from "swr/mutation";
|
||
import { useState } from "react";
|
||
|
||
const modelsDic = {
|
||
cogvideo_base: "base",
|
||
cogvideo_lora: "lora",
|
||
};
|
||
|
||
const postRequest = async (url, { arg }) => {
|
||
const response = await axiosInstance.post(baseUrl + url, arg);
|
||
return response?.data;
|
||
};
|
||
|
||
export default function TextVideoPanel({ filters }) {
|
||
const { register, handleSubmit } = useForm();
|
||
const [videos, setVideos] = useState([]);
|
||
|
||
const { trigger: triggerGenerateVideo, isMutating: isGeneratingVideo } =
|
||
useSWRMutation(
|
||
`/content/cogvideo/${modelsDic[filters?.tab_menu]}`,
|
||
postRequest,
|
||
{
|
||
onSuccess: (data) => setVideos(data?.videos),
|
||
},
|
||
);
|
||
|
||
const onSubmit = (data) => {
|
||
triggerGenerateVideo(data);
|
||
};
|
||
|
||
return (
|
||
<VStack
|
||
spacing={4}
|
||
w="100%"
|
||
h="100%"
|
||
alignItems="start"
|
||
overflowY="auto"
|
||
as={"form"}
|
||
onSubmit={handleSubmit(onSubmit)}
|
||
>
|
||
{" "}
|
||
<HStack>
|
||
<FormControl as={VStack} alignItems={"start"}>
|
||
<HStack alignItems={"start"}>
|
||
<Icon
|
||
as={TbFrame}
|
||
bgColor={"gray.200"}
|
||
borderRadius={"50%"}
|
||
p={"5px"}
|
||
fontSize={"25px"}
|
||
border={"1px"}
|
||
borderColor={"gray.300"}
|
||
/>
|
||
<FormLabel>تعداد فریم ها:</FormLabel>
|
||
</HStack>
|
||
<Input
|
||
bgColor={"white"}
|
||
{...register("num_frames")}
|
||
type="number"
|
||
defaultValue={31}
|
||
/>
|
||
</FormControl>
|
||
<FormControl as={VStack} alignItems={"start"}>
|
||
<FormLabel>seed:</FormLabel>
|
||
<Input
|
||
bgColor={"white"}
|
||
{...register("seed")}
|
||
type="number"
|
||
defaultValue={42}
|
||
/>
|
||
</FormControl>
|
||
|
||
<FormControl as={VStack} alignItems={"start"}>
|
||
<HStack alignItems={"start"}>
|
||
<Icon
|
||
as={TbArrowGuide}
|
||
bgColor={"gray.200"}
|
||
borderRadius={"50%"}
|
||
p={"5px"}
|
||
fontSize={"25px"}
|
||
border={"1px"}
|
||
borderColor={"gray.300"}
|
||
/>
|
||
<FormLabel>مقیاس راهنمایی:</FormLabel>
|
||
</HStack>
|
||
<Input
|
||
bgColor={"white"}
|
||
{...register("guidance_scale")}
|
||
type="number"
|
||
defaultValue={5.2}
|
||
/>
|
||
</FormControl>
|
||
<FormControl as={VStack} alignItems={"start"}>
|
||
<HStack alignItems={"start"}>
|
||
<Icon
|
||
as={FaDraft2Digital}
|
||
bgColor={"gray.200"}
|
||
borderRadius={"50%"}
|
||
p={"5px"}
|
||
fontSize={"25px"}
|
||
border={"1px"}
|
||
borderColor={"gray.300"}
|
||
/>
|
||
<FormLabel>تعداد مراحل استنتاج:</FormLabel>
|
||
</HStack>
|
||
<Input
|
||
bgColor={"white"}
|
||
{...register("num_inference_steps")}
|
||
type="number"
|
||
defaultValue={60}
|
||
/>
|
||
</FormControl>
|
||
</HStack>
|
||
<FormControl as={VStack} alignItems={"start"}>
|
||
<HStack alignItems={"start"}>
|
||
<Icon
|
||
as={TbPrompt}
|
||
bgColor={"gray.200"}
|
||
borderRadius={"50%"}
|
||
p={"5px"}
|
||
fontSize={"25px"}
|
||
border={"1px"}
|
||
borderColor={"gray.300"}
|
||
/>
|
||
<FormLabel>پرامپت:</FormLabel>
|
||
</HStack>
|
||
<Textarea bgColor={"white"} {...register("prompt")} />
|
||
</FormControl>
|
||
<Button
|
||
p={"20px"}
|
||
colorScheme="pink"
|
||
leftIcon={<FaPlay />}
|
||
type="submit"
|
||
isLoading={isGeneratingVideo}
|
||
>
|
||
اجرا
|
||
</Button>
|
||
<Divider my={"20px"} borderColor={"gray.300"} />
|
||
<TableContainer w={"100%"} mt={"10px"}>
|
||
<Table>
|
||
<Thead>
|
||
<Tr>
|
||
<Th fontSize={"md"}>ردیف</Th>
|
||
</Tr>
|
||
</Thead>
|
||
<Tbody></Tbody>
|
||
</Table>
|
||
</TableContainer>
|
||
<Divider my={"20px"} borderColor={"gray.300"} />
|
||
<ResultBox type="video" loading={isGeneratingVideo} resultData={videos} />
|
||
</VStack>
|
||
);
|
||
}
|