"use client"; import { LoadingIcon } from "@/components/LoadingIcon"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Skeleton } from "@/components/ui/skeleton"; import { checkStatus, generate, generate_img, getUploadUrl, } from "@/server/generate"; import { useEffect, useState } from "react"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; export default function Page() { return ( txt2img img2img ); } export function Txt2img() { const [prompt, setPrompt] = useState(""); const [image, setImage] = useState(""); const [loading, setLoading] = useState(false); const [runId, setRunId] = useState(""); const [status, setStatus] = useState(); // Polling in frontend to check for the useEffect(() => { if (!runId) return; const interval = setInterval(() => { checkStatus(runId).then((res) => { if (res) setStatus(res.status); if (res && res.status === "success") { console.log(res.outputs[0]?.data); setImage(res.outputs[0]?.data?.images[0].url); setLoading(false); clearInterval(interval); } }); }, 2000); return () => clearInterval(interval); }, [runId]); return ( Comfy Deploy - Vector Line Art Tool Lora -{" "} stick-line-vector-illustration { if (loading) return; e.preventDefault(); setLoading(true); generate(prompt).then((res) => { console.log(res); if (!res) { setStatus("error"); setLoading(false); return; } setRunId(res.run_id); }); setStatus("preparing"); }} > Image prompt setPrompt(e.target.value)} /> Generate {loading && } {!loading && image && ( )} {!image && status && ( {status} )} {loading && } ); } export function Img2img() { const [prompt, setPrompt] = useState(); const [image, setImage] = useState(""); const [loading, setLoading] = useState(false); const [runId, setRunId] = useState(""); const [status, setStatus] = useState(); const handleFileChange = (e: React.ChangeEvent) => { setPrompt(e.target.files[0]); }; // Polling in frontend to check for the useEffect(() => { if (!runId) return; const interval = setInterval(() => { checkStatus(runId).then((res) => { if (res) setStatus(res.status); if (res && res.status === "success") { console.log(res.outputs[0]?.data); setImage(res.outputs[0]?.data?.images[0].url); setLoading(false); clearInterval(interval); } }); }, 2000); return () => clearInterval(interval); }, [runId]); return ( Comfy Deploy - Vector Line Art Tool Lora -{" "} stick-line-vector-illustration { e.preventDefault() if (loading) return; if (!prompt) return; setImage(""); setStatus("getting url for upload"); console.log(prompt?.type, prompt?.size); getUploadUrl(prompt?.type, prompt?.size).then((res) => { if (!res) return; setStatus("uploading input"); console.log(res); fetch(res.upload_url, { method: "PUT", body: prompt, headers: { "Content-Type": prompt.type, "x-amz-acl": "public-read", "Content-Length": prompt.size.toString(), }, }).then((_res) => { if (_res.ok) { setStatus("uploaded input"); setLoading(true); generate_img(res.download_url).then((res) => { console.log(res); if (!res) { setStatus("error"); setLoading(false); return; } setRunId(res.run_id); }); setStatus("preparing"); } }); }); }} > Image prompt Generate {loading && } {!loading && image && ( )} {!image && status && ( {status} )} {loading && } ); }