Spaces:
Running
Running
fix: GPT now generates exactly N prompts (respect count), not always 9
Browse files
backend/app/api/listing_free.py
CHANGED
|
@@ -68,6 +68,7 @@ async def analyze_product(body: dict):
|
|
| 68 |
sid = body.get("session_id")
|
| 69 |
openai_key = body.get("openai_key", "").strip()
|
| 70 |
product_info = body.get("product_info", "").strip()
|
|
|
|
| 71 |
|
| 72 |
if not openai_key:
|
| 73 |
raise HTTPException(400, "Missing OpenAI API key")
|
|
@@ -83,6 +84,7 @@ async def analyze_product(body: dict):
|
|
| 83 |
from ..services.listing_free.gpt_analysis import extract_attributes, generate_prompts
|
| 84 |
attrs = extract_attributes(img_path, openai_key, product_info)
|
| 85 |
prompts = generate_prompts(attrs, openai_key)
|
|
|
|
| 86 |
s["attributes"] = attrs
|
| 87 |
s["prompts"] = prompts
|
| 88 |
return {"ok": True, "attributes": attrs, "prompts": prompts, "count": len(prompts)}
|
|
|
|
| 68 |
sid = body.get("session_id")
|
| 69 |
openai_key = body.get("openai_key", "").strip()
|
| 70 |
product_info = body.get("product_info", "").strip()
|
| 71 |
+
count = min(body.get("count", 9), 9)
|
| 72 |
|
| 73 |
if not openai_key:
|
| 74 |
raise HTTPException(400, "Missing OpenAI API key")
|
|
|
|
| 84 |
from ..services.listing_free.gpt_analysis import extract_attributes, generate_prompts
|
| 85 |
attrs = extract_attributes(img_path, openai_key, product_info)
|
| 86 |
prompts = generate_prompts(attrs, openai_key)
|
| 87 |
+
prompts = prompts[:count]
|
| 88 |
s["attributes"] = attrs
|
| 89 |
s["prompts"] = prompts
|
| 90 |
return {"ok": True, "attributes": attrs, "prompts": prompts, "count": len(prompts)}
|
frontend/src/pages/ListingFree.jsx
CHANGED
|
@@ -104,7 +104,7 @@ export default function ListingFree() {
|
|
| 104 |
try {
|
| 105 |
const res = await fetch("/api/listing-free/analyze", {
|
| 106 |
method: "POST", headers: { "Content-Type": "application/json" },
|
| 107 |
-
body: JSON.stringify({ session_id: sessionId, openai_key: openaiKey.trim() }),
|
| 108 |
});
|
| 109 |
const data = await res.json();
|
| 110 |
if (!data.ok && data.error) throw new Error(data.error);
|
|
@@ -394,7 +394,7 @@ export default function ListingFree() {
|
|
| 394 |
{/* Generate */}
|
| 395 |
<button className="btn" style={{ width: "100%", fontSize: 14, padding: "10px", background: "var(--orange)", color: "#fff", border: "none", fontWeight: 600 }}
|
| 396 |
disabled={generating} onClick={doGenerate}>
|
| 397 |
-
{generating ? "Generating..." : `Generate ${mode === "manual" ? prompts.filter(p => p.trim()).length :
|
| 398 |
</button>
|
| 399 |
</>
|
| 400 |
)}
|
|
|
|
| 104 |
try {
|
| 105 |
const res = await fetch("/api/listing-free/analyze", {
|
| 106 |
method: "POST", headers: { "Content-Type": "application/json" },
|
| 107 |
+
body: JSON.stringify({ session_id: sessionId, openai_key: openaiKey.trim(), count: imageCount }),
|
| 108 |
});
|
| 109 |
const data = await res.json();
|
| 110 |
if (!data.ok && data.error) throw new Error(data.error);
|
|
|
|
| 394 |
{/* Generate */}
|
| 395 |
<button className="btn" style={{ width: "100%", fontSize: 14, padding: "10px", background: "var(--orange)", color: "#fff", border: "none", fontWeight: 600 }}
|
| 396 |
disabled={generating} onClick={doGenerate}>
|
| 397 |
+
{generating ? "Generating..." : `Generate ${mode === "manual" ? prompts.filter(p => p.trim()).length : (autoPrompts?.length || imageCount)} images`}
|
| 398 |
</button>
|
| 399 |
</>
|
| 400 |
)}
|