ginipick commited on
Commit
fa21362
·
verified ·
1 Parent(s): 82507ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -846,24 +846,28 @@ def process_input(prompt: str, uploaded_files):
846
 
847
  # ── ⑤ 이미지 생성
848
  if st.session_state.generate_image and full_response:
849
- idea_sections = re.split(r"(## Idea \d+:)", full_response)
 
850
  pairs = [(idea_sections[i].strip(),
851
  idea_sections[i+1].strip() if i+1 < len(idea_sections) else "")
852
  for i in range(1, len(idea_sections), 2)]
853
 
 
854
  for title, text_block in pairs:
 
855
  table_match = re.search(
856
- r"\|\s*\*\*Image\s+Prompt\*\*\s*\|\s*([^\n\|]+)",
857
  text_block, flags=re.IGNORECASE)
 
 
858
  if not table_match:
859
  table_match = re.search(
860
- r"(?i)Image\s+Prompt\s*[:|-]\s*([^\n]+)", text_block)
861
 
862
  if not table_match:
863
- continue
864
 
865
- raw_prompt = re.sub(r"[\r\n\|`'\"\\]", " ",
866
- table_match.group(1).strip())
867
 
868
  with st.spinner(f"Generating image for {title}…"):
869
  img, cap = generate_image(raw_prompt)
@@ -877,6 +881,8 @@ def process_input(prompt: str, uploaded_files):
877
  "image_caption": f"{title} – {cap}"
878
  })
879
 
 
 
880
  # ── ⑥ 결과 저장
881
  st.session_state.messages.append(
882
  {"role": "assistant", "content": full_response})
 
846
 
847
  # ── ⑤ 이미지 생성
848
  if st.session_state.generate_image and full_response:
849
+
850
+ idea_sections = re.split(r"(##\s*Idea\s*\d+\s*:?)", full_response, flags=re.IGNORECASE)
851
  pairs = [(idea_sections[i].strip(),
852
  idea_sections[i+1].strip() if i+1 < len(idea_sections) else "")
853
  for i in range(1, len(idea_sections), 2)]
854
 
855
+ # ❷ 이미지 프롬프트 추출 – 표/콜론/하이픈 모든 변형 지원
856
  for title, text_block in pairs:
857
+ # 표 형태 | Image Prompt | ... | (굵게 표기 유/무)
858
  table_match = re.search(
859
+ r"\|\s*(?:\*\*)?Image\s+Prompt(?:\*\*)?\s*\|\s*([^|\n]+)", # ← 수정
860
  text_block, flags=re.IGNORECASE)
861
+
862
+ # 텍스트 형태 Image Prompt : ... 또는 Image Prompt - ...
863
  if not table_match:
864
  table_match = re.search(
865
+ r"(?i)Image\s+Prompt\s*[:\-]\s*([^\n]+)", text_block)
866
 
867
  if not table_match:
868
+ continue # 이 아이디어엔 프롬프트 없음 → 건너뜀
869
 
870
+ raw_prompt = re.sub(r"[\r\n`\"'\\]", " ", table_match.group(1)).strip()
 
871
 
872
  with st.spinner(f"Generating image for {title}…"):
873
  img, cap = generate_image(raw_prompt)
 
881
  "image_caption": f"{title} – {cap}"
882
  })
883
 
884
+
885
+
886
  # ── ⑥ 결과 저장
887
  st.session_state.messages.append(
888
  {"role": "assistant", "content": full_response})