userIdc2024 commited on
Commit
2064695
Β·
verified Β·
1 Parent(s): 6ed5274

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +8 -110
src/streamlit_app.py CHANGED
@@ -19,7 +19,6 @@ from design_generation import (
19
  OUTPUT_DIR,
20
  analyze_jewellery,
21
  create_zip_from_images,
22
- generate_auto_design_image,
23
  generate_design_directions,
24
  generate_final_images,
25
  generate_six_campaign_images,
@@ -1162,9 +1161,9 @@ with tab_research:
1162
  r_done.append(1)
1163
  if "processed_product_refs" in st.session_state:
1164
  r_done.append(2)
1165
- if "design_options_per_product" in st.session_state or "auto_design_results" in st.session_state:
1166
  r_done.append(3)
1167
- if "all_final_images" in st.session_state or "auto_design_results" in st.session_state:
1168
  r_done.append(4)
1169
  r_current = (max(r_done) + 1) if r_done else 1
1170
 
@@ -1230,8 +1229,7 @@ with tab_research:
1230
  st.session_state["researched_products"] = products
1231
  st.session_state["research_keywords_order"] = keywords
1232
  for key in ["processed_product_refs", "design_options_per_product",
1233
- "frozen_selected_campaigns", "all_final_images",
1234
- "auto_design_results"]:
1235
  st.session_state.pop(key, None)
1236
  status_ui.update(label=f"Done β€” {len(products)} products found.", state="complete")
1237
  st.rerun()
@@ -1313,8 +1311,6 @@ with tab_research:
1313
  if checked:
1314
  selected_product_ids.add(pid)
1315
 
1316
- st.markdown("---")
1317
-
1318
  st.markdown("---")
1319
  col_proc, col_cnt = st.columns([1, 3])
1320
  with col_proc:
@@ -1337,8 +1333,7 @@ with tab_research:
1337
  if p.get("local_image_path") and Path(p["local_image_path"]).exists()
1338
  ]
1339
  st.session_state["processed_product_refs"] = processed_refs
1340
- for key in ["design_options_per_product", "frozen_selected_campaigns",
1341
- "all_final_images", "auto_design_results"]:
1342
  st.session_state.pop(key, None)
1343
  st.rerun()
1344
 
@@ -1352,28 +1347,10 @@ with tab_research:
1352
  ):
1353
  st.markdown(
1354
  f"**{len(processed_refs)} product(s)** ready. "
1355
- "Generate 5 design direction previews per product, then pick one direction per product."
1356
  )
1357
 
1358
- col_gen, col_auto = st.columns(2)
1359
- with col_gen:
1360
- gen_designs_btn = st.button(
1361
- "Generate Design Directions",
1362
- type="primary",
1363
- key="btn_gen_designs",
1364
- use_container_width=True,
1365
- help="Generate 5 direction previews per product, then pick one per product.",
1366
- )
1367
- with col_auto:
1368
- auto_gen_btn = st.button(
1369
- "Auto-Generate All Designs",
1370
- type="primary",
1371
- key="btn_auto_gen",
1372
- use_container_width=True,
1373
- help="Auto-generate one design per product and show results grouped by keyword.",
1374
- )
1375
-
1376
- if gen_designs_btn:
1377
  design_options_per_product: Dict[str, Any] = {}
1378
 
1379
  for item in processed_refs:
@@ -1407,43 +1384,10 @@ with tab_research:
1407
  st.error(f"{pname}: {e}")
1408
 
1409
  st.session_state["design_options_per_product"] = design_options_per_product
1410
- st.session_state.pop("auto_design_results", None)
1411
  for key in ["frozen_selected_campaigns", "all_final_images"]:
1412
  st.session_state.pop(key, None)
1413
  st.rerun()
1414
 
