Update app.py
Browse files31 unmodified lines323334353637381 unmodified line40414243444546474834 unmodified lines83848586878889909113 unmodified lines10510610710810911011111211312 unmodified lines12612712812913013113213313412 unmodified lines14714814915015115215315415518 unmodified lines1741751761771781791801811821831841851861872 unmodified lines19019119219319419519619719819920020120220320420520620755 unmodified lines26326426526626726826931 unmodified lines6. ์ฒ์๋ถํฐ ์ ์ผ ์๋ถํฐ 1๋ก ์ ํ๊ณ ์์๋๋ก ์๋ฒ์ ์ ๋ฆฌ7. ๋์ผํ ์ซ์๊ฐ ๋์จ๋ค๊ณ ํด์ ๊ทธ ์ซ์๋ ์ ๋ชฉ์ด ์๋๋ค๊ฐ์ : ์ ํ ํค์๋ ์์กด๋๋ฅผ ๋ฎ์ถ๊ณ ์์น์ ํจํด ๊ธฐ๋ฐ ์ถ์ถ ๊ฐํ"""# ์๋ณธ ์ค ์ ์ฅ (** ํจํด ๋ณด์กด)original_lines = text.split('\n')1 unmodified line# ์ ์ฒ๋ฆฌ๋ ์ค ์ ์ฅlines = [preprocess_text(line) for line in original_lines]# ์ ๋ชฉ ํ๋ณด ์ ์ฅ์ฉ ์งํฉtitles = []seen_titles = set()# ์ ๋ชฉ์ผ๋ก ์ ํฉํ์ง ์์ ๋จ์ด๋ค (ํ๋งค์, ์๋น์ค, ๋ถ๊ฐ ์ ๋ณด ๋ฑ)exclude_words = [34 unmodified linesnot any(exclude in clean_match for exclude in exclude_words) and \not re.match(r'^[\d,.\s]+$', clean_match):if clean_match not in seen_titles:titles.append(clean_match)seen_titles.add(clean_match)# ํจํด 2: ๊ฐ๊ฒฉ ์ ๋ณด ์์ ์ค์ด ์ ๋ชฉ์ผ ๊ฐ๋ฅ์ฑ์ด ๋์for i in range(len(lines) - 1):13 unmodified linesnot re.match(r'^[\d,.\s]+$', current_line) and \'์ฐํ๊ธฐ' not in current_line:if current_line not in seen_titles:titles.append(current_line)seen_titles.add(current_line)# ํจํด 3: ์ฐํ๊ธฐ ๋ค์ ์ค ํ์ธfor i in range(len(lines) - 1):12 unmodified linesnot any(exclude in next_line for exclude in exclude_words) and \not re.match(r'^[\d,.\s]+$', next_line):if next_line not in seen_titles:titles.append(next_line)seen_titles.add(next_line)# ํจํด 4: ๋ฐ๋ณต๋๋ ํ ์คํธ ์ฐพ๊ธฐ (์กฐ๊ฑด 4: ์์๋๋ก 3์ค ๊ธฐ์ค์ผ๋ก ๋์ผํ ๋ด์ฉ)for i in range(len(lines)):12 unmodified lines# ์์๋๋ก 3์ค ๋ฒ์ ๋ด์ ๋์ผํ ํ ์คํธ๊ฐ ์๋์ง ํ์ธfor j in range(max(0, i - 3), min(len(lines), i + 4)):if i != j and not has_ad_nearby[j] and lines[i] == lines[j]:if current_line not in seen_titles:titles.append(current_line)seen_titles.add(current_line)break# ํจํด 5: ์์น ๊ธฐ๋ฐ ์ถ์ถ (๊ฐ ์ ํ ๋ธ๋ก์ ์ฃผ์ ์์น์ ์ ๋ชฉ์ด ์์ ๊ฐ๋ฅ์ฑ์ด ๋์)18 unmodified linesnot any(exclude in current_line for exclude in exclude_words) and \not re.match(r'^[\d,.\s]+$', current_line):if current_line not in seen_titles:titles.append(current_line)seen_titles.add(current_line)break# ์ค๋ณต ์ ๊ฑฐ ๋ฐ ์ ๋ชฉ ์ ์ final_titles = []processed_titles = set()for title in titles:# ์ ๋ชฉ์ผ๋ก ์ ํฉํ์ง ์์ ํญ๋ชฉ ํํฐ๋ง2 unmodified linesif any(exclude in title for exclude in exclude_words):continueif title not in processed_titles:# "์ฐํ๊ธฐ" ๋ฌธ๊ตฌ๊ฐ ํฌํจ๋ ๊ฒฝ์ฐ ์ ๊ฑฐif '์ฐํ๊ธฐ' in title:parts = title.split('์ฐํ๊ธฐ')if len(parts) > 1:# ์ซ์ ๋ค์์ ์ค๋ ํญ์ด๋ ๊ณต๋ฐฑ์ผ๋ก ๊ตฌ๋ถclean_title = re.sub(r'์ฐํ๊ธฐ\d+[,\d]*\s*[\t ]+', '', title).strip()if len(clean_title) > 10:title = clean_titlefinal_titles.append(title)processed_titles.add(title)return final_titles55 unmodified lines2. ์ค๋ณต ๊ณต๋ฐฑ์ ๋จ์ผ ๊ณต๋ฐฑ์ผ๋ก ๋ณ๊ฒฝ3. ์์๋๋ก 3์ค ๊ธฐ์ค์ผ๋ก ๋์ผํ ๋ด์ฉ์ด ์์ผ๋ฉด ์ ๋ชฉ์ผ๋ก ๊ฐ์ฃผ4. ์์๋๋ก 5์ค ๊ธฐ์ค์ผ๋ก "๊ด๊ณ " ๋ฌธ๊ตฌ๊ฐ ์๋ ์ ํ์ ์ ์ธ5. ์ค๋ณต ์ ๋ชฉ์ ์ ๊ฑฐํ๊ณ ์์๋๋ก ๋ฒํธ ๋ถ์ฌ""")with gr.Row():31 unmodified lines3233343536373839401 unmodified line424344454647484934 unmodified lines84858687888990919293949513 unmodified lines10911011111211311411512 unmodified lines12812913013113213313412 unmodified lines14714814915015115215318 unmodified lines1721731741751761771781791801811822 unmodified lines18518618718818919019119219319419519619755 unmodified lines25325425525625725825931 unmodified lines6. ์ฒ์๋ถํฐ ์ ์ผ ์๋ถํฐ 1๋ก ์ ํ๊ณ ์์๋๋ก ์๋ฒ์ ์ ๋ฆฌ7. ๋์ผํ ์ซ์๊ฐ ๋์จ๋ค๊ณ ํด์ ๊ทธ ์ซ์๋ ์ ๋ชฉ์ด ์๋๋ค๊ฐ์ :1. ์ ํ ํค์๋ ์์กด๋ ์ ๊ฑฐ2. ์ค๋ณต ์ ๊ฑฐ ์์ด ๋ชจ๋ ์ ๋ชฉ ์ ์ง"""# ์๋ณธ ์ค ์ ์ฅ (** ํจํด ๋ณด์กด)original_lines = text.split('\n')1 unmodified line# ์ ์ฒ๋ฆฌ๋ ์ค ์ ์ฅlines = [preprocess_text(line) for line in original_lines]# ์ ๋ชฉ ํ๋ณด ์ ์ฅ์ฉ ๋ฐฐ์ด (์ค๋ณต ์ฒดํฌ๋ฅผ ์ํ seen_titles ์ ๊ฑฐ)titles = []# ์ ๋ชฉ์ผ๋ก ์ ํฉํ์ง ์์ ๋จ์ด๋ค (ํ๋งค์, ์๋น์ค, ๋ถ๊ฐ ์ ๋ณด ๋ฑ)exclude_words = [34 unmodified linesnot any(exclude in clean_match for exclude in exclude_words) and \not re.match(r'^[\d,.\s]+$', clean_match):# "์ฐํ๊ธฐ" ๋ฌธ๊ตฌ๊ฐ ํฌํจ๋ ๊ฒฝ์ฐ ์ ๊ฑฐif '์ฐํ๊ธฐ' in clean_match:clean_match = re.sub(r'์ฐํ๊ธฐ\d+[,\d]*\s*[\t ]+', '', clean_match).strip()if len(clean_match) > 10:titles.append(clean_match)# ํจํด 2: ๊ฐ๊ฒฉ ์ ๋ณด ์์ ์ค์ด ์ ๋ชฉ์ผ ๊ฐ๋ฅ์ฑ์ด ๋์for i in range(len(lines) - 1):13 unmodified linesnot re.match(r'^[\d,.\s]+$', current_line) and \'์ฐํ๊ธฐ' not in current_line:titles.append(current_line)# ํจํด 3: ์ฐํ๊ธฐ ๋ค์ ์ค ํ์ธfor i in range(len(lines) - 1):12 unmodified linesnot any(exclude in next_line for exclude in exclude_words) and \not re.match(r'^[\d,.\s]+$', next_line):titles.append(next_line)# ํจํด 4: ๋ฐ๋ณต๋๋ ํ ์คํธ ์ฐพ๊ธฐ (์กฐ๊ฑด 4: ์์๋๋ก 3์ค ๊ธฐ์ค์ผ๋ก ๋์ผํ ๋ด์ฉ)for i in range(len(lines)):12 unmodified lines# ์์๋๋ก 3์ค ๋ฒ์ ๋ด์ ๋์ผํ ํ ์คํธ๊ฐ ์๋์ง ํ์ธfor j in range(max(0, i - 3), min(len(lines), i + 4)):if i != j and not has_ad_nearby[j] and lines[i] == lines[j]:titles.append(current_line)break# ํจํด 5: ์์น ๊ธฐ๋ฐ ์ถ์ถ (๊ฐ ์ ํ ๋ธ๋ก์ ์ฃผ์ ์์น์ ์ ๋ชฉ์ด ์์ ๊ฐ๋ฅ์ฑ์ด ๋์)18 unmodified linesnot any(exclude in current_line for exclude in exclude_words) and \not re.match(r'^[\d,.\s]+$', current_line):titles.append(current_line)break# ์ ๋ชฉ ์ ์ (์ค๋ณต ์ ๊ฑฐ๋ ํ์ง ์์)final_titles = []for title in titles:# ์ ๋ชฉ์ผ๋ก ์ ํฉํ์ง ์์ ํญ๋ชฉ ํํฐ๋ง2 unmodified linesif any(exclude in title for exclude in exclude_words):continue# "์ฐํ๊ธฐ" ๋ฌธ๊ตฌ๊ฐ ํฌํจ๋ ๊ฒฝ์ฐ ์ ๊ฑฐif '์ฐํ๊ธฐ' in title:title = re.sub(r'์ฐํ๊ธฐ\d+[,\d]*\s*[\t ]+', '', title).strip()if len(title) <= 10:continuefinal_titles.append(title)return final_titles55 unmodified lines2. ์ค๋ณต ๊ณต๋ฐฑ์ ๋จ์ผ ๊ณต๋ฐฑ์ผ๋ก ๋ณ๊ฒฝ3. ์์๋๋ก 3์ค ๊ธฐ์ค์ผ๋ก ๋์ผํ ๋ด์ฉ์ด ์์ผ๋ฉด ์ ๋ชฉ์ผ๋ก ๊ฐ์ฃผ4. ์์๋๋ก 5์ค ๊ธฐ์ค์ผ๋ก "๊ด๊ณ " ๋ฌธ๊ตฌ๊ฐ ์๋ ์ ํ์ ์ ์ธ5. ๋์ผํ ์ ๋ชฉ๋ ๋ชจ๋ ์ ์งํ์ฌ ์์๋๋ก ๋ฒํธ ๋ถ์ฌ""")with gr.Row():
app.py+22-32