diff --git a/.env b/.env index bfd53f1..20388ea 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -NEXT_PUBLIC_BASE_URL=http://192.168.10.87:8070/generative +NEXT_PUBLIC_BASE_URL=https://api.d.aiengines.ir/generative_api diff --git a/components/tabs/textImagePanel.js b/components/tabs/textImagePanel.js index 5306dd4..4d6fa85 100644 --- a/components/tabs/textImagePanel.js +++ b/components/tabs/textImagePanel.js @@ -24,15 +24,37 @@ import { FaDraft2Digital, FaPlay } from "react-icons/fa"; import { useState } from "react"; import { useForm } from "react-hook-form"; import ResultBox from "../ui/ResultBox"; +import axiosInstance, { baseUrl } from "@/lib/api"; +import useSWRMutation from "swr/mutation"; -export default function TextImagePanel() { - const { register, handleSubmit } = useForm(""); +const modelsDic = { + sdxl: "base", + sdxl_lora: "lora", +}; - const [height, setHeight] = useState(""); - const [width, setWidth] = useState(""); +const postRequest = async (url, { arg }) => { + const response = await axiosInstance.post(baseUrl + url, arg); + return response?.data; +}; - const addSubmit = (e) => { - console.log(e); +export default function TextImagePanel({ filters }) { + const { register, handleSubmit, watch } = useForm(""); + const [images, setImages] = useState([]); + + const width = watch("width"); + const height = watch("height"); + + const { trigger: triggerGenerateImage, isMutating: isGeneratingImage } = + useSWRMutation( + `/content/sdxl/${modelsDic[filters?.tab_menu]}`, + postRequest, + { + onSuccess: (data) => setImages(data?.images), + }, + ); + + const onSubmit = (data) => { + triggerGenerateImage(data); }; return ( @@ -43,7 +65,7 @@ export default function TextImagePanel() { alignItems="start" overflowY="auto" as={"form"} - onSubmit={handleSubmit(addSubmit)} + onSubmit={handleSubmit(onSubmit)} > {" "} @@ -60,7 +82,7 @@ export default function TextImagePanel() { /> طول: - + @@ -75,11 +97,11 @@ export default function TextImagePanel() { /> عرض: - + seed: - + @@ -96,7 +118,11 @@ export default function TextImagePanel() { /> تعداد مراحل استنتاج: - + @@ -109,9 +135,13 @@ export default function TextImagePanel() { border={"1px"} borderColor={"gray.300"} /> - تعداد: + مقیاس راهنمایی: - + @@ -144,7 +174,13 @@ export default function TextImagePanel() { - + ); } diff --git a/components/ui/ResultBox.jsx b/components/ui/ResultBox.jsx index a03b899..bf88f5e 100644 --- a/components/ui/ResultBox.jsx +++ b/components/ui/ResultBox.jsx @@ -1,4 +1,14 @@ -import { Box, Heading, HStack, Icon, Text } from "@chakra-ui/react"; +import { + AspectRatio, + Box, + Heading, + HStack, + Icon, + Image, + Skeleton, + Text, + VStack, +} from "@chakra-ui/react"; import { FaBolt } from "react-icons/fa"; import ChatTypingLoader from "../loading/ChatTypingLoader"; import { @@ -15,7 +25,13 @@ const iconsDic = { video: IoVideocamOutline, }; -function ResultBox({ type = "llm", loading = false, resultData = "" }) { +function ResultBox({ + type = "llm", + loading = false, + resultData = "", + imgWidth, + imgHeight, +}) { return ( - {loading && ( + {loading && type === "llm" && ( )} + + {type === "image" && loading && ( + + + در حال تولید تصویر... + + + + + )} + + {type === "image" && !loading && resultData?.[0] && ( + + + + )} ); diff --git a/pages/index.js b/pages/index.js index 29c916a..76b8e23 100644 --- a/pages/index.js +++ b/pages/index.js @@ -179,7 +179,7 @@ export default function Home() { - +