00Boobs00 commited on
Commit
43eb61c
·
verified ·
1 Parent(s): 106e469

Upload components/ComfyUI.js with huggingface_hub

Browse files
Files changed (1) hide show
  1. components/ComfyUI.js +87 -0
components/ComfyUI.js ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState } from 'react';
2
+ import { Image as ImageIcon, Loader2, Sparkles } from 'lucide-react';
3
+
4
+ export default function ComfyUI() {
5
+ const [prompt, setPrompt] = useState('');
6
+ const [loading, setLoading] = useState(false);
7
+ const [imageUrl, setImageUrl] = useState('');
8
+ const [error, setError] = useState('');
9
+
10
+ const handleGenerate = async () => {
11
+ if (!prompt.trim()) return;
12
+
13
+ setLoading(true);
14
+ setError('');
15
+ setImageUrl('');
16
+
17
+ try {
18
+ const response = await fetch('/api/comfy', {
19
+ method: 'POST',
20
+ headers: { 'Content-Type': 'application/json' },
21
+ body: JSON.stringify({ prompt }),
22
+ });
23
+
24
+ if (!response.ok) throw new Error('Failed to generate image');
25
+
26
+ const data = await response.json();
27
+ setImageUrl(data.url);
28
+ } catch (err) {
29
+ setError(err.message || 'Something went wrong');
30
+ } finally {
31
+ setLoading(false);
32
+ }
33
+ };
34
+
35
+ return (
36
+ <div className="bg-slate-800 rounded-xl p-6 shadow-xl border border-slate-700">
37
+ <div className="flex items-center gap-2 mb-4">
38
+ <ImageIcon className="w-5 h-5 text-pink-500" />
39
+ <h2 className="text-lg font-semibold text-white">ComfyUI Image Gen</h2>
40
+ </div>
41
+
42
+ <div className="space-y-4">
43
+ <div>
44
+ <label className="block text-sm font-medium text-slate-400 mb-1">
45
+ Prompt
46
+ </label>
47
+ <textarea
48
+ value={prompt}
49
+ onChange={(e) => setPrompt(e.target.value)}
50
+ placeholder="A futuristic cyberpunk city with neon lights..."
51
+ className="w-full bg-slate-900 border border-slate-600 rounded-lg p-3 text-white placeholder-slate-500 focus:ring-2 focus:ring-pink-500 focus:border-transparent outline-none transition-all resize-none h-24"
52
+ />
53
+ </div>
54
+
55
+ <button
56
+ onClick={handleGenerate}
57
+ disabled={loading}
58
+ className="w-full bg-gradient-to-r from-pink-600 to-purple-600 hover:from-pink-500 hover:to-purple-500 text-white font-medium py-2.5 rounded-lg transition-all flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed"
59
+ >
60
+ {loading ? (
61
+ <>
62
+ <Loader2 className="w-4 h-4 animate-spin" />
63
+ Generating...
64
+ </>
65
+ ) : (
66
+ <>
67
+ <Sparkles className="w-4 h-4" />
68
+ Generate Image
69
+ </>
70
+ )}
71
+ </button>
72
+
73
+ {error && (
74
+ <div className="bg-red-900/30 text-red-400 p-3 rounded-lg text-sm border border-red-800">
75
+ {error}
76
+ </div>
77
+ )}
78
+
79
+ {imageUrl && (
80
+ <div className="mt-4 border border-slate-600 rounded-lg overflow-hidden bg-slate-900">
81
+ <img src={imageUrl} alt="Generated content" className="w-full h-auto object-cover" />
82
+ </div>
83
+ )}
84
+ </div>
85
+ </div>
86
+ );
87
+ }