page.tsx 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. 'use client';
  2. import { useEffect, useState } from 'react';
  3. import Link from 'next/link';
  4. import { Header } from '@/components/header';
  5. import { AppLayout } from '@/components/layout';
  6. import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
  7. import { Button } from '@/components/ui/button';
  8. import { apiClient } from '@/lib/api';
  9. import { ProtectedRoute } from '@/components/auth/protected-route';
  10. import { useAuth } from '@/lib/auth-context';
  11. import { ImagePlus, Image, Sparkles, Settings, Activity, ArrowRight, CheckCircle2, XCircle, User, LogOut } from 'lucide-react';
  12. const features = [
  13. {
  14. title: 'Text to Image',
  15. description: 'Generate stunning images from text descriptions using Stable Diffusion',
  16. icon: ImagePlus,
  17. href: '/text2img',
  18. color: 'text-blue-500',
  19. },
  20. {
  21. title: 'Image to Image',
  22. description: 'Transform existing images with AI-powered modifications',
  23. icon: Image,
  24. href: '/img2img',
  25. color: 'text-purple-500',
  26. },
  27. {
  28. title: 'Upscaler',
  29. description: 'Enhance and upscale your images for higher quality results',
  30. icon: Sparkles,
  31. href: '/upscaler',
  32. color: 'text-green-500',
  33. },
  34. {
  35. title: 'Model Management',
  36. description: 'Load, unload, and manage your AI models efficiently',
  37. icon: Settings,
  38. href: '/models',
  39. color: 'text-orange-500',
  40. },
  41. {
  42. title: 'Queue Monitor',
  43. description: 'Track and manage your generation jobs in real-time',
  44. icon: Activity,
  45. href: '/queue',
  46. color: 'text-pink-500',
  47. },
  48. ];
  49. export default function HomePage() {
  50. const { user, logout } = useAuth();
  51. const [health, setHealth] = useState<'checking' | 'healthy' | 'error'>('checking');
  52. const [systemInfo, setSystemInfo] = useState<any>(null);
  53. useEffect(() => {
  54. checkHealth();
  55. loadSystemInfo();
  56. }, []);
  57. const checkHealth = async () => {
  58. try {
  59. await apiClient.getHealth();
  60. setHealth('healthy');
  61. } catch (err) {
  62. setHealth('error');
  63. }
  64. };
  65. const loadSystemInfo = async () => {
  66. try {
  67. const info = await apiClient.getSystemInfo();
  68. setSystemInfo(info);
  69. } catch (err) {
  70. console.error('Failed to load system info:', err);
  71. }
  72. };
  73. return (
  74. <ProtectedRoute>
  75. <AppLayout>
  76. <Header
  77. title="Stable Diffusion REST"
  78. description="Modern web interface for AI image generation"
  79. actions={
  80. <div className="flex items-center gap-4">
  81. <div className="flex items-center gap-2 text-sm">
  82. <User className="h-4 w-4" />
  83. <span>{user?.username}</span>
  84. <span className="text-muted-foreground">({user?.role})</span>
  85. </div>
  86. <Button variant="outline" size="sm" onClick={logout}>
  87. <LogOut className="h-4 w-4 mr-2" />
  88. Sign Out
  89. </Button>
  90. <Link href="/settings">
  91. <Button variant="outline" size="sm">
  92. <Settings className="h-4 w-4 mr-2" />
  93. Settings
  94. </Button>
  95. </Link>
  96. </div>
  97. }
  98. />
  99. <div className="container mx-auto p-6">
  100. <div className="space-y-8">
  101. {/* Status Banner */}
  102. <Card>
  103. <CardContent className="flex items-center justify-between p-6">
  104. <div className="flex items-center gap-3">
  105. {health === 'checking' ? (
  106. <>
  107. <div className="h-3 w-3 animate-pulse rounded-full bg-yellow-500" />
  108. <span className="text-sm">Checking API status...</span>
  109. </>
  110. ) : health === 'healthy' ? (
  111. <>
  112. <CheckCircle2 className="h-5 w-5 text-green-500" />
  113. <span className="text-sm font-medium">API is running</span>
  114. </>
  115. ) : (
  116. <>
  117. <XCircle className="h-5 w-5 text-red-500" />
  118. <span className="text-sm font-medium text-destructive">
  119. Cannot connect to API
  120. </span>
  121. </>
  122. )}
  123. </div>
  124. {systemInfo && (
  125. <div className="flex gap-4 text-sm text-muted-foreground">
  126. {systemInfo.version && <span>v{systemInfo.version}</span>}
  127. {systemInfo.cuda_available !== undefined && (
  128. <span>CUDA: {systemInfo.cuda_available ? 'Available' : 'Not Available'}</span>
  129. )}
  130. </div>
  131. )}
  132. </CardContent>
  133. </Card>
  134. {/* Welcome Section */}
  135. <div className="text-center">
  136. <h1 className="text-4xl font-bold tracking-tight">Welcome to SD REST UI</h1>
  137. <p className="mt-4 text-lg text-muted-foreground">
  138. A modern, intuitive interface for Stable Diffusion image generation
  139. </p>
  140. </div>
  141. {/* Features Grid */}
  142. <div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
  143. {features.map((feature) => (
  144. <Card key={feature.href} className="group relative overflow-hidden transition-all hover:shadow-lg">
  145. <CardHeader>
  146. <div className="flex items-center gap-3">
  147. <div className={`rounded-lg bg-muted p-2 ${feature.color}`}>
  148. <feature.icon className="h-6 w-6" />
  149. </div>
  150. <CardTitle className="text-xl">{feature.title}</CardTitle>
  151. </div>
  152. <CardDescription className="mt-2">{feature.description}</CardDescription>
  153. </CardHeader>
  154. <CardContent>
  155. <Link href={feature.href}>
  156. <Button variant="ghost" className="w-full justify-between group-hover:bg-accent">
  157. Get Started
  158. <ArrowRight className="h-4 w-4 transition-transform group-hover:translate-x-1" />
  159. </Button>
  160. </Link>
  161. </CardContent>
  162. </Card>
  163. ))}
  164. </div>
  165. {/* Quick Start Guide */}
  166. <Card>
  167. <CardHeader>
  168. <CardTitle>Quick Start Guide</CardTitle>
  169. <CardDescription>Get started with image generation in a few simple steps</CardDescription>
  170. </CardHeader>
  171. <CardContent className="space-y-4">
  172. <div className="flex gap-4">
  173. <div className="flex h-8 w-8 items-center justify-center rounded-full bg-primary text-primary-foreground font-semibold">
  174. 1
  175. </div>
  176. <div className="flex-1">
  177. <h4 className="font-medium">Load a Model</h4>
  178. <p className="text-sm text-muted-foreground">
  179. Navigate to <Link href="/models" className="text-primary hover:underline">Model Management</Link> and load your preferred checkpoint
  180. </p>
  181. </div>
  182. </div>
  183. <div className="flex gap-4">
  184. <div className="flex h-8 w-8 items-center justify-center rounded-full bg-primary text-primary-foreground font-semibold">
  185. 2
  186. </div>
  187. <div className="flex-1">
  188. <h4 className="font-medium">Choose Generation Type</h4>
  189. <p className="text-sm text-muted-foreground">
  190. Select <Link href="/text2img" className="text-primary hover:underline">Text to Image</Link>, <Link href="/img2img" className="text-primary hover:underline">Image to Image</Link>, or <Link href="/upscaler" className="text-primary hover:underline">Upscaler</Link>
  191. </p>
  192. </div>
  193. </div>
  194. <div className="flex gap-4">
  195. <div className="flex h-8 w-8 items-center justify-center rounded-full bg-primary text-primary-foreground font-semibold">
  196. 3
  197. </div>
  198. <div className="flex-1">
  199. <h4 className="font-medium">Generate & Monitor</h4>
  200. <p className="text-sm text-muted-foreground">
  201. Start generation and track progress in the <Link href="/queue" className="text-primary hover:underline">Queue Monitor</Link>
  202. </p>
  203. </div>
  204. </div>
  205. </CardContent>
  206. </Card>
  207. {/* API Info */}
  208. <Card>
  209. <CardHeader>
  210. <CardTitle>API Configuration</CardTitle>
  211. <CardDescription>Backend API connection details</CardDescription>
  212. </CardHeader>
  213. <CardContent>
  214. <dl className="grid gap-3 text-sm">
  215. <div className="flex justify-between">
  216. <dt className="text-muted-foreground">API URL:</dt>
  217. <dd className="font-mono">{process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8080'}</dd>
  218. </div>
  219. <div className="flex justify-between">
  220. <dt className="text-muted-foreground">Base Path:</dt>
  221. <dd className="font-mono">{process.env.NEXT_PUBLIC_API_BASE_PATH || '/api/v1'}</dd>
  222. </div>
  223. <div className="flex justify-between">
  224. <dt className="text-muted-foreground">Status:</dt>
  225. <dd>
  226. {health === 'healthy' ? (
  227. <span className="text-green-600 dark:text-green-400">Connected</span>
  228. ) : health === 'error' ? (
  229. <span className="text-destructive">Disconnected</span>
  230. ) : (
  231. <span className="text-yellow-600 dark:text-yellow-400">Checking...</span>
  232. )}
  233. </dd>
  234. </div>
  235. </dl>
  236. </CardContent>
  237. </Card>
  238. </div>
  239. </div>
  240. </AppLayout>
  241. </ProtectedRoute>
  242. );
  243. }