Spaces:
Sleeping
Sleeping
File size: 18,252 Bytes
64fa001 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | "use client"
import { useState, useTransition } from "react"
import { useRouter } from "next/navigation"
import Image from "next/image"
import { Button } from "@/components/ui/button"
import { Label } from "@/components/ui/label"
import { Textarea } from "@/components/ui/textarea"
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select"
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import { Loader2, Download, Sparkles, AlertCircle, Wand2 } from "lucide-react"
export default function CreatePage() {
const router = useRouter()
const [isPending, startTransition] = useTransition()
const [prompt, setPrompt] = useState("")
const [model, setModel] = useState("flux-dev")
const [width, setWidth] = useState("1024")
const [height, setHeight] = useState("1024")
const [isCustomWidth, setIsCustomWidth] = useState(false)
const [isCustomHeight, setIsCustomHeight] = useState(false)
const [resultUrl, setResultUrl] = useState<string | null>(null)
const [error, setError] = useState<string | null>(null)
async function handleGenerate() {
if (!prompt) return
setError(null)
setResultUrl(null)
startTransition(async () => {
try {
const res = await fetch("/api/generate", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
prompt,
model,
width: parseInt(width),
height: parseInt(height),
}),
})
const data = await res.json()
if (!res.ok) {
setError(data.error || "Generation failed")
} else if (data.url) {
setResultUrl(data.url)
router.refresh() // Update credits in navbar
} else {
setError("No image URL returned")
}
} catch (err) {
setError("Something went wrong")
}
})
}
return (
<div className="container py-8 md:py-16 max-w-7xl min-h-[calc(100vh-4rem)]">
{/* Background elements */}
<div className="fixed inset-0 -z-20 mesh-gradient opacity-30 dark:opacity-20" />
<div className="grid grid-cols-1 lg:grid-cols-5 gap-8 items-start">
{/* Left Column: Control Panel */}
<div className="lg:col-span-2 space-y-6">
<div className="space-y-1 pl-1">
<h1 className="text-4xl font-black tracking-tighter uppercase text-stroke text-transparent bg-clip-text bg-gradient-to-br from-foreground to-muted-foreground">Studio</h1>
<p className="text-sm font-bold text-muted-foreground uppercase tracking-widest">
Cost: 5 Credits / Gen
</p>
</div>
<div className="glass-panel p-6 rounded-none space-y-6 relative overflow-hidden group">
<div className="absolute top-0 right-0 w-24 h-24 bg-primary/10 rounded-full blur-2xl group-hover:bg-primary/20 transition-all duration-500" />
<div className="space-y-4">
<div className="space-y-2">
<Label htmlFor="model" className="uppercase text-xs font-bold tracking-wider">Model Architecture</Label>
<Select value={model} onValueChange={setModel}>
<SelectTrigger id="model" className="h-12 border-2 border-border rounded-none font-bold focus:ring-offset-0 focus:ring-0 focus:border-primary bg-background/50">
<SelectValue placeholder="Select model" />
</SelectTrigger>
<SelectContent className="rounded-none border-2 border-border neo-brutalist">
<SelectItem value="flux-dev" className="font-medium focus:bg-primary/20">Flux 2 Dev</SelectItem>
<SelectItem value="flux-klein-9b" className="font-medium focus:bg-primary/20">Flux Klein 9B</SelectItem>
<SelectItem value="flux-klein-4b" className="font-medium focus:bg-primary/20">Flux Klein 4B</SelectItem>
<SelectItem value="lucid-origin" className="font-medium focus:bg-primary/20">Lucid Origin</SelectItem>
<SelectItem value="dreamshaper" className="font-medium focus:bg-primary/20">DreamShaper 8</SelectItem>
<SelectItem value="stable-diffusion-xl-lightning" className="font-medium focus:bg-primary/20">SDXL Lightning (Fast)</SelectItem>
</SelectContent>
</Select>
</div>
<div className="grid grid-cols-2 gap-4">
<div className="space-y-2">
<Label htmlFor="width" className="uppercase text-xs font-bold tracking-wider">Width</Label>
<Select
value={isCustomWidth ? "custom" : width}
onValueChange={(val) => {
if (val === "custom") setIsCustomWidth(true)
else {
setIsCustomWidth(false)
setWidth(val)
}
}}
>
<SelectTrigger id="width" className="h-12 border-2 border-border rounded-none font-bold bg-background/50">
<SelectValue placeholder="Width" />
</SelectTrigger>
<SelectContent className="rounded-none border-2 border-border neo-brutalist">
<SelectItem value="512">512px</SelectItem>
<SelectItem value="768">768px</SelectItem>
<SelectItem value="1024">1024px</SelectItem>
<SelectItem value="custom" className="text-primary font-bold">Custom...</SelectItem>
</SelectContent>
</Select>
{/* Custom Input */}
{isCustomWidth && (
<input
type="number"
value={width}
onChange={(e) => setWidth(e.target.value)}
className="w-full h-10 border-2 border-primary/50 rounded-none px-3 font-medium text-sm bg-background mt-2 focus:outline-none focus:border-primary transition-colors"
placeholder="Width (256-1440)"
min="256"
max="1440"
step="32"
/>
)}
</div>
<div className="space-y-2">
<Label htmlFor="height" className="uppercase text-xs font-bold tracking-wider">Height</Label>
<Select
value={isCustomHeight ? "custom" : height}
onValueChange={(val) => {
if (val === "custom") setIsCustomHeight(true)
else {
setIsCustomHeight(false)
setHeight(val)
}
}}
>
<SelectTrigger id="height" className="h-12 border-2 border-border rounded-none font-bold bg-background/50">
<SelectValue placeholder="Height" />
</SelectTrigger>
<SelectContent className="rounded-none border-2 border-border neo-brutalist">
<SelectItem value="512">512px</SelectItem>
<SelectItem value="768">768px</SelectItem>
<SelectItem value="1024">1024px</SelectItem>
<SelectItem value="custom" className="text-primary font-bold">Custom...</SelectItem>
</SelectContent>
</Select>
{/* Custom Input */}
{isCustomHeight && (
<input
type="number"
value={height}
onChange={(e) => setHeight(e.target.value)}
className="w-full h-10 border-2 border-primary/50 rounded-none px-3 font-medium text-sm bg-background mt-2 focus:outline-none focus:border-primary transition-colors"
placeholder="Height (256-1440)"
min="256"
max="1440"
step="32"
/>
)}
</div>
</div>
<div className="space-y-2 pt-2">
<Label htmlFor="prompt" className="uppercase text-xs font-bold tracking-wider flex justify-between">
Prompt
<span className="text-muted-foreground text-[10px] font-normal tracking-normal normal-case">Be descriptive for best results</span>
</Label>
<Textarea
id="prompt"
placeholder="Describe your imagination in detail... (e.g. A futuristic neon city with flying cars, cyberpunk style, cinematic lighting)"
className="min-h-[140px] resize-none border-2 border-border rounded-none font-medium bg-background/50 focus-visible:ring-0 focus-visible:border-primary p-4 leading-relaxed"
value={prompt}
onChange={(e) => setPrompt(e.target.value)}
/>
</div>
{error && (
<div className="p-4 text-sm font-bold text-destructive bg-destructive/10 border-2 border-destructive/20 flex items-center gap-2 animate-in slide-in-from-left-2">
<AlertCircle className="h-4 w-4" />
{error}
</div>
)}
</div>
<div className="pt-2">
<Button
onClick={handleGenerate}
className="w-full h-14 text-lg bg-primary hover:bg-primary/90 text-primary-foreground font-black uppercase tracking-widest rounded-none md:neo-brutalist"
disabled={isPending || !prompt}
>
{isPending ? (
<>
<Loader2 className="mr-3 h-5 w-5 animate-spin" />
Dreaming...
</>
) : (
<>
<Wand2 className="mr-3 h-5 w-5" />
Generate Art
</>
)}
</Button>
</div>
</div>
</div>
{/* Right Column: Canvas */}
<div className="lg:col-span-3 h-full">
<div className="h-full min-h-[500px] glass-panel rounded-none p-2 md:p-4 flex flex-col relative group">
<div className="absolute top-0 left-0 w-full h-1 bg-gradient-to-r from-primary via-secondary to-accent opacity-50" />
<div className="flex-1 flex items-center justify-center bg-secondary/5 border-2 border-dashed border-border/30 relative overflow-hidden min-h-[400px]">
{/* Grid Pattern Background */}
<div className="absolute inset-0 bg-[linear-gradient(to_right,#80808012_1px,transparent_1px),linear-gradient(to_bottom,#80808012_1px,transparent_1px)] bg-[size:24px_24px] pointer-events-none" />
{resultUrl ? (
<div className="relative w-full h-full min-h-[inherit] flex items-center justify-center p-4">
<Image
src={resultUrl}
alt={prompt}
width={1024}
height={1024}
className="object-contain max-h-[70vh] w-auto h-auto shadow-2xl border-4 border-black dark:border-white"
unoptimized
/>
<div className="absolute bottom-4 right-4 flex gap-3 opacity-0 group-hover:opacity-100 transition-opacity duration-300">
<Button variant="secondary" className="neo-brutalist h-10 w-10 p-0 rounded-full" asChild>
<a href={resultUrl} target="_blank" rel="noopener noreferrer">
<Sparkles className="h-4 w-4" />
</a>
</Button>
<Button className="neo-brutalist h-10 w-10 p-0 rounded-full bg-primary text-white" asChild>
<a href={resultUrl} download="wild-art-generated.png">
<Download className="h-4 w-4" />
</a>
</Button>
</div>
</div>
) : (
<div className="text-center text-muted-foreground p-8 max-w-sm relative z-10">
{isPending ? (
<div className="flex flex-col items-center gap-6">
<div className="relative">
<div className="absolute inset-0 bg-primary/20 blur-xl animate-pulse rounded-full" />
<Loader2 className="h-16 w-16 animate-spin text-primary relative z-10" />
</div>
<div className="space-y-2">
<p className="font-bold text-xl animate-pulse text-foreground">Materializing...</p>
<p className="text-xs uppercase tracking-widest opacity-70">Computing Tensors • Denoising • Upscaling</p>
</div>
</div>
) : (
<div className="flex flex-col items-center gap-4 group/placeholder cursor-default">
<div className="h-24 w-24 rounded-full bg-secondary/20 flex items-center justify-center mb-4 group-hover/placeholder:scale-110 transition-transform duration-500 border-2 border-dashed border-muted-foreground/30">
<Sparkles className="h-10 w-10 text-muted-foreground/50" />
</div>
<h3 className="font-bold text-xl text-foreground">Canvas Empty</h3>
<p className="text-sm leading-relaxed opacity-70">
Your imagination is the only limit.<br />
Configure the settings on the left and hit <span className="text-primary font-bold">GENERATE</span>.
</p>
</div>
)}
</div>
)}
</div>
</div>
</div>
</div>
</div>
)
}
|