AIRider commited on
Commit
b4d724f
Β·
verified Β·
1 Parent(s): f0b6a8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -132,7 +132,7 @@ def generate_blog_post(query, prompt_template):
132
  try:
133
  # λͺ©ν‘œ κΈ€μžμˆ˜ μ„€μ • (문자 수)
134
  target_char_length = 2000
135
- max_attempts = 2 # μ΅œλŒ€ μ‹œλ„ 횟수 (초기 μ‹œλ„ 1회 + μž¬μ‹œλ„ 1회)
136
 
137
  # μ°Έκ³ κΈ€ κ°€μ Έμ˜€κΈ°
138
  references = fetch_references(query)
@@ -159,15 +159,17 @@ def generate_blog_post(query, prompt_template):
159
  'μš”μ•½'
160
  ]
161
 
162
- # λΆˆν•„μš”ν•œ ν‘œν˜„ 제거 ν•¨μˆ˜
163
  def remove_unwanted_phrases(text):
164
- for phrase in unwanted_phrases:
165
- # μ •κ·œμ‹ νŒ¨ν„΄ 생성: λΆˆν•„μš”ν•œ ν‘œν˜„ + λ’€μ˜ 곡백듀
166
- pattern = re.compile(re.escape(phrase) + r'\s*')
167
- text = pattern.sub('', text)
168
- # μ—°μ†λœ 곡백을 ν•˜λ‚˜μ˜ 곡백으둜 μΉ˜ν™˜
169
- text = re.sub(r'\s+', ' ', text).strip()
170
- return text
 
 
171
 
172
  # 초기 ν”„λ‘¬ν”„νŠΈ ꡬ성
173
  base_prompt = prompt_template + f"""
@@ -182,10 +184,10 @@ def generate_blog_post(query, prompt_template):
182
  # 첫 번째 μ‹œλ„ μ΄ν›„μ—λŠ” ν”„λ‘¬ν”„νŠΈμ— μΆ”κ°€ 지침을 포함
183
  if attempt > 0:
184
  additional_instructions = f"""
185
- 1. μƒμ„±λœ κΈ€μ˜ 길이가 λͺ©ν‘œ κΈ€μžμˆ˜μ— 미달, λ‚΄μš©μ˜ μ§ˆμ„ μœ μ§€ν•˜κ³  λ”μš± ν’λΆ€ν•˜κ²Œ μž‘μ„±ν•˜κ³ , 세뢀사항을 μΆ”κ°€ν•˜μ—¬ μžμ—°μŠ€λŸ½κ²Œ ν™•μž₯ν•˜λΌ
186
- 2. μ€‘λ³΅λ˜λŠ” λ‚΄μš©μ€ ν”Όν•˜κ³  μƒˆλ‘œμš΄ 정보λ₯Ό μΆ”κ°€ν•˜λΌ
187
- 3. λ°˜λ“œμ‹œ λ§ˆν¬λ‹€μš΄ ν˜•μ‹μ΄ μ•„λ‹Œ μˆœμˆ˜ν•œ ν…μŠ€νŠΈλ‘œλ§Œ 좜λ ₯ν•˜λΌ
188
- 4. λ°˜λ“œμ‹œ 이 ν‘œν˜„λ“€μ€ μ‚­μ œν•˜λΌ: μ—¬λŸ¬λΆ„, 졜근, λ§ˆμ§€λ§‰μœΌλ‘œ, 결둠적으둜, κ²°κ΅­, μ’…ν•©μ μœΌλ‘œ, λ”°λΌμ„œ, 마무리, μš”μ•½.
189
  """
190
  else:
191
  additional_instructions = ""
 
132
  try:
133
  # λͺ©ν‘œ κΈ€μžμˆ˜ μ„€μ • (문자 수)
134
  target_char_length = 2000
135
+ max_attempts = 2 # μ΅œλŒ€ μ‹œλ„ 횟수
136
 
137
  # μ°Έκ³ κΈ€ κ°€μ Έμ˜€κΈ°
138
  references = fetch_references(query)
 
159
  'μš”μ•½'
160
  ]
161
 
162
+ # λΆˆν•„μš”ν•œ ν‘œν˜„μ΄ ν¬ν•¨λœ 단어 전체λ₯Ό μ œκ±°ν•˜λŠ” ν•¨μˆ˜
163
  def remove_unwanted_phrases(text):
164
+ # 단어 λ‹¨μœ„λ‘œ ν…μŠ€νŠΈλ₯Ό λΆ„ν• 
165
+ words = re.findall(r'\S+|\n', text)
166
+ result_words = []
167
+ for word in words:
168
+ # λΆˆν•„μš”ν•œ ν‘œν˜„μ΄ 단어에 ν¬ν•¨λ˜μ–΄ μžˆλŠ”μ§€ 확인
169
+ if not any(phrase in word for phrase in unwanted_phrases):
170
+ result_words.append(word)
171
+ # 단어듀을 λ‹€μ‹œ μ‘°ν•©ν•˜μ—¬ κ²°κ³Ό ν…μŠ€νŠΈ 생성
172
+ return ' '.join(result_words).replace(' \n ', '\n').replace(' \n', '\n').replace('\n ', '\n')
173
 
174
  # 초기 ν”„λ‘¬ν”„νŠΈ ꡬ성
175
  base_prompt = prompt_template + f"""
 
184
  # 첫 번째 μ‹œλ„ μ΄ν›„μ—λŠ” ν”„λ‘¬ν”„νŠΈμ— μΆ”κ°€ 지침을 포함
185
  if attempt > 0:
186
  additional_instructions = f"""
187
+ 1. μƒμ„±λœ κΈ€μ˜ 길이가 λͺ©ν‘œ κΈ€μžμˆ˜μ— λ―Έλ‹¬μž…λ‹ˆλ‹€. λ‚΄μš©μ˜ μ§ˆμ„ μœ μ§€ν•˜κ³  λ”μš± ν’λΆ€ν•˜κ²Œ μž‘μ„±ν•˜κ³ , 세뢀사항을 μΆ”κ°€ν•˜μ—¬ μžμ—°μŠ€λŸ½κ²Œ ν™•μž₯ν•˜μ„Έμš”.
188
+ 2. μ€‘λ³΅λ˜λŠ” λ‚΄μš©μ€ ν”Όν•˜κ³  μƒˆλ‘œμš΄ 정보λ₯Ό μΆ”κ°€ν•˜μ„Έμš”.
189
+ 3. λ°˜λ“œμ‹œ λ§ˆν¬λ‹€μš΄ ν˜•μ‹μ΄ μ•„λ‹Œ μˆœμˆ˜ν•œ ν…μŠ€νŠΈλ‘œλ§Œ 좜λ ₯ν•˜μ„Έμš”.
190
+ 4. λ°˜λ“œμ‹œ 이 ν‘œν˜„λ“€μ€ μ‚¬μš©ν•˜μ§€ λ§ˆμ„Έμš”: μ—¬λŸ¬λΆ„, 졜근, λ§ˆμ§€λ§‰μœΌλ‘œ, 결둠적으둜, κ²°κ΅­, μ’…ν•©μ μœΌλ‘œ, λ”°λΌμ„œ, 마무리, μš”μ•½.
191
  """
192
  else:
193
  additional_instructions = ""