'use client'; import { useEffect, useState } from 'react'; import Link from 'next/link'; import { Header, AppLayout } from '@/components/layout'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { apiClient } from '@/lib/api'; import { ProtectedRoute } from '@/components/auth/protected-route'; import { useAuth } from '@/lib/auth-context'; import { ImagePlus, Image, Sparkles, Settings, Activity, ArrowRight, CheckCircle2, XCircle, User, LogOut } from 'lucide-react'; const features = [ { title: 'Text to Image', description: 'Generate stunning images from text descriptions using Stable Diffusion', icon: ImagePlus, href: '/text2img', color: 'text-blue-500', }, { title: 'Image to Image', description: 'Transform existing images with AI-powered modifications', icon: Image, href: '/img2img', color: 'text-purple-500', }, { title: 'Upscaler', description: 'Enhance and upscale your images for higher quality results', icon: Sparkles, href: '/upscaler', color: 'text-green-500', }, { title: 'Model Management', description: 'Load, unload, and manage your AI models efficiently', icon: Settings, href: '/models', color: 'text-orange-500', }, { title: 'Queue Monitor', description: 'Track and manage your generation jobs in real-time', icon: Activity, href: '/queue', color: 'text-pink-500', }, ]; export default function HomePage() { const { user, logout, isAuthenticated, isLoading, authEnabled } = useAuth(); const [health, setHealth] = useState<'checking' | 'healthy' | 'error'>('checking'); const [systemInfo, setSystemInfo] = useState<{ version?: string; cuda_available?: boolean } | null>(null); const checkHealth = async () => { try { await apiClient.getHealth(); setTimeout(() => setHealth('healthy'), 0); } catch (err) { console.error('Health check failed:', err); setTimeout(() => setHealth('error'), 0); } }; const loadSystemInfo = async () => { try { const info = await apiClient.getSystemInfo(); setTimeout(() => setSystemInfo(info), 0); } catch (err) { console.error('Failed to load system info:', err); } }; useEffect(() => { // Check health and system info regardless of authentication status checkHealth(); loadSystemInfo(); // Set up periodic health checks with proper cleanup const healthInterval = setInterval(checkHealth, 30000); // Check every 30 seconds const systemInfoInterval = setInterval(loadSystemInfo, 60000); // Check every minute return () => { clearInterval(healthInterval); clearInterval(systemInfoInterval); }; }, []); // Show loading state while checking authentication if (isLoading) { return (

Loading...

); } return (
{user?.username} ({user?.role})
) } />
{/* Status Banner */}
{health === 'checking' ? ( <>
Checking API status... ) : health === 'healthy' ? ( <> API is running ) : ( <> Cannot connect to API )}
{systemInfo && (
{systemInfo.version && v{systemInfo.version}} {systemInfo.cuda_available !== undefined && ( CUDA: {systemInfo.cuda_available ? 'Available' : 'Not Available'} )}
)} {/* Welcome Section */}

Welcome to SD REST UI

A modern, intuitive interface for Stable Diffusion image generation

{/* Features Grid */}
{features.map((feature) => (
{feature.title}
{feature.description}
))}
{/* Quick Start Guide */} Quick Start Guide Get started with image generation in a few simple steps
1

Load a Model

Navigate to Model Management and load your preferred checkpoint

2

Choose Generation Type

Select Text to Image, Image to Image, or Upscaler

3

Generate & Monitor

Start generation and track progress in the Queue Monitor

{/* API Info */} API Configuration Backend API connection details
API URL:
{process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8080'}
Base Path:
{process.env.NEXT_PUBLIC_API_BASE_PATH || '/api/v1'}
Status:
{health === 'healthy' ? ( Connected ) : health === 'error' ? ( Disconnected ) : ( Checking... )}
); }