1415
- if auto_gen_btn:
1416
- auto_design_results: Dict[str, List[Dict[str, Any]]] = {}
1417
- total = len(processed_refs)
1418
- progress_bar = st.progress(0, text=f"Generating designs β€” 0 / {total} products…")
1419
-
1420
- for idx, item in enumerate(processed_refs):
1421
- product = item["product"]
1422
- image_path = item["image_path"]
1423
- keyword = product.get("source_keyword", "Other")
1424
- pname = product.get("product_name", "Product")
1425
-
1426
- progress_bar.progress(
1427
- idx / total if total else 0,
1428
- text=f"Generating design {idx + 1}/{total}: {pname[:40]}…",
1429
- )
1430
-
1431
- try:
1432
- result = generate_auto_design_image(image_path)
1433
- auto_design_results.setdefault(keyword, []).append({
1434
- "product": product,
1435
- "design_path": result["design_path"],
1436
- "design_name": result["design_name"],
1437
- })
1438
- except Exception as e:
1439
- st.warning(f"Skipped {pname}: {e}")
1440
-
1441
- progress_bar.progress(1.0, text=f"Done β€” {total} designs generated.")
1442
- st.session_state["auto_design_results"] = auto_design_results
1443
- for key in ["design_options_per_product", "frozen_selected_campaigns", "all_final_images"]:
1444
- st.session_state.pop(key, None)
1445
- st.rerun()
1446
-
1447
  if "design_options_per_product" in st.session_state:
1448
  design_opts = st.session_state["design_options_per_product"]
1449
  selected_campaigns: Dict[str, Any] = {}
@@ -1455,7 +1399,7 @@ with tab_research:
1455
  brand = product.get("brand", "")
1456
 
1457
  st.markdown(f"#### {pname} β€” {brand}")
1458
- st.caption("Review the 5 design directions, then choose one below.")
1459
 
1460
  d_cols = st.columns(3)
1461
  for idx, design in enumerate(design_options):
@@ -1565,52 +1509,6 @@ with tab_research:
1565
 
1566
  st.divider()
1567
 
1568
- # ── Step 4 (Auto) Β· Designs grouped by keyword ───────────────────────────
1569
- if "auto_design_results" in st.session_state:
1570
- auto_results = st.session_state["auto_design_results"]
1571
- kw_order = st.session_state.get(
1572
- "research_keywords_order",
1573
- list(auto_results.keys()),
1574
- )
1575
- total_designs = sum(len(v) for v in auto_results.values())
1576
-
1577
- with st.expander(
1578
- f"Step 4 Β· Auto-Generated Designs by Keyword ({total_designs} designs across {len(auto_results)} keyword(s))",
1579
- expanded=True,
1580
- ):
1581
- for kw in kw_order:
1582
- entries = auto_results.get(kw, [])
1583
- if not entries:
1584
- continue
1585
-
1586
- st.markdown(f"### {kw}")
1587
- n_cols = min(len(entries), 5)
1588
- cols = st.columns(n_cols)
1589
- for i, entry in enumerate(entries):
1590
- design_path = entry.get("design_path", "")
1591
- with cols[i % n_cols]:
1592
- if design_path and Path(design_path).exists():
1593
- st.image(design_path, use_container_width=True)
1594
- pname = entry["product"].get("product_name", "")
1595
- label = entry.get("design_name", "")
1596
- st.caption(
1597
- f"{label}"
1598
- + (f" Β· {pname[:22]}…" if len(pname) > 22 else (f" Β· {pname}" if pname else ""))
1599
- )
1600
- with open(design_path, "rb") as f:
1601
- st.download_button(
1602
- "Download",
1603
- data=f,
1604
- file_name=Path(design_path).name,
1605
- mime="image/jpeg",
1606
- key=f"dl_auto_{kw}_{i}",
1607
- use_container_width=True,
1608
- )
1609
- else:
1610
- st.caption("Image unavailable")
1611
-
1612
- st.divider()
1613
-
1614
 
1615
  # ══════════════════════════════════════════════════════════════════════════════
