Update app.py
Browse files123416 unmodified lines21222324252627282930313233343536375 unmodified lines43444546474849505152535455565758593 unmodified lines636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232241 unmodified line2262272282292302312324 unmodified lines23723823924024124224318 unmodified lines2622632642652662673 unmodified lines2712722732742752762772782792803 unmodified lines2842852862872882891 unmodified line29129229329429529629729819 unmodified lines318319320321322323324import gradio as grimport reimport pandas as pdimport io16 unmodified linesreturn processed.strip()def extract_titles(text):"""ํ ์คํธ์์ ์ ํ ์ ๋ชฉ์ ์ถ์ถํ๋ ํจ์๊ท์น:1. "*"๋ฌธ์ ๊ฐ ๋์ค๋ฉด ์ ๊ฑฐ2. " "์ด๋ฉด " "๋ก ๋ณ๊ฒฝ3. ์คํ์ด์ค๊ฐ 1๊ฐ์ด์์ด๋ฉด ๋ฌด์กฑ๊ฑด 2๊ฐ๋ฉด 1๊ฐ๋ก ์์ 4. ์์๋๋ก 3์ค์ ๊ธฐ์ค์ผ๋ก ๋์ผํ ๋ด์ฉ์ด ์์ผ๋ฉด ์ ๋ชฉ์ผ๋ก ๊ฐ์ฃผ5. ์์๋๋ก 5์ค๊ธฐ์ค์ผ๋ก "๊ด๊ณ "๊ณ ๋ฌธ๊ตฌ๊ฐ ์๋ค๋ฉด ์ ๋ชฉ์์ ์ ์ธ6. ์ฒ์๋ถํฐ ์ ์ผ ์๋ถํฐ 1๋ก ์ ํ๊ณ ์์๋๋ก ์๋ฒ์ ์ ๋ฆฌ7. ๋์ผํ ์ซ์๊ฐ ๋์จ๋ค๊ณ ํด์ ๊ทธ ์ซ์๋ ์ ๋ชฉ์ด ์๋๋ค"""# ์๋ณธ ์ค ์ ์ฅ (** ํจํด ๋ณด์กด)original_lines = text.split('\n')5 unmodified linestitles = []seen_titles = set()# ํจํด 1: ** ์ฌ์ด์ ์๋ ํ ์คํธ๋ฅผ ๊ธฐ๋ณธ ์ ๋ชฉ ํ๋ณด๋ก ๊ฐ์ฃผfor i, original_line in enumerate(original_lines):# ๊ด๊ณ ์ฌ๋ถ ํ์ธ (5์ค ์์๋๋ก)has_ad = Falsefor j in range(max(0, i - 5), min(len(lines), i + 6)):if '๊ด๊ณ ' in lines[j]:has_ad = Truebreak# ๊ด๊ณ ๊ฐ ์์ผ๋ฉด ๊ฑด๋๋ฐ๊ธฐif has_ad:continue# ** ํจํด ์ฐพ๊ธฐ (์ ๋ชฉ์ผ ๊ฐ๋ฅ์ฑ์ด ๋์)3 unmodified linesfor match in matches:clean_match = preprocess_text(match)# ์ ๋ชฉ์ผ๋ก ์ ํฉํ์ง ํ์ธif len(clean_match) > 10 and \not any(exclude in clean_match for exclude in ['์ํ๋ง ๋ณด๊ธฐ', '๊ตฌ๋งค์ ๋ณด', 'ํฌ์ธํธ ์ต๋']):# ์ ํ๋ช ์ผ๋ก ๊ฐ์ฃผํ ์ ์๋ ํค์๋๊ฐ ํฌํจ๋์ด ์๋์ง ํ์ธkey_product_words = ['๋์๋ฝ', '๋์๋ฝํต', '๋ณด์จ', '์คํ ', '๋ฐ์น', '๋ฐํ๋ฉ', '์ฃฝํต','๋ฌด์นจ', '๋ฐ์ฐฌ', '์ง๋ฏธ', '์ค์ง์ด', '๊นป์', '์ง๋ฏธ์ฑ', '๋ฌด์นจํ','์ง์ฅ์ธ', '์ ์น์', '์๋ฌ๋', '์ด์ ์', '๋ณด์จํต', '๋ฐฅํต', '๋จ']has_product_keyword = any(keyword in clean_match.lower() for keyword in key_product_words)if has_product_keyword and clean_match not in seen_titles:titles.append(clean_match)seen_titles.add(clean_match)# ํจํด 2: ์ฐํ๊ธฐ ๋ค์์ ์ค๋ ํ ์คํธfor i in range(len(lines)):current_line = lines[i]# ๊ด๊ณ ์ฌ๋ถ ํ์ธ (5์ค ์์๋๋ก)has_ad = Falsefor j in range(max(0, i - 5), min(len(lines), i + 6)):if '๊ด๊ณ ' in lines[j]:has_ad = Truebreak# ๊ด๊ณ ๊ฐ ์์ผ๋ฉด ๊ฑด๋๋ฐ๊ธฐif has_ad:continue# ์ฐํ๊ธฐ ๋ค์ ์ค ํ์ธif '์ฐํ๊ธฐ' in current_line and i + 1 < len(lines):next_line = lines[i + 1]if len(next_line) > 10 and \not any(exclude in next_line for exclude in ['๋ฐฐ์ก๋น', '์ํ๋ง ๋ณด๊ธฐ']):# ์ ํ๋ช ์ผ๋ก ๊ฐ์ฃผํ ์ ์๋ ํค์๋๊ฐ ํฌํจ๋์ด ์๋์ง ํ์ธkey_product_words = ['๋์๋ฝ', '๋์๋ฝํต', '๋ณด์จ', '์คํ ', '๋ฐ์น', '๋ฐํ๋ฉ', '์ฃฝํต','๋ฌด์นจ', '๋ฐ์ฐฌ', '์ง๋ฏธ', '์ค์ง์ด', '๊นป์', '์ง๋ฏธ์ฑ', '๋ฌด์นจํ','์ง์ฅ์ธ', '์ ์น์', '์๋ฌ๋', '์ด์ ์', '๋ณด์จํต', '๋ฐฅํต', '๋จ']has_product_keyword = any(keyword in next_line.lower() for keyword in key_product_words)if has_product_keyword and next_line not in seen_titles:titles.append(next_line)seen_titles.add(next_line)# ๊ฐ๊ฒฉ ์ ๋ณด ๋ฐ๋ก ์ ์ค ํ์ธif i + 1 < len(lines) and \(re.search(r'\d+,?\d*์', lines[i + 1]) or '์๋ฐฐ์ก๋น' in lines[i + 1]):if len(current_line) > 10 and \'์ฐํ๊ธฐ' not in current_line and \'์ํ๋ง ๋ณด๊ธฐ' not in current_line:# ์ ํ๋ช ์ผ๋ก ๊ฐ์ฃผํ ์ ์๋ ํค์๋๊ฐ ํฌํจ๋์ด ์๋์ง ํ์ธkey_product_words = ['๋์๋ฝ', '๋์๋ฝํต', '๋ณด์จ', '์คํ ', '๋ฐ์น', '๋ฐํ๋ฉ', '์ฃฝํต','๋ฌด์นจ', '๋ฐ์ฐฌ', '์ง๋ฏธ', '์ค์ง์ด', '๊นป์', '์ง๋ฏธ์ฑ', '๋ฌด์นจํ','์ง์ฅ์ธ', '์ ์น์', '์๋ฌ๋', '์ด์ ์', '๋ณด์จํต', '๋ฐฅํต', '๋จ']has_product_keyword = any(keyword in current_line.lower() for keyword in key_product_words)if has_product_keyword and current_line not in seen_titles:titles.append(current_line)seen_titles.add(current_line)# ํจํด 3: ์์๋ 3์ค ๋ด์ ์ ์ฌํ ๋ด์ฉ์ด ์๋์ง ํ์ธfor i in range(len(lines)):current_line = lines[i]# ๊ด๊ณ ์ฌ๋ถ ํ์ธhas_ad = Falsefor j in range(max(0, i - 5), min(len(lines), i + 6)):if '๊ด๊ณ ' in lines[j]:has_ad = Truebreakif has_ad:continueif len(current_line) > 10 and \not any(exclude in current_line for exclude in ['์๋ฐฐ์ก๋น', '์๏ฟฝ๏ฟฝ๋ง ๋ณด๊ธฐ', '๊ตฌ๋งค์ ๋ณด','์ํ/๊ฑด๊ฐ', 'ํฌ์ธํธ ์ต๋', '์ ๋ฆฝ์ฟ ํฐ','์ฌ์ง :', '๋ณ์ ', '๋ฆฌ๋ทฐ', '์ผํ๋ชฐ๋ณ ์ต์ ๊ฐ']):for j in range(max(0, i - 3), min(len(lines), i + 4)):if i != j:# ์ ์ฌ๋ ์ธก์ ์ ์ํ ์ค์ ๋จ์ด ์ถ์ถcurrent_words = current_line.split(' ')compare_line = lines[j]compare_words = compare_line.split(' ')# ํน์ง์ ์ธ ๋จ์ด ๋ชฉ๋กkey_product_words = ['๋์๋ฝ', '๋์๋ฝํต', '๋ณด์จ', '์คํ ', '๋ฐ์น', '๋ฐํ๋ฉ', '์ฃฝํต','๋ฌด์นจ', '๋ฐ์ฐฌ', '์ง๋ฏธ', '์ค์ง์ด', '๊นป์', '์ง๋ฏธ์ฑ', '๋ฌด์นจํ','์ง์ฅ์ธ', '์ ์น์', '์๋ฌ๋', '์ด์ ์', '๋ณด์จํต', '๋ฐฅํต', '๋จ']# ๊ณตํต ๋จ์ด ์ฐพ๊ธฐcommon_words = 0for word in current_words:# ์ซ์๋ง์ผ๋ก ๊ตฌ์ฑ๋ ๋จ์ด๋ ๊ฑด๋๋ฐ๊ธฐ (๊ท์น 7)if re.fullmatch(r'\d+', word):continue# 4๊ธ์ ์ด์์ ๋จ์ด์ด๊ฑฐ๋ ํน์ง์ ์ธ ๋จ์ด์ธ ๊ฒฝ์ฐ๋ง ํ์ธif len(word) >= 4 or any(key in word.lower() for key in key_product_words):if any(word in cw or cw in word for cw in compare_words):common_words += 1# ๊ณตํต ๋จ์ด๊ฐ 2๊ฐ ์ด์์ด๋ฉด ๋งค์น๋ก ๊ฐ์ฃผif common_words >= 2:# ์ ํ๋ช ์ผ๋ก ๊ฐ์ฃผํ ์ ์๋ ํค์๋๊ฐ ํฌํจ๋์ด ์๋์ง ํ์ธhas_product_keyword = any(keyword in current_line.lower() for keyword in key_product_words)if has_product_keyword and 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:# ์ ๋ชฉ์ผ๋ก ์ ํฉํ์ง ์์ ํญ๋ชฉ ํํฐ๋งif len(title) > 10 and not re.match(r'^[0-9.]+$', title):# ์ด๋ฏธ ์ถ๊ฐ๋ ์ ๋ชฉ๊ณผ ์ ์ฌํ์ง ํ์ธis_duplicate = Falsefor existing in final_titles:# ๋จ์ด ๊ธฐ๋ฐ ์ ์ฌ๋ ๊ณ์ฐtitle_words = set(title.split(' '))existing_words = set(existing.split(' '))# ๊ณตํต ๋จ์ด ๋น์จ ๊ณ์ฐcommon = title_words.intersection(existing_words)similarity = len(common) / min(len(title_words), len(existing_words))# 70% ์ด์ ์ ์ฌํ๋ฉด ์ค๋ณต์ผ๋ก ๊ฐ์ฃผif similarity > 0.7:is_duplicate = True# ๋ ๊ธด ์ ๋ชฉ์ ์ ์งif len(title) > len(existing) and existing in processed_titles:processed_titles.remove(existing)processed_titles.add(title)final_titles[final_titles.index(existing)] = titlebreakif not is_duplicate and title not in processed_titles:final_titles.append(title)processed_titles.add(title)return final_titlesdef process_text_and_download(input_text):"""ํ ์คํธ๋ฅผ ๋ถ์ํ์ฌ ์ ๋ชฉ์ ์ถ์ถํ๊ณ ์์ ํ์ผ๋ก ๋ณํํ๋ ํจ์"""1 unmodified linereturn None, "ํ ์คํธ๋ฅผ ์ ๋ ฅํด์ฃผ์ธ์."# ์ ๋ชฉ ์ถ์ถtitles = extract_titles(input_text)if not titles:return None, "์ถ์ถ๋ ์ ๋ชฉ์ด ์์ต๋๋ค. ๋ค๋ฅธ ํ ์คํธ๋ฅผ ์๋ํด๋ณด์ธ์."4 unmodified lines'์ ๋ชฉ': titles})# ์์ ํ์ผ๋ก ์ ์ฅ (๊ทธ๋ผ๋์ค 5.0์์๋ BytesIO ์ง์ ์ฌ์ฉ ๋์ ์์ ํ์ผ ์ฌ์ฉ)temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.xlsx')temp_file.close()18 unmodified lines"""๊ทธ๋ผ๋์ค ์ฑ ์์ฑ ํจ์"""with gr.Blocks(title="์ ํ ์ ๋ชฉ ์ถ์ถ๊ธฐ") as app:gr.Markdown("""# ํ ์คํธ์์ ์ ํ ์ ๋ชฉ ์ถ์ถ๊ธฐ3 unmodified lines### ์ ์ฉ๋๋ ๊ท์น:1. "*" ๋ฌธ์ ์ ๊ฑฐ2. ์ค๋ณต ๊ณต๋ฐฑ์ ๋จ์ผ ๊ณต๋ฐฑ์ผ๋ก ๋ณ๊ฒฝ3. ์์๋๋ก 3์ค ๊ธฐ์ค์ผ๋ก ๋์ผ/์ ์ฌํ ๋ด์ฉ์ด ์์ผ๋ฉด ์ ๋ชฉ์ผ๋ก ๊ฐ์ฃผ4. ์์๋๋ก 5์ค ๊ธฐ์ค์ผ๋ก "๊ด๊ณ " ๋ฌธ๊ตฌ๊ฐ ์๋ ์ ํ์ ์ ์ธ5. ์ค๋ณต ์ ๋ชฉ์ ์ ๊ฑฐํ๊ณ ์์๋๋ก ๋ฒํธ ๋ถ์ฌ6. ์ ํ ๊ด๋ จ ํค์๋๊ฐ ํฌํจ๋ ํ ์คํธ๋ฅผ ์ ๋ชฉ์ผ๋ก ์ฐ์ ๊ฐ์ฃผ""")with gr.Row():3 unmodified linesplaceholder="์ฌ๊ธฐ์ ์ ํ ๋ชฉ๋ก์ด ํฌํจ๋ ํ ์คํธ๋ฅผ ๋ถ์ฌ๋ฃ์ผ์ธ์...",lines=15)submit_btn = gr.Button("์ ๋ชฉ ์ถ์ถํ๊ธฐ")with gr.Column():1 unmodified linedownload_btn = gr.File(label="์์ ํ์ผ ๋ค์ด๋ก๋", file_types=[".xlsx"])submit_btn.click(process_text_and_download,inputs=[input_text],outputs=[download_btn, output_text])19 unmodified lines# ์ฑ ์คํdemo = create_app()if __name__ == "__main__":demo.launch()12316 unmodified lines2021222324252627282930313233345 unmodified lines404142434445464748495051525354555657585960613 unmodified lines65666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891 unmodified line1911921931941951961974 unmodified lines20220320420520620720818 unmodified lines2272282292302312322332343 unmodified lines2382392402412422432442453 unmodified lines2492502512522532542551 unmodified line25725825926026126226326419 unmodified lines284285286287288289import reimport pandas as pdimport io16 unmodified linesreturn processed.strip()def extract_titles(text, debug=False):"""ํ ์คํธ์์ ์ ํ ์ ๋ชฉ์ ์ถ์ถํ๋ ํจ์๊ฐ์ ์ฌํญ:1. ์ ํ ํค์๋ ๋ชฉ๋ก ํ์ฅ2. ์ ์ฌ๋ ๊ณ์ฐ ์ ๊ฑฐ (๊ฐ ์ํ์ ๊ณ ์ ํ๊ฒ ์ฒ๋ฆฌ)3. ๊ด๊ณ ํํฐ๋ง ๋ก์ง ์์ 4. ์ ๋ชฉ ์ถ์ถ ํจํด ๋ค์ํ"""# ์๋ณธ ์ค ์ ์ฅ (** ํจํด ๋ณด์กด)original_lines = text.split('\n')5 unmodified linestitles = []seen_titles = set()# ์ ํ ๊ด๋ จ ํค์๋ ํ์ฅ (์ํ, ๋ฐ์น๋ฐ์ค ๋ฑ ์ถ๊ฐ)key_product_words = ['๋์๋ฝ', '๋์๋ฝํต', '๋ณด์จ', '์คํ ', '๋ฐ์น', '๋ฐํ๋ฉ', '์ฃฝํต','๋ฌด์นจ', '๋ฐ์ฐฌ', '์ง๋ฏธ', '์ค์ง์ด', '๊นป์', '์ง๋ฏธ์ฑ', '๋ฌด์นจํ','์ง์ฅ์ธ', '์ ์น์', '์๋ฌ๋', '์ด์ ์', '๋ณด์จํต', '๋ฐฅํต', '๋จ','์ํ', '์๊ธฐ', '์ธํธ', '๋ฐ์น๋ฐ์ค', '๋ฐํ๋ ', '์ฐฌํฉ', '์ํ','๊ฐ์', '๊ฐ๋ฐฉ']if debug:print("=== ๋๋ฒ๊น ๋ชจ๋ ํ์ฑํ ===")# ํจํด 1: ** ์ฌ์ด์ ์๋ ํ ์คํธ๋ฅผ ๊ธฐ๋ณธ ์ ๋ชฉ ํ๋ณด๋ก ๊ฐ์ฃผfor i, original_line in enumerate(original_lines):# ๊ด๊ณ ๋ฌธ๊ตฌ ์์ฒด๋ ๊ฑด๋๋ฐ๋, ๊ด๊ณ ๊ฐ ํฌํจ๋ ์ ํ ์ ์ฒด๋ฅผ ๋ฌด์ํ์ง ์์if '๊ด๊ณ ' in lines[i] and len(lines[i].strip()) < 20: # ์งง์ ๊ด๊ณ ๋ฌธ๊ตฌ๋ง ๊ฑด๋๋ฐ๊ธฐif debug:print(f"๊ด๊ณ ๋ฌธ๊ตฌ ๋ฐ๊ฒฌ (๊ฑด๋๋): {lines[i]}")continue# ** ํจํด ์ฐพ๊ธฐ (์ ๋ชฉ์ผ ๊ฐ๋ฅ์ฑ์ด ๋์)3 unmodified linesfor match in matches:clean_match = preprocess_text(match)# ์ ๋ชฉ์ผ๋ก ์ ํฉํ์ง ํ์ธ (๊ธธ์ด ๊ฒ์ฌ ์ํ)if len(clean_match) > 5 and \not any(exclude in clean_match for exclude in ['์ํ๋ง ๋ณด๊ธฐ', '๊ตฌ๋งค์ ๋ณด']):# ์ ํ๋ช ์ผ๋ก ๊ฐ์ฃผํ ์ ์๋ ํค์๋๊ฐ ํฌํจ๋์ด ์๋์ง ํ์ธhas_product_keyword = any(keyword in clean_match.lower() for keyword in key_product_words)if has_product_keyword and clean_match not in seen_titles:if debug:print(f"ํจํด1 (** ํจํด) ์ ๋ชฉ ํ๋ณด: {clean_match}")titles.append(clean_match)seen_titles.add(clean_match)# ํจํด 2: ์ฐํ๊ธฐ ๋ค์ ์ค๋ ํ ์คํธ๋ฅผ ์ ๋ชฉ์ผ๋ก ๊ฐ์ฃผfor i in range(len(lines)):current_line = lines[i]# ์งง์ ๊ด๊ณ ๋ฌธ๊ตฌ๋ ๊ฑด๋๋ฐ๊ธฐif '๊ด๊ณ ' in current_line and len(current_line.strip()) < 20:continue# ์ฐํ๊ธฐ ํจํด ํ์ธ (์ฐํ๊ธฐ + ์ซ์)if '์ฐํ๊ธฐ' in current_line:# ํ์ฌ ์ค์์ ์ ๋ชฉ ์ฐพ๊ธฐ (์ฐํ๊ธฐ ๋ค์ ์์ ์ ์์)parts = current_line.split('์ฐํ๊ธฐ')if len(parts) > 1 and len(parts[1].strip()) > 5:# ํญ์ด๋ ์คํ์ด์ค๋ก ๊ตฌ๋ถ๋ ๋ถ๋ถ ์ฒ๋ฆฌpotential_title = parts[1].strip().split('\t')[0].strip()# ์ซ์๋ก๋ง ๋์ด์์ง ์์์ง ํ์ธif not re.match(r'^\d+$', potential_title) and len(potential_title) > 5:if any(keyword in potential_title.lower() for keyword in key_product_words) and potential_title not in seen_titles:if debug:print(f"ํจํด2-1 (์ฐํ๊ธฐ ๋ค ํ ์คํธ) ์ ๋ชฉ ํ๋ณด: {potential_title}")titles.append(potential_title)seen_titles.add(potential_title)# ์ฐํ๊ธฐ ๋ค์ ์ค ํ์ธ - ์ด ๋ถ๋ถ์ด ์ค์if i + 1 < len(lines):next_line = lines[i + 1]if len(next_line) > 5 and \not any(exclude in next_line for exclude in ['๋ฐฐ์ก๋น', '์ํ๋ง ๋ณด๊ธฐ', '์๋ฐฐ์ก๋น']):# ์ซ์๋ก๋ง ๋์ด์์ง ์์์ง ํ์ธif not re.match(r'^\d+$', next_line):# ์ ํ๋ช ์ผ๋ก ๊ฐ์ฃผํ ์ ์๋ ํค์๋๊ฐ ํฌํจ๋์ด ์๋์ง ํ์ธhas_product_keyword = any(keyword in next_line.lower() for keyword in key_product_words)if has_product_keyword and next_line not in seen_titles:if debug:print(f"ํจํด2-2 (์ฐํ๊ธฐ ๋ค์ ์ค) ์ ๋ชฉ ํ๋ณด: {next_line}")titles.append(next_line)seen_titles.add(next_line)# ํจํด 3: ๊ฐ๊ฒฉ ์ ๋ณด ๋ฐ๋ก ์ ์ค ํ์ธ (์ค์ํ ์ ๋ชฉ ์ถ์ถ ํจํด)if i + 1 < len(lines) and \(re.search(r'\d+,?\d*์', lines[i + 1]) or '์๋ฐฐ์ก๋น' in lines[i + 1]):if len(current_line) > 5 and \'์ฐํ๊ธฐ' not in current_line and \'์ํ๋ง ๋ณด๊ธฐ' not in current_line:# ์ ํ๋ช ์ผ๋ก ๊ฐ์ฃผํ ์ ์๋ ํค์๋๊ฐ ํฌํจ๋์ด ์๋์ง ํ์ธhas_product_keyword = any(keyword in current_line.lower() for keyword in key_product_words)if has_product_keyword and current_line not in seen_titles:if debug:print(f"ํจํด3 (๊ฐ๊ฒฉ ์ ๋ณด ์ ์ค) ์ ๋ชฉ ํ๋ณด: {current_line}")titles.append(current_line)seen_titles.add(current_line)# ํจํด 4: ๋ฐ๋ณต๋๋ ์ ํ๋ช ํจํด ์ฐพ๊ธฐ (์์๋๋ก ๋น์ทํ ํ ์คํธ๊ฐ ์๋ ๊ฒฝ์ฐ)for i in range(len(lines)):current_line = lines[i]# ์งง์ ๊ด๊ณ ๋ฌธ๊ตฌ๋ ๊ฑด๋๋ฐ๊ธฐif '๊ด๊ณ ' in current_line and len(current_line.strip()) < 20:continueif len(current_line) > 5 and \not any(exclude in current_line for exclude in ['์๋ฐฐ์ก๋น', '์๏ฟฝ๏ฟฝ๋ง ๋ณด๊ธฐ', '๊ตฌ๋งค์ ๋ณด','์ํ/๊ฑด๊ฐ', 'ํฌ์ธํธ ์ต๋', '์ ๋ฆฝ์ฟ ํฐ','์ฌ์ง :', '๋ณ์ ', '๋ฆฌ๋ทฐ']):# ์ค๋ณต ํ ์คํธ ์ฐพ๊ธฐfound_duplicate = Falsefor j in range(max(0, i - 3), min(len(lines), i + 4)):if i != j and lines[i] == lines[j]:found_duplicate = Truebreak# ์ ํ ํค์๋๊ฐ ์๋์ง ํ์ธhas_product_keyword = any(keyword in current_line.lower() for keyword in key_product_words)# ์ค๋ณต์ด ์๊ฑฐ๋ ํค์๋๊ฐ ์์ผ๋ฉด ์ ๋ชฉ์ผ๋ก ๊ฐ์ฃผif (found_duplicate or has_product_keyword) and current_line not in seen_titles:# ์ซ์๋ก๋ง ๋ ํ ์คํธ๋ ์ ์ธif not re.match(r'^[\d\s]+$', current_line):if debug:print(f"ํจํด4 (๋ฐ๋ณต/ํค์๋ ํจํด) ์ ๋ชฉ ํ๋ณด: {current_line}")titles.append(current_line)seen_titles.add(current_line)# ์ค๋ณต ์ ๊ฑฐ ๋ฐ ์ ๋ชฉ ์ ์ (์ ์ฌ๋ ๊ณ์ฐ ์์ด ๋จ์ ์ค๋ณต๋ง ์ ๊ฑฐ)final_titles = []processed_titles = set()for title in titles:# ์ ๋ชฉ์ผ๋ก ์ ํฉํ์ง ์์ ํญ๋ชฉ ํํฐ๋งif len(title) > 5 and not re.match(r'^[0-9.]+$', title):# ๋จ์ ์ค๋ณต ๊ฒ์ฌ๋ง ์ํif title not in processed_titles:final_titles.append(title)processed_titles.add(title)return final_titlesdef process_text_and_download(input_text, debug=False):"""ํ ์คํธ๋ฅผ ๋ถ์ํ์ฌ ์ ๋ชฉ์ ์ถ์ถํ๊ณ ์์ ํ์ผ๋ก ๋ณํํ๋ ํจ์"""1 unmodified linereturn None, "ํ ์คํธ๋ฅผ ์ ๋ ฅํด์ฃผ์ธ์."# ์ ๋ชฉ ์ถ์ถtitles = extract_titles(input_text, debug)if not titles:return None, "์ถ์ถ๋ ์ ๋ชฉ์ด ์์ต๋๋ค. ๋ค๋ฅธ ํ ์คํธ๋ฅผ ์๋ํด๋ณด์ธ์."4 unmodified lines'์ ๋ชฉ': titles})# ์์ ํ์ผ๋ก ์ ์ฅtemp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.xlsx')temp_file.close()18 unmodified lines"""๊ทธ๋ผ๋์ค ์ฑ ์์ฑ ํจ์"""import gradio as grwith gr.Blocks(title="์ ํ ์ ๋ชฉ ์ถ์ถ๊ธฐ") as app:gr.Markdown("""# ํ ์คํธ์์ ์ ํ ์ ๋ชฉ ์ถ์ถ๊ธฐ3 unmodified lines### ์ ์ฉ๋๋ ๊ท์น:1. "*" ๋ฌธ์ ์ ๊ฑฐ2. ์ค๋ณต ๊ณต๋ฐฑ์ ๋จ์ผ ๊ณต๋ฐฑ์ผ๋ก ๋ณ๊ฒฝ3. ์ ํ ๊ด๋ จ ํค์๋๊ฐ ํฌํจ๋ ํ ์คํธ๋ฅผ ์ ๋ชฉ์ผ๋ก ์ฐ์ ๊ฐ์ฃผ4. ์ค๋ณต ์ ๋ชฉ์ ์ ๊ฑฐํ๊ณ ์์๋๋ก ๋ฒํธ ๋ถ์ฌ""")with gr.Row():3 unmodified linesplaceholder="์ฌ๊ธฐ์ ์ ํ ๋ชฉ๋ก์ด ํฌํจ๋ ํ ์คํธ๋ฅผ ๋ถ์ฌ๋ฃ์ผ์ธ์...",lines=15)debug_mode = gr.Checkbox(label="๋๋ฒ๊น ๋ชจ๋ (์์ธ ๋ก๊ทธ ์ถ๋ ฅ)")submit_btn = gr.Button("์ ๋ชฉ ์ถ์ถํ๊ธฐ")with gr.Column():1 unmodified linedownload_btn = gr.File(label="์์ ํ์ผ ๋ค์ด๋ก๋", file_types=[".xlsx"])submit_btn.click(lambda text, debug: process_text_and_download(text, debug),inputs=[input_text, debug_mode],outputs=[download_btn, output_text])19 unmodified lines# ์ฑ ์คํif __name__ == "__main__":demo = create_app()demo.launch()
app.py+102-137