Spaces:
Sleeping
Sleeping
feat: manual prompt generation — generate 9 scene prompts from product description without GPT
Browse files
frontend/src/pages/ListingFree.jsx
CHANGED
|
@@ -74,6 +74,7 @@ export default function ListingFree() {
|
|
| 74 |
const [gptPrompts, setGptPrompts] = useState(null);
|
| 75 |
const [showGptList, setShowGptList] = useState(true);
|
| 76 |
const [showProductInfoInput, setShowProductInfoInput] = useState(false);
|
|
|
|
| 77 |
|
| 78 |
const pollRef = useRef(null);
|
| 79 |
const prodRef = useRef(null);
|
|
@@ -118,6 +119,33 @@ export default function ListingFree() {
|
|
| 118 |
const removeItem = (idx) => setItems(prev => prev.filter((_, i) => i !== idx));
|
| 119 |
const updateItem = (idx, patch) => setItems(prev => prev.map((it, i) => i === idx ? { ...it, ...patch } : it));
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
const storeKey = "tnt_listing_free_key";
|
| 122 |
useEffect(() => { try { localStorage.setItem(storeKey, openaiKey); } catch {} }, [openaiKey]);
|
| 123 |
useEffect(() => { try { setOpenaiKey(localStorage.getItem(storeKey) || ""); } catch {} }, []);
|
|
@@ -373,6 +401,23 @@ export default function ListingFree() {
|
|
| 373 |
</div>
|
| 374 |
)}
|
| 375 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 376 |
{/* GPT Prompts -> items */}
|
| 377 |
{gptPrompts && gptPrompts.length > 0 && items.length === 0 && (
|
| 378 |
<div className="card">
|
|
|
|
| 74 |
const [gptPrompts, setGptPrompts] = useState(null);
|
| 75 |
const [showGptList, setShowGptList] = useState(true);
|
| 76 |
const [showProductInfoInput, setShowProductInfoInput] = useState(false);
|
| 77 |
+
const [manualPromptText, setManualPromptText] = useState("");
|
| 78 |
|
| 79 |
const pollRef = useRef(null);
|
| 80 |
const prodRef = useRef(null);
|
|
|
|
| 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 {} }, []);
|
|
|
|
| 401 |
</div>
|
| 402 |
)}
|
| 403 |
|
| 404 |
+
{/* Manual prompt generation */}
|
| 405 |
+
{sessionId && !gptPrompts && (
|
| 406 |
+
<div className="card">
|
| 407 |
+
<div className="panel-title">Manual prompt generation</div>
|
| 408 |
+
<div style={{ fontSize: 12, color: "var(--ink-2)", marginBottom: 6 }}>
|
| 409 |
+
Describe your product — 9 scene prompts will be auto-generated for each listing type.
|
| 410 |
+
</div>
|
| 411 |
+
<textarea value={manualPromptText} onChange={e => setManualPromptText(e.target.value)}
|
| 412 |
+
placeholder='e.g. "Sữa rửa mặt trà xanh cho da dầu mụn"'
|
| 413 |
+
style={{ width: "100%", minHeight: 60, fontSize: 12, padding: "6px 8px", marginBottom: 6 }} spellCheck={false} />
|
| 414 |
+
<button className="btn sm primary" style={{ fontSize: 12 }}
|
| 415 |
+
disabled={!manualPromptText.trim()} onClick={generateManualPrompts}>
|
| 416 |
+
Generate 9 prompts manually
|
| 417 |
+
</button>
|
| 418 |
+
</div>
|
| 419 |
+
)}
|
| 420 |
+
|
| 421 |
{/* GPT Prompts -> items */}
|
| 422 |
{gptPrompts && gptPrompts.length > 0 && items.length === 0 && (
|
| 423 |
<div className="card">
|