Spaces:
Running
Running
refactor: simplify Listing Free UI — Gradio URL, upload, count, manual/auto mode, config, generate
Browse files- frontend/src/pages/ListingFree.jsx +186 -413
frontend/src/pages/ListingFree.jsx
CHANGED
|
@@ -1,13 +1,6 @@
|
|
| 1 |
import { useState, useRef, useEffect } from "react";
|
| 2 |
-
import { IcImage, IcUpload, IcDownload, IcRefresh,
|
| 3 |
|
| 4 |
-
const TEMPLATES = [
|
| 5 |
-
{ id: "simple", name: "Simple Poster", desc: "Eyebrow + headline + subhead + tag — classic elegance" },
|
| 6 |
-
{ id: "multicolor", name: "Multicolor Headline", desc: "Stacked words with per-word colors + badge" },
|
| 7 |
-
{ id: "feature_panel", name: "Feature Panel", desc: "Rounded side panel with title + icon rows" },
|
| 8 |
-
];
|
| 9 |
-
const ICON_OPTIONS = ["check", "leaf", "drop", "sun", "shield", "sparkle"];
|
| 10 |
-
const FONT_OPTIONS = ["script", "script_bold", "handwrite", "calligraphy", "retro", "serif", "serif_classic", "serif_luxury", "sans", "condensed", "impact", "vn", "vn_bold", "vn_med"];
|
| 11 |
const RESOLUTIONS = [
|
| 12 |
{ label: "1088x1088 (Square)", value: "1088x1088" },
|
| 13 |
{ label: "1088x1920 (Portrait)", value: "1088x1920" },
|
|
@@ -20,143 +13,61 @@ const MODELS = [
|
|
| 20 |
{ label: "Flux 1.1 Pro", value: "flux_1.1_pro" },
|
| 21 |
{ label: "Flux Schnell", value: "flux_schnell" },
|
| 22 |
];
|
| 23 |
-
const PRESET_ITEMS = [
|
| 24 |
-
{ type: "thumbnail", label: "Thumbnail" },
|
| 25 |
-
{ type: "hero", label: "Hero" },
|
| 26 |
-
{ type: "feature", label: "Feature" },
|
| 27 |
-
{ type: "benefit", label: "Benefit" },
|
| 28 |
-
{ type: "ingredient", label: "Ingredient" },
|
| 29 |
-
{ type: "display", label: "Display" },
|
| 30 |
-
{ type: "promo", label: "Promo" },
|
| 31 |
-
{ type: "in_use", label: "In Use" },
|
| 32 |
-
{ type: "lifestyle", label: "Lifestyle" },
|
| 33 |
-
];
|
| 34 |
-
|
| 35 |
-
function newItem(type) {
|
| 36 |
-
const base = { type, label: type, lang: "vi", template: "simple", text_pos: "bottom-center", text_blocks: [{ role: "headline", text: "NEW PRODUCT", font: "sans" }], scene_prompt: "" };
|
| 37 |
-
if (type === "feature_panel") {
|
| 38 |
-
base.template = "feature_panel"; base.panel_side = "left"; base.title = "FEATURES";
|
| 39 |
-
base.features = [{ icon: "check", text: "Feature 1" }];
|
| 40 |
-
} else if (type === "multicolor") {
|
| 41 |
-
base.template = "multicolor"; base.font = "impact";
|
| 42 |
-
base.headline_words = [{ text: "BOLD", color: "white" }]; base.sub = ""; base.tag = "";
|
| 43 |
-
}
|
| 44 |
-
return base;
|
| 45 |
-
}
|
| 46 |
|
| 47 |
export default function ListingFree() {
|
| 48 |
const [sessionId, setSessionId] = useState(null);
|
| 49 |
const [productFile, setProductFile] = useState(null);
|
| 50 |
const [productPreview, setProductPreview] = useState(null);
|
| 51 |
-
const [bgFile, setBgFile] = useState(null);
|
| 52 |
-
const [bgPreview, setBgPreview] = useState(null);
|
| 53 |
-
const [modelFile, setModelFile] = useState(null);
|
| 54 |
-
const [modelPreview, setModelPreview] = useState(null);
|
| 55 |
-
const [items, setItems] = useState([]);
|
| 56 |
const [results, setResults] = useState([]);
|
| 57 |
const [status, setStatus] = useState(null);
|
| 58 |
const [logs, setLogs] = useState([]);
|
| 59 |
-
const [progress, setProgress] = useState(0);
|
| 60 |
const [busy, setBusy] = useState(false);
|
| 61 |
const [generating, setGenerating] = useState(false);
|
| 62 |
-
const [
|
| 63 |
-
const [showAdvanced, setShowAdvanced] = useState(false);
|
| 64 |
|
| 65 |
-
const [
|
| 66 |
-
const [
|
| 67 |
-
const [wangpUrl, setWangpUrl] = useState("https://fe91b5c9d1cfdfc08e.gradio.live/");
|
| 68 |
const [modelChoice, setModelChoice] = useState("flux2_klein_9b");
|
| 69 |
const [resolution, setResolution] = useState("1088x1088");
|
| 70 |
const [steps, setSteps] = useState(20);
|
| 71 |
const [guidance, setGuidance] = useState(4);
|
| 72 |
const [refStrength, setRefStrength] = useState(75);
|
| 73 |
const [negativePrompt, setNegativePrompt] = useState("mirror, reflection in mirror, text, words, letters, typography, captions, deformed hands, extra fingers, bad anatomy, blurry, low quality, watermark");
|
| 74 |
-
|
| 75 |
-
const [
|
| 76 |
-
const [
|
| 77 |
-
const [
|
|
|
|
| 78 |
|
| 79 |
const pollRef = useRef(null);
|
| 80 |
const prodRef = useRef(null);
|
| 81 |
-
const bgRef = useRef(null);
|
| 82 |
-
const modelRef = useRef(null);
|
| 83 |
const lastMsgRef = useRef("");
|
| 84 |
|
| 85 |
useEffect(() => {
|
| 86 |
return () => {
|
| 87 |
if (productPreview) URL.revokeObjectURL(productPreview);
|
| 88 |
-
if (bgPreview) URL.revokeObjectURL(bgPreview);
|
| 89 |
-
if (modelPreview) URL.revokeObjectURL(modelPreview);
|
| 90 |
if (pollRef.current) clearTimeout(pollRef.current);
|
| 91 |
};
|
| 92 |
-
}, [productPreview
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
};
|
| 98 |
|
| 99 |
-
const
|
| 100 |
if (!f || !f.type.startsWith("image/")) return;
|
| 101 |
if (productPreview) URL.revokeObjectURL(productPreview);
|
| 102 |
setProductFile(f); setProductPreview(URL.createObjectURL(f));
|
| 103 |
-
setSessionId(null); setResults([]);
|
| 104 |
-
|
| 105 |
-
setGptPrompts(null);
|
| 106 |
-
};
|
| 107 |
-
const handleBgFile = (f) => {
|
| 108 |
-
if (!f || !f.type.startsWith("image/")) return;
|
| 109 |
-
if (bgPreview) URL.revokeObjectURL(bgPreview);
|
| 110 |
-
setBgFile(f); setBgPreview(URL.createObjectURL(f));
|
| 111 |
-
};
|
| 112 |
-
const handleModelFile = (f) => {
|
| 113 |
-
if (!f || !f.type.startsWith("image/")) return;
|
| 114 |
-
if (modelPreview) URL.revokeObjectURL(modelPreview);
|
| 115 |
-
setModelFile(f); setModelPreview(URL.createObjectURL(f));
|
| 116 |
};
|
| 117 |
|
| 118 |
-
const addPresetItem = (preset) => setItems(prev => [...prev, { ...newItem(preset.type), label: preset.label }]);
|
| 119 |
-
const removeItem = (idx) => setItems(prev => prev.filter((_, i) => i !== idx));
|
| 120 |
-
const updateItem = (idx, patch) => setItems(prev => prev.map((it, i) => i === idx ? { ...it, ...patch } : it));
|
| 121 |
-
|
| 122 |
-
const PROMPT_TEMPLATES = {
|
| 123 |
-
thumbnail: "Close-up product shot of {product}, minimalist studio background with soft lighting, clean and elegant, product centered, copy space around",
|
| 124 |
-
hero: "Model confidently holding {product}, bright natural lighting, clean background, professional beauty shot, model looking at camera",
|
| 125 |
-
feature: "{product} with its key ingredients displayed on a marble surface, soft natural lighting, clean minimal background, flat lay",
|
| 126 |
-
benefit: "Before and after concept for {product}, glowing skin, bright natural light, clean white background, transformational beauty shot",
|
| 127 |
-
ingredient: "Fresh natural ingredients related to {product} arranged artistically, green leaves and botanical elements, morning sunlight",
|
| 128 |
-
display: "{product} on a sleek modern shelf, retail display style, soft warm lighting, blurred background, premium feel",
|
| 129 |
-
promo: "Special offer presentation of {product}, golden light particles, luxurious dark background, premium gift-like presentation",
|
| 130 |
-
in_use: "Person applying {product} in a bright modern bathroom, natural morning light, clean mirror reflection, skincare routine",
|
| 131 |
-
lifestyle: "Person enjoying {product} in a cozy modern lifestyle setting, warm ambient lighting, natural everyday moment",
|
| 132 |
-
};
|
| 133 |
-
|
| 134 |
-
const generateManualPrompts = () => {
|
| 135 |
-
const text = manualPromptText.trim();
|
| 136 |
-
if (!text) return;
|
| 137 |
-
const generated = PRESET_ITEMS.map(p => {
|
| 138 |
-
const item = newItem(p.type);
|
| 139 |
-
item.label = p.label;
|
| 140 |
-
const tpl = PROMPT_TEMPLATES[p.type] || "Product shot of {product}, clean background";
|
| 141 |
-
item.scene_prompt = tpl.replace(/\{product\}/g, text);
|
| 142 |
-
return item;
|
| 143 |
-
});
|
| 144 |
-
setItems(generated);
|
| 145 |
-
addLog("success", `Generated ${generated.length} manual prompts`);
|
| 146 |
-
setStatus(`${generated.length} prompts created manually`);
|
| 147 |
-
};
|
| 148 |
-
|
| 149 |
-
const storeKey = "tnt_listing_free_key";
|
| 150 |
-
useEffect(() => { try { localStorage.setItem(storeKey, openaiKey); } catch {} }, [openaiKey]);
|
| 151 |
-
useEffect(() => { try { setOpenaiKey(localStorage.getItem(storeKey) || ""); } catch {} }, []);
|
| 152 |
-
|
| 153 |
const startUpload = async () => {
|
| 154 |
if (!productFile || busy || generating) return;
|
| 155 |
-
setBusy(true); setStatus("Uploading..."); addLog("info", "Uploading
|
| 156 |
const fd = new FormData();
|
| 157 |
fd.append("product", productFile);
|
| 158 |
-
if (bgFile) fd.append("background", bgFile);
|
| 159 |
-
if (modelFile) fd.append("model", modelFile);
|
| 160 |
try {
|
| 161 |
const res = await fetch("/api/listing-free/upload", { method: "POST", body: fd });
|
| 162 |
const data = await res.json();
|
|
@@ -165,70 +76,62 @@ export default function ListingFree() {
|
|
| 165 |
} catch (e) { setStatus("Error: " + e.message); addLog("error", e.message); setBusy(false); }
|
| 166 |
};
|
| 167 |
|
| 168 |
-
const
|
| 169 |
-
if (!sessionId || !openaiKey.trim() || busy
|
| 170 |
-
|
| 171 |
-
setBusy(true); setStatus("Analyzing with GPT-4o..."); addLog("info", "Analyzing product with GPT-4o Vision...");
|
| 172 |
try {
|
| 173 |
const res = await fetch("/api/listing-free/analyze", {
|
| 174 |
method: "POST", headers: { "Content-Type": "application/json" },
|
| 175 |
-
body: JSON.stringify({ session_id: sessionId, openai_key: openaiKey.trim()
|
| 176 |
});
|
| 177 |
const data = await res.json();
|
| 178 |
if (!data.ok && data.error) throw new Error(data.error);
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
addLog("success", `GPT
|
| 182 |
-
setStatus(`
|
| 183 |
} catch (e) { setStatus("Error: " + e.message); addLog("error", e.message); }
|
| 184 |
finally { setBusy(false); }
|
| 185 |
};
|
| 186 |
|
| 187 |
-
const
|
| 188 |
-
if (!sessionId ||
|
| 189 |
-
if (
|
| 190 |
-
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
setGenerating(true); setResults([]); setLogs([]); setProgress(0);
|
| 193 |
-
addLog("info", "Starting
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
try {
|
| 195 |
const body = {
|
| 196 |
session_id: sessionId,
|
| 197 |
openai_key: openaiKey.trim(),
|
| 198 |
-
product_info: productInfo.trim(),
|
| 199 |
wangp_url: wangpUrl.trim(),
|
| 200 |
model_choice: modelChoice,
|
| 201 |
-
resolution,
|
| 202 |
-
steps,
|
| 203 |
-
guidance,
|
| 204 |
ref_strength: refStrength,
|
| 205 |
negative_prompt: negativePrompt,
|
| 206 |
};
|
| 207 |
-
if (items
|
| 208 |
-
else if (gptPrompts) body.items = gptPrompts;
|
| 209 |
|
| 210 |
const res = await fetch("/api/listing-free/auto-generate", {
|
| 211 |
method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),
|
| 212 |
});
|
| 213 |
const data = await res.json();
|
| 214 |
if (!data.ok && data.error) throw new Error(data.error);
|
| 215 |
-
if (data.items) setItems(data.items);
|
| 216 |
-
await pollSession();
|
| 217 |
-
} catch (e) { setStatus("Error: " + e.message); addLog("error", e.message); }
|
| 218 |
-
finally { setGenerating(false); }
|
| 219 |
-
};
|
| 220 |
-
|
| 221 |
-
const startDesign = async () => {
|
| 222 |
-
if (!sessionId || items.length === 0 || busy || generating) return;
|
| 223 |
-
setGenerating(true); setStatus("Applying designs..."); setResults([]); setLogs([]);
|
| 224 |
-
addLog("info", `Applying ${items.length} designs...`);
|
| 225 |
-
try {
|
| 226 |
-
const res = await fetch("/api/listing-free/design", {
|
| 227 |
-
method: "POST", headers: { "Content-Type": "application/json" },
|
| 228 |
-
body: JSON.stringify({ session_id: sessionId, items }),
|
| 229 |
-
});
|
| 230 |
-
const data = await res.json();
|
| 231 |
-
if (!data.ok && data.error) throw new Error(data.error);
|
| 232 |
await pollSession();
|
| 233 |
} catch (e) { setStatus("Error: " + e.message); addLog("error", e.message); }
|
| 234 |
finally { setGenerating(false); }
|
|
@@ -272,309 +175,178 @@ export default function ListingFree() {
|
|
| 272 |
const resetAll = () => {
|
| 273 |
if (pollRef.current) clearTimeout(pollRef.current);
|
| 274 |
if (sessionId) fetch(`/api/listing-free/session/${sessionId}`, { method: "DELETE" }).catch(() => {});
|
| 275 |
-
setSessionId(null); setResults([]);
|
| 276 |
-
|
| 277 |
if (productPreview) { URL.revokeObjectURL(productPreview); setProductPreview(null); }
|
| 278 |
-
|
| 279 |
-
if (modelPreview) { URL.revokeObjectURL(modelPreview); setModelPreview(null); }
|
| 280 |
-
setProductFile(null); setBgFile(null); setModelFile(null);
|
| 281 |
-
setShowLog(false); setShowProductInfoInput(false);
|
| 282 |
};
|
| 283 |
|
| 284 |
return (
|
| 285 |
<div>
|
| 286 |
<div className="h1">Workspace: <span className="accent">Listing ảnh Free</span></div>
|
| 287 |
-
<p className="subtitle">Upload
|
| 288 |
<div className="grid-2">
|
| 289 |
<div className="stack">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
{/* Upload */}
|
| 291 |
<div className="card">
|
| 292 |
-
<div className="panel-title"><IcUpload size={16} /> Upload
|
| 293 |
-
<div style={{
|
| 294 |
-
{
|
| 295 |
-
{
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
<div
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
{
|
| 304 |
-
|
| 305 |
-
<img src={preview} alt="" style={{ width: "100%", aspectRatio: "1/1", borderRadius: 8, objectFit: "cover" }} />
|
| 306 |
-
<div style={{ fontSize: 11, textAlign: "center", marginTop: 4, color: "var(--muted)" }}>{label}</div>
|
| 307 |
-
</div>
|
| 308 |
-
) : (
|
| 309 |
-
<div style={{ textAlign: "center", padding: "24px 4px", flex: 1, display: "flex", flexDirection: "column", justifyContent: "center" }}>
|
| 310 |
-
<div className="chip" style={{ margin: "0 auto 6px" }}><IcImage size={18} /></div>
|
| 311 |
-
<div style={{ fontSize: 11, fontWeight: 600 }}>{label}</div>
|
| 312 |
-
{required && <div style={{ fontSize: 10, color: "var(--muted)", marginTop: 2 }}>Required</div>}
|
| 313 |
-
</div>
|
| 314 |
-
)}
|
| 315 |
</div>
|
| 316 |
-
)
|
| 317 |
</div>
|
| 318 |
{productPreview && !sessionId && (
|
| 319 |
<button className="btn primary" style={{ marginTop: 8, width: "100%" }} disabled={busy} onClick={startUpload}>
|
| 320 |
-
{busy ? "Uploading..." : "Upload
|
| 321 |
</button>
|
| 322 |
)}
|
| 323 |
</div>
|
| 324 |
|
| 325 |
-
{/* OpenAI Key + Product Info */}
|
| 326 |
{sessionId && (
|
| 327 |
-
<
|
| 328 |
-
|
| 329 |
-
<div
|
| 330 |
-
<
|
| 331 |
-
placeholder="sk-... (OpenAI key for GPT-4o Vision analysis + prompt generation)"
|
| 332 |
-
style={{ flex: 1, padding: "7px 12px", fontSize: 13, border: "1px solid var(--line)", borderRadius: "var(--radius-sm)" }} />
|
| 333 |
-
{openaiKey && <span style={{ fontSize: 11, color: "var(--green)", whiteSpace: "nowrap" }}>Saved ✓</span>}
|
| 334 |
-
{openaiKey && <button className="btn sm" style={{ fontSize: 10, padding: "2px 6px" }} onClick={() => { setOpenaiKey(""); try { localStorage.removeItem(storeKey); } catch {} }}>Clear</button>}
|
| 335 |
-
</div>
|
| 336 |
-
<button className="btn sm" style={{ fontSize: 12 }} onClick={() => setShowProductInfoInput(!showProductInfoInput)}>
|
| 337 |
-
{showProductInfoInput ? "Hide" : "+ Add"} product info
|
| 338 |
-
</button>
|
| 339 |
-
{showProductInfoInput && (
|
| 340 |
-
<textarea value={productInfo} onChange={e => setProductInfo(e.target.value)}
|
| 341 |
-
placeholder="Product info for GPT analysis (brand, ingredients, benefits...)"
|
| 342 |
-
style={{ width: "100%", minHeight: 80, fontSize: 12, marginTop: 6 }} spellCheck={false} />
|
| 343 |
-
)}
|
| 344 |
-
<button className="btn primary" style={{ width: "100%", marginTop: 8 }}
|
| 345 |
-
disabled={busy || generating || !openaiKey.trim()} onClick={analyzeWithGpt}>
|
| 346 |
-
{busy ? "Analyzing..." : showProductInfoInput ? "Analyze with GPT-4o" : "Analyze with GPT-4o"}
|
| 347 |
-
</button>
|
| 348 |
-
{gptPrompts && <div style={{ fontSize: 12, color: "var(--green)", marginTop: 6 }}>Got {gptPrompts.length} prompts from GPT</div>}
|
| 349 |
-
<div style={{ fontSize: 10, color: "var(--muted)", marginTop: 4 }}>Key saved in browser, no need to re-enter next time.</div>
|
| 350 |
-
</div>
|
| 351 |
-
)}
|
| 352 |
-
|
| 353 |
-
{/* Wangp Config */}
|
| 354 |
-
{sessionId && (
|
| 355 |
-
<div className="card">
|
| 356 |
-
<div className="panel-title" style={{ cursor: "pointer" }} onClick={() => setShowAdvanced(!showAdvanced)}>
|
| 357 |
-
<IcSliders size={16} /> Wangp / Flux config {showAdvanced ? "▲" : "▼"}
|
| 358 |
-
</div>
|
| 359 |
-
{showAdvanced && (
|
| 360 |
-
<div className="stack" style={{ gap: 8 }}>
|
| 361 |
<div>
|
| 362 |
-
<label style={{ fontSize: 11, color: "var(--muted)" }}>
|
| 363 |
-
<
|
| 364 |
-
style={{
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
<div style={{ flex: 1 }}>
|
| 368 |
-
<label style={{ fontSize: 11, color: "var(--muted)" }}>Model</label>
|
| 369 |
-
<select value={modelChoice} onChange={e => setModelChoice(e.target.value)}
|
| 370 |
-
style={{ width: "100%", fontSize: 12, padding: "4px 6px" }}>
|
| 371 |
-
{MODELS.map(m => <option key={m.value} value={m.value}>{m.label}</option>)}
|
| 372 |
-
</select>
|
| 373 |
-
</div>
|
| 374 |
-
<div style={{ flex: 1 }}>
|
| 375 |
-
<label style={{ fontSize: 11, color: "var(--muted)" }}>Resolution</label>
|
| 376 |
-
<select value={resolution} onChange={e => setResolution(e.target.value)}
|
| 377 |
-
style={{ width: "100%", fontSize: 12, padding: "4px 6px" }}>
|
| 378 |
-
{RESOLUTIONS.map(r => <option key={r.value} value={r.value}>{r.label}</option>)}
|
| 379 |
-
</select>
|
| 380 |
-
</div>
|
| 381 |
-
</div>
|
| 382 |
-
<div className="row" style={{ gap: 6 }}>
|
| 383 |
-
<div style={{ flex: 1 }}>
|
| 384 |
-
<label style={{ fontSize: 11, color: "var(--muted)" }}>Steps</label>
|
| 385 |
-
<input type="number" value={steps} onChange={e => setSteps(Number(e.target.value))}
|
| 386 |
-
min={1} max={50} style={{ width: "100%", fontSize: 12, padding: "4px 6px" }} />
|
| 387 |
-
</div>
|
| 388 |
-
<div style={{ flex: 1 }}>
|
| 389 |
-
<label style={{ fontSize: 11, color: "var(--muted)" }}>Guidance</label>
|
| 390 |
-
<input type="number" value={guidance} onChange={e => setGuidance(Number(e.target.value))}
|
| 391 |
-
min={1} max={20} step={0.5} style={{ width: "100%", fontSize: 12, padding: "4px 6px" }} />
|
| 392 |
-
</div>
|
| 393 |
-
<div style={{ flex: 1 }}>
|
| 394 |
-
<label style={{ fontSize: 11, color: "var(--muted)" }}>Ref Strength</label>
|
| 395 |
-
<input type="number" value={refStrength} onChange={e => setRefStrength(Number(e.target.value))}
|
| 396 |
-
min={0} max={100} style={{ width: "100%", fontSize: 12, padding: "4px 6px" }} />
|
| 397 |
-
</div>
|
| 398 |
</div>
|
| 399 |
<div>
|
| 400 |
-
<label style={{ fontSize: 11, color: "var(--muted)" }}>
|
| 401 |
-
<
|
| 402 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 403 |
</div>
|
| 404 |
</div>
|
| 405 |
-
)}
|
| 406 |
-
</div>
|
| 407 |
-
)}
|
| 408 |
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
</div>
|
| 424 |
-
)}
|
| 425 |
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
<div key={i} style={{ borderBottom: "1px solid var(--line)", padding: "6px 0" }}>
|
| 436 |
-
<div style={{ fontWeight: 600, marginBottom: 2 }}>{p.label}</div>
|
| 437 |
-
<div style={{ color: "var(--muted)", marginBottom: 2 }}>Template: {p.template} | Lang: {p.lang} | Type: {p.type}</div>
|
| 438 |
-
{p.scene_prompt && <div style={{ color: "var(--ink-2)", wordBreak: "break-word" }}>Prompt: {p.scene_prompt}</div>}
|
| 439 |
</div>
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
{/* Add items + Auto Generate */}
|
| 454 |
-
{sessionId && (
|
| 455 |
-
<div className="card">
|
| 456 |
-
<div className="panel-title"><IcPlus size={16} /> Listing items</div>
|
| 457 |
-
<div style={{ display: "flex", flexWrap: "wrap", gap: 6, marginBottom: 12 }}>
|
| 458 |
-
{PRESET_ITEMS.map(p => (
|
| 459 |
-
<div key={p.type} onClick={() => addPresetItem(p)}
|
| 460 |
-
style={{ padding: "5px 12px", fontSize: 11, borderRadius: 20, cursor: "pointer",
|
| 461 |
-
border: "2px solid var(--line)", background: "var(--white)", userSelect: "none" }}>
|
| 462 |
-
+ {p.label}
|
| 463 |
</div>
|
| 464 |
-
)
|
| 465 |
</div>
|
| 466 |
|
| 467 |
-
{
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
{
|
| 476 |
</select>
|
| 477 |
-
|
| 478 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 479 |
</select>
|
| 480 |
</div>
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
{
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
))}
|
| 498 |
-
<button className="btn sm" style={{ fontSize: 10, marginTop: 2 }} onClick={() => updateItem(idx, { text_blocks: [...(item.text_blocks || []), { role: "subhead", text: "", font: "sans" }] })}>+ block</button>
|
| 499 |
-
</div>
|
| 500 |
-
)}
|
| 501 |
-
{item.template === "multicolor" && (
|
| 502 |
-
<div>
|
| 503 |
-
<select value={item.text_pos} onChange={e => updateItem(idx, { text_pos: e.target.value })} style={{ fontSize: 11, padding: "2px 4px", marginBottom: 4 }}>
|
| 504 |
-
<option value="bottom-left">Bottom left</option><option value="top-left">Top left</option>
|
| 505 |
-
</select>
|
| 506 |
-
{(item.headline_words || []).map((w, wi) => (
|
| 507 |
-
<div key={wi} style={{ display: "flex", gap: 3, marginBottom: 3 }}>
|
| 508 |
-
<input value={w.text} onChange={e => { const ws = [...item.headline_words]; ws[wi] = { ...ws[wi], text: e.target.value }; updateItem(idx, { headline_words: ws }); }} placeholder="Word" style={{ flex: 1, fontSize: 11, padding: "2px 4px" }} />
|
| 509 |
-
<select value={w.color} onChange={e => { const ws = [...item.headline_words]; ws[wi] = { ...ws[wi], color: e.target.value }; updateItem(idx, { headline_words: ws }); }} style={{ fontSize: 10, padding: "2px", width: 55 }}>
|
| 510 |
-
{["white","pink","gold","dark","black","red","green"].map(c => <option key={c} value={c}>{c}</option>)}
|
| 511 |
-
</select>
|
| 512 |
-
<button className="btn sm" style={{ fontSize: 9, padding: "1px 4px" }} onClick={() => updateItem(idx, { headline_words: item.headline_words.filter((_, i) => i !== wi) })}>×</button>
|
| 513 |
-
</div>
|
| 514 |
-
))}
|
| 515 |
-
<button className="btn sm" style={{ fontSize: 10 }} onClick={() => updateItem(idx, { headline_words: [...(item.headline_words || []), { text: "", color: "white" }] })}>+ word</button>
|
| 516 |
-
<div style={{ display: "flex", gap: 4, marginTop: 4 }}>
|
| 517 |
-
<input value={item.sub || ""} onChange={e => updateItem(idx, { sub: e.target.value })} placeholder="Subtitle" style={{ flex: 1, fontSize: 11, padding: "2px 4px" }} />
|
| 518 |
-
<input value={item.tag || ""} onChange={e => updateItem(idx, { tag: e.target.value })} placeholder="Tag" style={{ flex: 1, fontSize: 11, padding: "2px 4px" }} />
|
| 519 |
-
</div>
|
| 520 |
-
</div>
|
| 521 |
-
)}
|
| 522 |
-
{item.template === "feature_panel" && (
|
| 523 |
-
<div>
|
| 524 |
-
<div className="row" style={{ gap: 4, marginBottom: 4 }}>
|
| 525 |
-
<select value={item.panel_side} onChange={e => updateItem(idx, { panel_side: e.target.value })} style={{ fontSize: 11, padding: "2px 4px" }}>
|
| 526 |
-
<option value="left">Left</option><option value="right">Right</option>
|
| 527 |
-
</select>
|
| 528 |
-
<input value={item.title || ""} onChange={e => updateItem(idx, { title: e.target.value })} placeholder="Title" style={{ flex: 1, fontSize: 11, padding: "2px 4px" }} />
|
| 529 |
-
</div>
|
| 530 |
-
{(item.features || []).map((ft, fi) => (
|
| 531 |
-
<div key={fi} style={{ display: "flex", gap: 3, marginBottom: 3 }}>
|
| 532 |
-
<select value={ft.icon} onChange={e => { const f = [...item.features]; f[fi] = { ...f[fi], icon: e.target.value }; updateItem(idx, { features: f }); }} style={{ fontSize: 10, padding: "2px", width: 55 }}>
|
| 533 |
-
{ICON_OPTIONS.map(ic => <option key={ic} value={ic}>{ic}</option>)}
|
| 534 |
-
</select>
|
| 535 |
-
<input value={ft.text} onChange={e => { const f = [...item.features]; f[fi] = { ...f[fi], text: e.target.value }; updateItem(idx, { features: f }); }} placeholder="Feature text" style={{ flex: 1, fontSize: 11, padding: "2px 4px" }} />
|
| 536 |
-
<button className="btn sm" style={{ fontSize: 9, padding: "1px 4px" }} onClick={() => updateItem(idx, { features: item.features.filter((_, i) => i !== fi) })}>×</button>
|
| 537 |
-
</div>
|
| 538 |
-
))}
|
| 539 |
-
<button className="btn sm" style={{ fontSize: 10 }} onClick={() => updateItem(idx, { features: [...(item.features || []), { icon: "check", text: "" }] })}>+ feature</button>
|
| 540 |
-
</div>
|
| 541 |
-
)}
|
| 542 |
-
<div style={{ marginTop: 6 }}>
|
| 543 |
-
<div style={{ fontSize: 10, fontWeight: 600, marginBottom: 2, color: "var(--muted)" }}>Scene prompt</div>
|
| 544 |
-
<textarea value={item.scene_prompt || ""} onChange={e => updateItem(idx, { scene_prompt: e.target.value })}
|
| 545 |
-
placeholder="Leave empty for design-only (no Wangp background)"
|
| 546 |
-
style={{ width: "100%", fontSize: 11, padding: "4px 6px", minHeight: 60, resize: "vertical" }} spellCheck={false} />
|
| 547 |
</div>
|
| 548 |
</div>
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
<button className="btn primary" style={{ flex: 1, fontSize: 12 }}
|
| 554 |
-
disabled={generating} onClick={startDesign}>
|
| 555 |
-
{generating ? "Generating..." : `Design only (${items.length} items)`}
|
| 556 |
-
</button>
|
| 557 |
-
<button className="btn" style={{ flex: 1, fontSize: 12, background: "var(--orange)", color: "#fff", border: "none" }}
|
| 558 |
-
disabled={generating} onClick={startAutoGenerate}>
|
| 559 |
-
{generating ? "Generating..." : "Auto Generate (Wangp + Design)"}
|
| 560 |
-
</button>
|
| 561 |
</div>
|
| 562 |
-
|
| 563 |
|
| 564 |
-
{
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
</div>
|
| 571 |
)}
|
| 572 |
|
| 573 |
{/* Log */}
|
| 574 |
-
{
|
| 575 |
<div className="card">
|
| 576 |
<div className="panel-title">Progress</div>
|
| 577 |
-
{
|
| 578 |
{status && <div style={{ fontSize: 13, color: "var(--ink-2)", marginBottom: 8 }}>{status}</div>}
|
| 579 |
<div className="logbox" style={{ maxHeight: 200, fontSize: 11, lineHeight: 1.6 }}>
|
| 580 |
{logs.map((l, i) => <div key={i} className={l.includes("✅") ? "ok" : l.includes("❌") ? "err" : ""}>{l}</div>)}
|
|
@@ -607,20 +379,21 @@ export default function ListingFree() {
|
|
| 607 |
<div className="chip" style={{ margin: "0 auto 12px" }}><IcStar size={24} /></div>
|
| 608 |
<div style={{ fontSize: 14, fontWeight: 600, marginBottom: 6 }}>Listing ảnh Free</div>
|
| 609 |
<div style={{ fontSize: 12, lineHeight: 1.6 }}>
|
| 610 |
-
Upload product image
|
| 611 |
</div>
|
| 612 |
</div>
|
| 613 |
)}
|
| 614 |
</div>
|
| 615 |
|
| 616 |
<div className="rail">
|
| 617 |
-
<div className="rail-title">
|
| 618 |
-
<div className="rail-step"><div className="num">1</div><div className="body"><div className="t">
|
| 619 |
-
<div className="rail-step"><div className="num">2</div><div className="body"><div className="t">
|
| 620 |
-
<div className="rail-step"><div className="num">3</div><div className="body"><div className="t">
|
| 621 |
-
<div className="rail-step"><div className="num">4</div><div className="body"><div className="t">
|
| 622 |
-
<div className="rail-step"><div className="num">5</div><div className="body"><div className="t">
|
| 623 |
-
<div className="
|
|
|
|
| 624 |
</div>
|
| 625 |
</div>
|
| 626 |
</div>
|
|
|
|
| 1 |
import { useState, useRef, useEffect } from "react";
|
| 2 |
+
import { IcImage, IcUpload, IcDownload, IcRefresh, IcStar } from "../components/Icons";
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
const RESOLUTIONS = [
|
| 5 |
{ label: "1088x1088 (Square)", value: "1088x1088" },
|
| 6 |
{ label: "1088x1920 (Portrait)", value: "1088x1920" },
|
|
|
|
| 13 |
{ label: "Flux 1.1 Pro", value: "flux_1.1_pro" },
|
| 14 |
{ label: "Flux Schnell", value: "flux_schnell" },
|
| 15 |
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
export default function ListingFree() {
|
| 18 |
const [sessionId, setSessionId] = useState(null);
|
| 19 |
const [productFile, setProductFile] = useState(null);
|
| 20 |
const [productPreview, setProductPreview] = useState(null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
const [results, setResults] = useState([]);
|
| 22 |
const [status, setStatus] = useState(null);
|
| 23 |
const [logs, setLogs] = useState([]);
|
|
|
|
| 24 |
const [busy, setBusy] = useState(false);
|
| 25 |
const [generating, setGenerating] = useState(false);
|
| 26 |
+
const [progress, setProgress] = useState(0);
|
|
|
|
| 27 |
|
| 28 |
+
const [wangpUrl, setWangpUrl] = useState(() => { try { return localStorage.getItem("tnt_wangp_url") || "https://fe91b5c9d1cfdfc08e.gradio.live/"; } catch { return "https://fe91b5c9d1cfdfc08e.gradio.live/"; }});
|
| 29 |
+
const [openaiKey, setOpenaiKey] = useState(() => { try { return localStorage.getItem("tnt_openai_key") || ""; } catch { return ""; }});
|
|
|
|
| 30 |
const [modelChoice, setModelChoice] = useState("flux2_klein_9b");
|
| 31 |
const [resolution, setResolution] = useState("1088x1088");
|
| 32 |
const [steps, setSteps] = useState(20);
|
| 33 |
const [guidance, setGuidance] = useState(4);
|
| 34 |
const [refStrength, setRefStrength] = useState(75);
|
| 35 |
const [negativePrompt, setNegativePrompt] = useState("mirror, reflection in mirror, text, words, letters, typography, captions, deformed hands, extra fingers, bad anatomy, blurry, low quality, watermark");
|
| 36 |
+
|
| 37 |
+
const [imageCount, setImageCount] = useState(4);
|
| 38 |
+
const [mode, setMode] = useState("manual");
|
| 39 |
+
const [prompts, setPrompts] = useState([]);
|
| 40 |
+
const [autoPrompts, setAutoPrompts] = useState(null);
|
| 41 |
|
| 42 |
const pollRef = useRef(null);
|
| 43 |
const prodRef = useRef(null);
|
|
|
|
|
|
|
| 44 |
const lastMsgRef = useRef("");
|
| 45 |
|
| 46 |
useEffect(() => {
|
| 47 |
return () => {
|
| 48 |
if (productPreview) URL.revokeObjectURL(productPreview);
|
|
|
|
|
|
|
| 49 |
if (pollRef.current) clearTimeout(pollRef.current);
|
| 50 |
};
|
| 51 |
+
}, [productPreview]);
|
| 52 |
|
| 53 |
+
useEffect(() => { try { localStorage.setItem("tnt_wangp_url", wangpUrl); } catch {} }, [wangpUrl]);
|
| 54 |
+
useEffect(() => { try { localStorage.setItem("tnt_openai_key", openaiKey); } catch {} }, [openaiKey]);
|
| 55 |
+
|
| 56 |
+
const addLog = (level, msg) => setLogs(prev => [...prev, `[${new Date().toLocaleTimeString()}] ${msg}`]);
|
| 57 |
|
| 58 |
+
const handleFile = (f) => {
|
| 59 |
if (!f || !f.type.startsWith("image/")) return;
|
| 60 |
if (productPreview) URL.revokeObjectURL(productPreview);
|
| 61 |
setProductFile(f); setProductPreview(URL.createObjectURL(f));
|
| 62 |
+
setSessionId(null); setResults([]); setLogs([]); setStatus(null);
|
| 63 |
+
setPrompts([]); setAutoPrompts(null); setGenerating(false); setBusy(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
};
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
const startUpload = async () => {
|
| 67 |
if (!productFile || busy || generating) return;
|
| 68 |
+
setBusy(true); setStatus("Uploading..."); addLog("info", "Uploading...");
|
| 69 |
const fd = new FormData();
|
| 70 |
fd.append("product", productFile);
|
|
|
|
|
|
|
| 71 |
try {
|
| 72 |
const res = await fetch("/api/listing-free/upload", { method: "POST", body: fd });
|
| 73 |
const data = await res.json();
|
|
|
|
| 76 |
} catch (e) { setStatus("Error: " + e.message); addLog("error", e.message); setBusy(false); }
|
| 77 |
};
|
| 78 |
|
| 79 |
+
const generateAutoPrompts = async () => {
|
| 80 |
+
if (!sessionId || !openaiKey.trim() || busy) return;
|
| 81 |
+
setBusy(true); setStatus("GPT analyzing..."); addLog("info", "GPT-4o Vision analyzing product...");
|
|
|
|
| 82 |
try {
|
| 83 |
const res = await fetch("/api/listing-free/analyze", {
|
| 84 |
method: "POST", headers: { "Content-Type": "application/json" },
|
| 85 |
+
body: JSON.stringify({ session_id: sessionId, openai_key: openaiKey.trim() }),
|
| 86 |
});
|
| 87 |
const data = await res.json();
|
| 88 |
if (!data.ok && data.error) throw new Error(data.error);
|
| 89 |
+
setAutoPrompts(data.prompts);
|
| 90 |
+
setPrompts(data.prompts.map(p => p.scene_prompt || ""));
|
| 91 |
+
addLog("success", `GPT generated ${data.count} prompts`);
|
| 92 |
+
setStatus(`${data.count} prompts ready`);
|
| 93 |
} catch (e) { setStatus("Error: " + e.message); addLog("error", e.message); }
|
| 94 |
finally { setBusy(false); }
|
| 95 |
};
|
| 96 |
|
| 97 |
+
const doGenerate = async () => {
|
| 98 |
+
if (!sessionId || generating) return;
|
| 99 |
+
if (mode === "manual") {
|
| 100 |
+
const filled = prompts.filter(p => p.trim());
|
| 101 |
+
if (filled.length === 0) { addLog("error", "Enter at least one prompt"); return; }
|
| 102 |
+
}
|
| 103 |
+
if (mode === "auto" && !openaiKey.trim()) { addLog("error", "Enter OpenAI API key"); return; }
|
| 104 |
|
| 105 |
setGenerating(true); setResults([]); setLogs([]); setProgress(0);
|
| 106 |
+
addLog("info", "Starting generation...");
|
| 107 |
+
|
| 108 |
+
let items = null;
|
| 109 |
+
if (mode === "manual") {
|
| 110 |
+
items = prompts.filter(p => p.trim()).map((p, i) => ({
|
| 111 |
+
type: `img_${i}`, label: `Image ${i + 1}`,
|
| 112 |
+
lang: "vi", template: "simple", text_pos: "bottom-center",
|
| 113 |
+
text_blocks: [{ role: "headline", text: "New Product", font: "sans" }],
|
| 114 |
+
scene_prompt: p,
|
| 115 |
+
}));
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
try {
|
| 119 |
const body = {
|
| 120 |
session_id: sessionId,
|
| 121 |
openai_key: openaiKey.trim(),
|
|
|
|
| 122 |
wangp_url: wangpUrl.trim(),
|
| 123 |
model_choice: modelChoice,
|
| 124 |
+
resolution, steps, guidance,
|
|
|
|
|
|
|
| 125 |
ref_strength: refStrength,
|
| 126 |
negative_prompt: negativePrompt,
|
| 127 |
};
|
| 128 |
+
if (items) body.items = items;
|
|
|
|
| 129 |
|
| 130 |
const res = await fetch("/api/listing-free/auto-generate", {
|
| 131 |
method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),
|
| 132 |
});
|
| 133 |
const data = await res.json();
|
| 134 |
if (!data.ok && data.error) throw new Error(data.error);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
await pollSession();
|
| 136 |
} catch (e) { setStatus("Error: " + e.message); addLog("error", e.message); }
|
| 137 |
finally { setGenerating(false); }
|
|
|
|
| 175 |
const resetAll = () => {
|
| 176 |
if (pollRef.current) clearTimeout(pollRef.current);
|
| 177 |
if (sessionId) fetch(`/api/listing-free/session/${sessionId}`, { method: "DELETE" }).catch(() => {});
|
| 178 |
+
setSessionId(null); setResults([]); setLogs([]); setStatus(null);
|
| 179 |
+
setPrompts([]); setAutoPrompts(null); setGenerating(false); setBusy(false);
|
| 180 |
if (productPreview) { URL.revokeObjectURL(productPreview); setProductPreview(null); }
|
| 181 |
+
setProductFile(null);
|
|
|
|
|
|
|
|
|
|
| 182 |
};
|
| 183 |
|
| 184 |
return (
|
| 185 |
<div>
|
| 186 |
<div className="h1">Workspace: <span className="accent">Listing ảnh Free</span></div>
|
| 187 |
+
<p className="subtitle">Upload product image → set prompts → Flux/Wangp generates background → design overlay.</p>
|
| 188 |
<div className="grid-2">
|
| 189 |
<div className="stack">
|
| 190 |
+
|
| 191 |
+
{/* Gradio URL */}
|
| 192 |
+
<div className="card">
|
| 193 |
+
<div className="panel-title">Gradio URL</div>
|
| 194 |
+
<input value={wangpUrl} onChange={e => setWangpUrl(e.target.value)}
|
| 195 |
+
placeholder="https://xxx.gradio.live/"
|
| 196 |
+
style={{ width: "100%", fontSize: 13, padding: "7px 12px", border: "1px solid var(--line)", borderRadius: "var(--radius-sm)" }} />
|
| 197 |
+
<div style={{ fontSize: 10, color: "var(--muted)", marginTop: 4 }}>Saved in browser, change only when URL expires.</div>
|
| 198 |
+
</div>
|
| 199 |
+
|
| 200 |
{/* Upload */}
|
| 201 |
<div className="card">
|
| 202 |
+
<div className="panel-title"><IcUpload size={16} /> Upload product image</div>
|
| 203 |
+
<div className="dropzone" style={{ cursor: "pointer" }} onClick={() => prodRef.current?.click()}>
|
| 204 |
+
<input ref={prodRef} type="file" accept="image/jpeg,image/png,image/webp" style={{ display: "none" }}
|
| 205 |
+
onChange={(e) => handleFile(e.target.files?.[0])} />
|
| 206 |
+
{productPreview ? (
|
| 207 |
+
<div>
|
| 208 |
+
<img src={productPreview} alt="" style={{ width: "100%", maxHeight: 280, objectFit: "contain", borderRadius: 8 }} />
|
| 209 |
+
</div>
|
| 210 |
+
) : (
|
| 211 |
+
<div style={{ textAlign: "center", padding: "32px 8px" }}>
|
| 212 |
+
<div className="chip" style={{ margin: "0 auto 8px" }}><IcImage size={24} /></div>
|
| 213 |
+
<div style={{ fontSize: 13, fontWeight: 600 }}>Click to upload</div>
|
| 214 |
+
<div style={{ fontSize: 11, color: "var(--muted)", marginTop: 4 }}>Product image (required)</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
</div>
|
| 216 |
+
)}
|
| 217 |
</div>
|
| 218 |
{productPreview && !sessionId && (
|
| 219 |
<button className="btn primary" style={{ marginTop: 8, width: "100%" }} disabled={busy} onClick={startUpload}>
|
| 220 |
+
{busy ? "Uploading..." : "Upload"}
|
| 221 |
</button>
|
| 222 |
)}
|
| 223 |
</div>
|
| 224 |
|
|
|
|
| 225 |
{sessionId && (
|
| 226 |
+
<>
|
| 227 |
+
{/* Count + Mode */}
|
| 228 |
+
<div className="card">
|
| 229 |
+
<div style={{ display: "flex", gap: 12, marginBottom: 12 }}>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
<div>
|
| 231 |
+
<label style={{ fontSize: 11, color: "var(--muted)", display: "block", marginBottom: 4 }}>Number of images</label>
|
| 232 |
+
<select value={imageCount} onChange={e => { const n = Number(e.target.value); setImageCount(n); if (mode === "manual") setPrompts(prev => { const p = [...prev]; while (p.length < n) p.push(""); return p.slice(0, n); }); }}
|
| 233 |
+
style={{ fontSize: 13, padding: "4px 8px" }}>
|
| 234 |
+
{[1,2,3,4,5,6,7,8,9].map(n => <option key={n} value={n}>{n} images</option>)}
|
| 235 |
+
</select>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
</div>
|
| 237 |
<div>
|
| 238 |
+
<label style={{ fontSize: 11, color: "var(--muted)", display: "block", marginBottom: 4 }}>Mode</label>
|
| 239 |
+
<div style={{ display: "flex", gap: 4 }}>
|
| 240 |
+
<button className={`btn sm ${mode === "manual" ? "primary" : ""}`}
|
| 241 |
+
onClick={() => { setMode("manual"); setPrompts(Array(imageCount).fill("")); setAutoPrompts(null); }}>
|
| 242 |
+
Manual
|
| 243 |
+
</button>
|
| 244 |
+
<button className={`btn sm ${mode === "auto" ? "primary" : ""}`}
|
| 245 |
+
onClick={() => { setMode("auto"); setPrompts([]); }}>
|
| 246 |
+
Auto (GPT)
|
| 247 |
+
</button>
|
| 248 |
+
</div>
|
| 249 |
</div>
|
| 250 |
</div>
|
|
|
|
|
|
|
|
|
|
| 251 |
|
| 252 |
+
{/* Manual: prompt textareas */}
|
| 253 |
+
{mode === "manual" && (
|
| 254 |
+
<div>
|
| 255 |
+
<div style={{ fontSize: 11, color: "var(--muted)", marginBottom: 6 }}>Enter scene prompts (one per image):</div>
|
| 256 |
+
{prompts.map((p, i) => (
|
| 257 |
+
<div key={i} style={{ marginBottom: 6 }}>
|
| 258 |
+
<div style={{ fontSize: 10, fontWeight: 600, marginBottom: 2, color: "var(--ink-2)" }}>Image {i + 1}</div>
|
| 259 |
+
<textarea value={p} onChange={e => { const np = [...prompts]; np[i] = e.target.value; setPrompts(np); }}
|
| 260 |
+
placeholder="Describe the scene: background, lighting, setting, model..."
|
| 261 |
+
style={{ width: "100%", fontSize: 12, padding: "4px 6px", minHeight: 50, resize: "vertical" }} spellCheck={false} />
|
| 262 |
+
</div>
|
| 263 |
+
))}
|
| 264 |
+
</div>
|
| 265 |
+
)}
|
|
|
|
|
|
|
| 266 |
|
| 267 |
+
{/* Auto: OpenAI key */}
|
| 268 |
+
{mode === "auto" && (
|
| 269 |
+
<div>
|
| 270 |
+
<label style={{ fontSize: 11, color: "var(--muted)", display: "block", marginBottom: 4 }}>OpenAI API Key (GPT-4o Vision)</label>
|
| 271 |
+
<div style={{ display: "flex", gap: 6, marginBottom: 8 }}>
|
| 272 |
+
<input type="password" value={openaiKey} onChange={e => setOpenaiKey(e.target.value)}
|
| 273 |
+
placeholder="sk-..."
|
| 274 |
+
style={{ flex: 1, fontSize: 13, padding: "6px 10px", border: "1px solid var(--line)", borderRadius: "var(--radius-sm)" }} />
|
| 275 |
+
{openaiKey && <span style={{ fontSize: 10, color: "var(--green)", alignSelf: "center" }}>Saved ✓</span>}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
</div>
|
| 277 |
+
<button className="btn sm primary" disabled={busy || !openaiKey.trim()} onClick={generateAutoPrompts}>
|
| 278 |
+
{busy ? "Analyzing..." : "Generate prompts with GPT-4o"}
|
| 279 |
+
</button>
|
| 280 |
+
{autoPrompts && (
|
| 281 |
+
<div style={{ marginTop: 8 }}>
|
| 282 |
+
<div style={{ fontSize: 11, color: "var(--green)", marginBottom: 4 }}>Generated {autoPrompts.length} prompts:</div>
|
| 283 |
+
{autoPrompts.map((p, i) => (
|
| 284 |
+
<div key={i} style={{ fontSize: 11, marginBottom: 4, padding: "4px 6px", background: "var(--cream)", borderRadius: "var(--radius-sm)" }}>
|
| 285 |
+
<b>Image {i + 1}</b> ({p.label}): {p.scene_prompt}
|
| 286 |
+
</div>
|
| 287 |
+
))}
|
| 288 |
+
</div>
|
| 289 |
+
)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
</div>
|
| 291 |
+
)}
|
| 292 |
</div>
|
| 293 |
|
| 294 |
+
{/* Config */}
|
| 295 |
+
<div className="card">
|
| 296 |
+
<div className="panel-title">Generation config</div>
|
| 297 |
+
<div style={{ display: "flex", gap: 6, marginBottom: 6 }}>
|
| 298 |
+
<div style={{ flex: 1 }}>
|
| 299 |
+
<label style={{ fontSize: 10, color: "var(--muted)" }}>Model</label>
|
| 300 |
+
<select value={modelChoice} onChange={e => setModelChoice(e.target.value)}
|
| 301 |
+
style={{ width: "100%", fontSize: 12, padding: "4px 6px" }}>
|
| 302 |
+
{MODELS.map(m => <option key={m.value} value={m.value}>{m.label}</option>)}
|
| 303 |
</select>
|
| 304 |
+
</div>
|
| 305 |
+
<div style={{ flex: 1 }}>
|
| 306 |
+
<label style={{ fontSize: 10, color: "var(--muted)" }}>Resolution</label>
|
| 307 |
+
<select value={resolution} onChange={e => setResolution(e.target.value)}
|
| 308 |
+
style={{ width: "100%", fontSize: 12, padding: "4px 6px" }}>
|
| 309 |
+
{RESOLUTIONS.map(r => <option key={r.value} value={r.value}>{r.label}</option>)}
|
| 310 |
</select>
|
| 311 |
</div>
|
| 312 |
+
</div>
|
| 313 |
+
<div style={{ display: "flex", gap: 6, marginBottom: 6 }}>
|
| 314 |
+
<div style={{ flex: 1 }}>
|
| 315 |
+
<label style={{ fontSize: 10, color: "var(--muted)" }}>Steps</label>
|
| 316 |
+
<input type="number" value={steps} onChange={e => setSteps(Number(e.target.value))}
|
| 317 |
+
min={1} max={50} style={{ width: "100%", fontSize: 12, padding: "4px 6px" }} />
|
| 318 |
+
</div>
|
| 319 |
+
<div style={{ flex: 1 }}>
|
| 320 |
+
<label style={{ fontSize: 10, color: "var(--muted)" }}>Guidance</label>
|
| 321 |
+
<input type="number" value={guidance} onChange={e => setGuidance(Number(e.target.value))}
|
| 322 |
+
min={1} max={20} step={0.5} style={{ width: "100%", fontSize: 12, padding: "4px 6px" }} />
|
| 323 |
+
</div>
|
| 324 |
+
<div style={{ flex: 1 }}>
|
| 325 |
+
<label style={{ fontSize: 10, color: "var(--muted)" }}>Ref Strength</label>
|
| 326 |
+
<input type="number" value={refStrength} onChange={e => setRefStrength(Number(e.target.value))}
|
| 327 |
+
min={0} max={100} style={{ width: "100%", fontSize: 12, padding: "4px 6px" }} />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
</div>
|
| 329 |
</div>
|
| 330 |
+
<div>
|
| 331 |
+
<label style={{ fontSize: 10, color: "var(--muted)" }}>Negative Prompt</label>
|
| 332 |
+
<textarea value={negativePrompt} onChange={e => setNegativePrompt(e.target.value)}
|
| 333 |
+
style={{ width: "100%", fontSize: 11, minHeight: 50, padding: "4px 6px" }} spellCheck={false} />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
</div>
|
| 335 |
+
</div>
|
| 336 |
|
| 337 |
+
{/* Generate */}
|
| 338 |
+
<button className="btn" style={{ width: "100%", fontSize: 14, padding: "10px", background: "var(--orange)", color: "#fff", border: "none", fontWeight: 600 }}
|
| 339 |
+
disabled={generating} onClick={doGenerate}>
|
| 340 |
+
{generating ? "Generating..." : `Generate ${mode === "manual" ? prompts.filter(p => p.trim()).length : (autoPrompts?.length || imageCount)} images`}
|
| 341 |
+
</button>
|
| 342 |
+
</>
|
|
|
|
| 343 |
)}
|
| 344 |
|
| 345 |
{/* Log */}
|
| 346 |
+
{logs.length > 0 && (
|
| 347 |
<div className="card">
|
| 348 |
<div className="panel-title">Progress</div>
|
| 349 |
+
{generating && <div className="progress" style={{ marginBottom: 10 }}><i style={{ width: progress + "%" }} /></div>}
|
| 350 |
{status && <div style={{ fontSize: 13, color: "var(--ink-2)", marginBottom: 8 }}>{status}</div>}
|
| 351 |
<div className="logbox" style={{ maxHeight: 200, fontSize: 11, lineHeight: 1.6 }}>
|
| 352 |
{logs.map((l, i) => <div key={i} className={l.includes("✅") ? "ok" : l.includes("❌") ? "err" : ""}>{l}</div>)}
|
|
|
|
| 379 |
<div className="chip" style={{ margin: "0 auto 12px" }}><IcStar size={24} /></div>
|
| 380 |
<div style={{ fontSize: 14, fontWeight: 600, marginBottom: 6 }}>Listing ảnh Free</div>
|
| 381 |
<div style={{ fontSize: 12, lineHeight: 1.6 }}>
|
| 382 |
+
Upload product image, write scene prompts (or let GPT generate them), then Flux/Wangp creates backgrounds + design overlay.
|
| 383 |
</div>
|
| 384 |
</div>
|
| 385 |
)}
|
| 386 |
</div>
|
| 387 |
|
| 388 |
<div className="rail">
|
| 389 |
+
<div className="rail-title">How it works</div>
|
| 390 |
+
<div className="rail-step"><div className="num">1</div><div className="body"><div className="t">Gradio URL</div><div className="d">Paste your Flux/Wangp Space URL (saved automatically)</div></div></div>
|
| 391 |
+
<div className="rail-step"><div className="num">2</div><div className="body"><div className="t">Upload image</div><div className="d">Single product image</div></div></div>
|
| 392 |
+
<div className="rail-step"><div className="num">3</div><div className="body"><div className="t">Choose mode</div><div className="d">Manual: write your own scene prompts. Auto: GPT-4o generates them.</div></div></div>
|
| 393 |
+
<div className="rail-step"><div className="num">4</div><div className="body"><div className="t">Configure</div><div className="d">Model, resolution, steps, guidance, ref strength, negative prompt</div></div></div>
|
| 394 |
+
<div className="rail-step"><div className="num">5</div><div className="body"><div className="t">Generate</div><div className="d">Flux/Wangp creates backgrounds → Pillow overlays text design</div></div></div>
|
| 395 |
+
<div className="rail-step"><div className="num">6</div><div className="body"><div className="t">Download</div><div className="d">All images as zip file</div></div></div>
|
| 396 |
+
<div className="tip"><b>Tip:</b> OpenAI key is saved in browser. Gradio URL is also saved. Set once, use many times.</div>
|
| 397 |
</div>
|
| 398 |
</div>
|
| 399 |
</div>
|