ginipick commited on
Commit
1e4825e
Β·
verified Β·
1 Parent(s): 15955aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -28
app.py CHANGED
@@ -688,11 +688,11 @@ def idea_generator_app():
688
 
689
  sb.subheader("Example Prompts")
690
  c1, c2, c3 = sb.columns(3)
691
- if c1.button("AI & λΉ„μ¦ˆλ‹ˆμŠ€", key="ex1"):
692
  process_example(example_topics["example1"])
693
- if c2.button("슀마트 μ†Œμž¬ 건좕", key="ex2"):
694
  process_example(example_topics["example2"])
695
- if c3.button("λ―Έλž˜ν˜• ꡐ윑", key="ex3"):
696
  process_example(example_topics["example3"])
697
 
698
  # Download the latest ideas
@@ -880,42 +880,46 @@ def process_input(prompt: str, uploaded_files):
880
  status.update(label="Ideas created!", state="complete")
881
 
882
  # ── β‘€ 이미지 생성
 
883
  if st.session_state.generate_image and full_response:
884
 
885
- idea_sections = re.split(r"(##\s*Idea\s*\d+\s*:?)", full_response, flags=re.IGNORECASE)
886
- pairs = [(idea_sections[i].strip(),
887
- idea_sections[i+1].strip() if i+1 < len(idea_sections) else "")
888
- for i in range(1, len(idea_sections), 2)]
889
-
890
-
891
- for title, text_block in pairs:
892
-
893
- table_match = re.search(
894
- r"\|\s*(?:\*\*)?Image\s+Prompt(?:\*\*)?\s*\|\s*([^|\n]+)", # ← μˆ˜μ •
895
- text_block, flags=re.IGNORECASE)
896
-
897
- if not table_match:
898
- table_match = re.search(
899
- r"(?i)Image\s+Prompt\s*[:\-]\s*([^\n]+)", text_block)
900
-
901
- if not table_match:
902
- continue # 이 아이디어엔 ν”„λ‘¬ν”„νŠΈ μ—†μŒ β†’ κ±΄λ„ˆλœ€
903
-
904
- raw_prompt = re.sub(r"[\r\n`\"'\\]", " ", table_match.group(1)).strip()
905
-
906
- with st.spinner(f"Generating image for {title}…"):
 
907
  img, cap = generate_image(raw_prompt)
908
 
909
  if img:
910
- st.image(img, caption=f"{title} – {cap}")
 
911
  st.session_state.messages.append({
912
  "role": "assistant",
913
  "content": "",
914
  "image": img,
915
- "image_caption": f"{title} – {cap}"
916
  })
 
 
917
 
918
-
919
 
920
  # ── β‘₯ κ²°κ³Ό μ €μž₯
921
  st.session_state.messages.append(
 
688
 
689
  sb.subheader("Example Prompts")
690
  c1, c2, c3 = sb.columns(3)
691
+ if c1.button("λ„μ‹œ λ¬Ό λΆ€μ‘± 문제", key="ex1"):
692
  process_example(example_topics["example1"])
693
+ if c2.button("노인 λŒλ΄„ μ„œλΉ„μŠ€", key="ex2"):
694
  process_example(example_topics["example2"])
695
+ if c3.button("지속가λŠ₯ν•œ μ‹ν’ˆ 포μž₯", key="ex3"):
696
  process_example(example_topics["example3"])
697
 
698
  # Download the latest ideas
 
880
  status.update(label="Ideas created!", state="complete")
881
 
882
  # ── β‘€ 이미지 생성
883
+ # ── β‘€ 이미지 생성 (κΈ°μ‘΄ 블둝 μ „λΆ€ ꡐ체) ─────────────────────────────
884
  if st.session_state.generate_image and full_response:
885
 
886
+ # 1️⃣ ❢ CCM μŠ€νƒ€μΌ: "### 이미지 ν”„λ‘¬ν”„νŠΈ" ν—€λ”© μ•„λž˜ 쀄
887
+ ccm_match = re.search(
888
+ r"###\s*이미지\s*ν”„λ‘¬ν”„νŠΈ\s*\n+([^\n]+)",
889
+ full_response, flags=re.IGNORECASE)
890
+
891
+ # 2️⃣ ❷ 이전 μŠ€νƒ€μΌ: ν…Œμ΄λΈ” or "Image Prompt:"
892
+ legacy_match = None
893
+ if not ccm_match:
894
+ legacy_match = re.search(
895
+ r"\|\s*(?:\*\*)?Image\s+Prompt(?:\*\*)?\s*\|\s*([^|\n]+)",
896
+ full_response, flags=re.IGNORECASE)
897
+ if not legacy_match:
898
+ legacy_match = re.search(
899
+ r"(?i)Image\s+Prompt\s*[:\-]\s*([^\n]+)",
900
+ full_response)
901
+
902
+ # 3️⃣ μ΅œμ’… ν”„λ‘¬ν”„νŠΈ μΆ”μΆœ
903
+ match = ccm_match or legacy_match
904
+ if match:
905
+ raw_prompt = re.sub(r"[\r\n`\"'\\]", " ",
906
+ match.group(1)).strip()
907
+
908
+ with st.spinner("아이디어 이미지 생성 쀑…"):
909
  img, cap = generate_image(raw_prompt)
910
 
911
  if img:
912
+ st.image(img, caption=f"아이디어 μ‹œκ°ν™” – {cap}")
913
+ # λŒ€ν™” 기둝에 이미지도 μ €μž₯
914
  st.session_state.messages.append({
915
  "role": "assistant",
916
  "content": "",
917
  "image": img,
918
+ "image_caption": f"아이디어 μ‹œκ°ν™” – {cap}"
919
  })
920
+
921
+
922
 
 
923
 
924
  # ── β‘₯ κ²°κ³Ό μ €μž₯
925
  st.session_state.messages.append(