00Boobs00 commited on
Commit
37e516b
·
verified ·
1 Parent(s): ac82073

Upload components/ComfyUI.js with huggingface_hub

Browse files
Files changed (1) hide show
  1. components/ComfyUI.js +98 -0
components/ComfyUI.js ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState } from 'react';
2
+ import { Image as ImageIcon, Loader2, Sparkles, Download } 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 justify-between mb-4">
38
+ <div className="flex items-center gap-2">
39
+ <ImageIcon className="w-5 h-5 text-pink-500" />
40
+ <h2 className="text-lg font-semibold text-white">ComfyUI Image Gen</h2>
41
+ </div>
42
+ </div>
43
+
44
+ <div className="space-y-4">
45
+ <div>
46
+ <label className="block text-sm font-medium text-slate-400 mb-1">
47
+ Prompt
48
+ </label>
49
+ <textarea
50
+ value={prompt}
51
+ onChange={(e) => setPrompt(e.target.value)}
52
+ placeholder="A futuristic cyberpunk city with neon lights..."
53
+ 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"
54
+ />
55
+ </div>
56
+
57
+ <button
58
+ onClick={handleGenerate}
59
+ disabled={loading}
60
+ 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 shadow-lg shadow-pink-900/20"
61
+ >
62
+ {loading ? (
63
+ <>
64
+ <Loader2 className="w-4 h-4 animate-spin" />
65
+ Generating...
66
+ </>
67
+ ) : (
68
+ <>
69
+ <Sparkles className="w-4 h-4" />
70
+ Generate Image
71
+ </>
72
+ )}
73
+ </button>
74
+
75
+ {error && (
76
+ <div className="bg-red-900/30 text-red-400 p-3 rounded-lg text-sm border border-red-800 flex items-center gap-2">
77
+ <span>⚠️ {error}</span>
78
+ </div>
79
+ )}
80
+
81
+ {imageUrl && (
82
+ <div className="mt-4 border border-slate-600 rounded-lg overflow-hidden bg-slate-900 relative group">
83
+ <img src={imageUrl} alt="Generated content" className="w-full h-auto object-cover min-h-[200px]" />
84
+ <a
85
+ href={imageUrl}
86
+ download="generated-image.jpg"
87
+ target="_blank"
88
+ className="absolute top-2 right-2 bg-black/50 hover:bg-black/70 text-white p-2 rounded-lg opacity-0 group-hover:opacity-100 transition-opacity"
89
+ title="Download Image"
90
+ >
91
+ <Download className="w-4 h-4" />
92
+ </a>
93
+ </div>
94
+ )}
95
+ </div>
96
+ </div>
97
+ );
98
+ }