1616
  # UPLOAD WORKFLOW
@@ -1697,7 +1595,7 @@ with tab_upload:
1697
  campaign_options = st.session_state["upload_campaign_options"]
1698
 
1699
  with st.expander("Step 2 Β· Choose a Design Direction", expanded=(u_current == 2)):
1700
- st.markdown("Review the 5 design directions and select one to generate your final campaign images.")
1701
 
1702
  d_cols = st.columns(3)
1703
  for idx, campaign in enumerate(campaign_options):
 
19
  OUTPUT_DIR,
20
  analyze_jewellery,
21
  create_zip_from_images,
 
22
  generate_design_directions,
23
  generate_final_images,
24
  generate_six_campaign_images,
 
1161
  r_done.append(1)
1162
  if "processed_product_refs" in st.session_state:
1163
  r_done.append(2)
1164
+ if "design_options_per_product" in st.session_state:
1165
  r_done.append(3)
1166
+ if "all_final_images" in st.session_state:
1167
  r_done.append(4)
1168
  r_current = (max(r_done) + 1) if r_done else 1
1169
 
 
1229
  st.session_state["researched_products"] = products
1230
  st.session_state["research_keywords_order"] = keywords
1231
  for key in ["processed_product_refs", "design_options_per_product",
1232
+ "frozen_selected_campaigns", "all_final_images"]:
 
1233
  st.session_state.pop(key, None)
1234
  status_ui.update(label=f"Done β€” {len(products)} products found.", state="complete")
1235
  st.rerun()
 
1311
  if checked:
1312
  selected_product_ids.add(pid)
1313
 
 
 
1314
  st.markdown("---")
1315
  col_proc, col_cnt = st.columns([1, 3])
1316
  with col_proc:
 
1333
  if p.get("local_image_path") and Path(p["local_image_path"]).exists()
1334
  ]
1335
  st.session_state["processed_product_refs"] = processed_refs
1336
+ for key in ["design_options_per_product", "frozen_selected_campaigns", "all_final_images"]:
 
1337
  st.session_state.pop(key, None)
1338
  st.rerun()
1339
 
 
1347
  ):
1348
  st.markdown(
1349
  f"**{len(processed_refs)} product(s)** ready. "
1350
+ "Generate 6 design direction previews per product, then pick one direction per product."
1351
  )
1352
 
1353
+ if st.button("Generate Design Directions", type="primary", key="btn_gen_designs"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1354
  design_options_per_product: Dict[str, Any] = {}
1355
 
1356
  for item in processed_refs:
 
1384
  st.error(f"{pname}: {e}")
1385
 
1386
  st.session_state["design_options_per_product"] = design_options_per_product
 
1387
  for key in ["frozen_selected_campaigns", "all_final_images"]:
1388
  st.session_state.pop(key, None)
1389
  st.rerun()
1390
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1391
  if "design_options_per_product" in st.session_state:
1392
  design_opts = st.session_state["design_options_per_product"]
1393
  selected_campaigns: Dict[str, Any] = {}
 
1399
  brand = product.get("brand", "")
1400
 
1401
  st.markdown(f"#### {pname} β€” {brand}")
1402
+ st.caption("Review the 6 design directions, then choose one below.")
1403
 
1404
  d_cols = st.columns(3)
1405
  for idx, design in enumerate(design_options):
 
1509
 
1510
  st.divider()
1511
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1512
 
1513
  # ══════════════════════════════════════════════════════════════════════════════
1514
  # UPLOAD WORKFLOW
 
1595
  campaign_options = st.session_state["upload_campaign_options"]
1596
 
1597
  with st.expander("Step 2 Β· Choose a Design Direction", expanded=(u_current == 2)):
1598
+ st.markdown("Review the 6 design directions and select one to generate your final campaign images.")
1599
 
1600
  d_cols = st.columns(3)
1601
  for idx, campaign in enumerate(campaign_options):