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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -11
app.py CHANGED
@@ -162,17 +162,11 @@ def generate_blog_post(query, prompt_template):
162
  # λΆˆν•„μš”ν•œ ν‘œν˜„ 제거 ν•¨μˆ˜
163
  def remove_unwanted_phrases(text):
164
  for phrase in unwanted_phrases:
165
- # λΆˆν•„μš”ν•œ ν‘œν˜„μ΄ ν…μŠ€νŠΈμ— ν¬ν•¨λ˜μ–΄ μžˆλŠ” λ™μ•ˆ 반볡
166
- while phrase in text:
167
- index = text.find(phrase)
168
- # λΆˆν•„μš”ν•œ ν‘œν˜„ μ΄μ „μ˜ λ§ˆμ§€λ§‰ 곡백 μœ„μΉ˜ μ°ΎκΈ°
169
- prev_space = text.rfind(' ', 0, index)
170
- # prev_spaceκ°€ -1이면 λ¬Έμžμ—΄μ˜ μ²˜μŒλΆ€ν„° μ‹œμž‘
171
- start = prev_space if prev_space != -1 else 0
172
- # λΆˆν•„μš”ν•œ ν‘œν˜„μ˜ 끝 μœ„μΉ˜
173
- end = index + len(phrase)
174
- # ν•΄λ‹Ή λΆ€λΆ„ λ¬Έμžμ—΄ 제거
175
- text = text[:start] + text[end:]
176
  return text
177
 
178
  # 초기 ν”„λ‘¬ν”„νŠΈ ꡬ성
 
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
  # 초기 ν”„λ‘¬ν”„νŠΈ ꡬ성