Update app.py
Browse files36 unmodified lines373839404142432 unmodified lines464748495051525354555657180 unmodified lines23823924024124224343 unmodified lines28728828929029129229323 unmodified lines3173183193203213223233243253263273283295 unmodified lines33533633733833934034134234334434534634734834935035150 unmodified lines40240340440540640740840941041141241341441541641714 unmodified lines43243343443543643743843944044144244336 unmodified linesr'^ꡬ맀μ 보$',r'^ν¬μΈνΈ μ΅λ.*$',r'^λ°°μ‘λΉ.*$',r'^μ λ¦½μΏ ν°$',r'^λ³μ .*$',r'^리뷰.*$',r'^μΌνλͺ°λ³.*$',2 unmodified linesr'^λΉ νμ.*$',r'^κ΅ΏμλΉμ€$',r'^무λ£κ΅νλ°ν$',r'^λ€μ΄λ²νλ¬μ€.*$',r'^λ©€λ²μ.*$',r'^μ κ³ νκΈ°$',r'^λ±λ‘μΌ.*$',r'^ν‘ν‘$',r'^.*ν¬μΈνΈ μ 립μμ $',r'^μμ° λ©€λ²μ.*$',r'^μ°κ° .*$']180 unmodified linesif re.match(pattern, text):return Falsereturn True43 unmodified lines'μλ', 'μν', 'κΈ°ν', 'μμ', 'μ¬μ©', 'κ°', 'μμ', 'μμ','κΈ°λ³Έ', 'κ°λ₯ν', 'λλ', 'ν¬ν¨λ', 'ν¨κ»', 'κ²½μ°', 'μ 곡','μ μ©', 'μ', 'μ', 'ν¨', 'μ', 'μ΄', 'κ°', 'μ', 'λ₯Ό','μ', 'μμ', 'μΌλ‘', 'λ‘', 'λ', 'μ', 'μ΄λ€', 'μλ€']# λͺ¨λ ν€μλλ₯Ό μ μ₯ν λμ λ리: {ν€μλ: [λ±μ₯ μ λͺ© μΈλ±μ€ 리μ€νΈ]}23 unmodified linesreturn keyword_indicesdef analyze_keywords(titles, top_n=10):"""μ λͺ©μμ ν€μλλ₯Ό λΆμνκ³ ν΅κ³ μ 보λ₯Ό μμ±λ°ν:- keyword_stats: ν€μλ λΆμ μ λ³΄κ° λ΄κΈ΄ DataFrame- top_indices: κ° μμμ ν΄λΉνλ μ λͺ© μΈλ±μ€"""# μ λͺ©μμ ν€μλ μΆμΆkeyword_indices = extract_keywords(titles)5 unmodified lines# ν΄λΉ ν€μλκ° λ±μ₯ν μ λͺ© μcount = len(indices)# μμ 10κ° λ±μ₯ μ¬λΆin_top10 = any(idx < 10 for idx in indices) if len(titles) >= 10 else True# λ±μ₯ν μ λͺ© μμ λ¬Έμμ΄ranks = ", ".join(str(idx + 1) for idx in indices)keyword_stats.append({'ν€μλ': keyword,'λ±μ₯ μμ': ranks,'μ¬μ© νμ': count,'μμ 10κ° ν¬ν¨': 'μ' if in_top10 else 'μλμ€'})# μ¬μ© νμ κΈ°μ€μΌλ‘ μ λ ¬50 unmodified linesworksheet.set_column('A:A', 15) # ν€μλ μ΄worksheet.set_column('B:B', 30) # λ±μ₯ μμ μ΄worksheet.set_column('C:C', 10) # μ¬μ© νμ μ΄worksheet.set_column('D:D', 15) # μμ 10κ° ν¬ν¨ μ΄# κ²°κ³Ό μμ½ ν μ€νΈ μμ±result_text = f"μ΄ {len(titles)}οΏ½οΏ½μ μ λͺ©μ΄ μΆμΆλμμ΅λλ€.\n\n"for i, title in enumerate(titles, 1):result_text += f"{i}. {title}\n"result_text += f"\n\nν€μλ λΆμ κ²°κ³Ό (μμ 20κ°):\n"for i, row in keyword_df.head(20).iterrows():result_text += f"{row['ν€μλ']} - {row['μ¬μ© νμ']}ν λ±μ₯ (μμ: {row['λ±μ₯ μμ']})\n"return titles_file.name, keywords_file.name, result_text14 unmodified lines1. μ ν μ λͺ© μΆμΆ2. μΆμΆλ μ λͺ©μμ ν€μλ μΆμΆ λ° λΆμ3. ν€μλ μ¬μ© λΉλ λ° λ±μ₯ μμ λΆμ4. μμ 10κ° μ λͺ©μ ν€μλ ν¬ν¨ μ¬λΆ νμΈ### μ£Όμ νΉμ§:- "*" λ¬Έμ μ κ±°, μ€λ³΅ 곡백 μ²λ¦¬- κ΄κ³ μ£Όλ³ ν μ€νΈλ§ μ μΈνμ¬ μ νν μ λͺ© μΆμΆ- 'ν΄μΈ' μ λμ¬ μλ μ κ±°""")with gr.Row():36 unmodified lines373839404142434445462 unmodified lines49505152535455565758596061626364656667686970717273180 unmodified lines25425525625725825926026126226326426526626726826927027127227327427527627743 unmodified lines32132232332432532632732823 unmodified lines3523533543553563573583593603613623635 unmodified lines36937037137237337437537637737837938038138238338438538638738838939039139239339450 unmodified lines44544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447514 unmodified lines49049149249349449549649749849950050150236 unmodified linesr'^ꡬ맀μ 보$',r'^ν¬μΈνΈ μ΅λ.*$',r'^λ°°μ‘λΉ.*$',r'^μλ°°μ‘λΉ.*$',r'^μν/건κ°.*$',r'^μ λ¦½μΏ ν°$',r'^μ¬μ§ :.*$',r'^λ³μ .*$',r'^리뷰.*$',r'^μΌνλͺ°λ³.*$',2 unmodified linesr'^λΉ νμ.*$',r'^κ΅ΏμλΉμ€$',r'^무λ£κ΅νλ°ν$',r'^μ€λμΆλ°$',r'^λ€μ΄λ²νλ¬μ€.*$',r'^λ©€λ²μ.*$',r'^μ κ³ νκΈ°$',r'^λ±λ‘μΌ.*$',r'^ν‘ν‘$',r'^.*ν¬μΈνΈ μ 립μμ $',r'^μ€λ\(μΌμμΌ\) λ°°μ‘ ν΄λ¬΄$',r'^.*κΉμ§ μ£Όλ¬Έ μ$',r'^λμ§νΈ/κ°μ .*$',r'^νλͺ© :.*$',r'^λΉ λ₯Έλ°°μ‘$',r'^λΈλ£¨ν¬μ€λ²μ :.*$',r'^νν :.*$',r'^λ°°ν°λ¦¬μ©λ :.*$',r'^μμ§κ°μ :.*$',r'^μ¬μ©μκ° :.*$',r'^μ±λ :.*$',r'^λ΄μΌ.*λμ°©μμ $',r'^μμ° λ©€λ²μ.*$',r'^μ°κ° .*$']180 unmodified linesif re.match(pattern, text):return False# λ°°μ‘ μ 보, κ°κ²© λ±μ΄ ν¬ν¨λ λ¨μ μ λ³΄μ± ν μ€νΈλ μ μΈinfo_patterns = [r'.*μ€λ\(.*?\) λ°°μ‘.*',r'.*λ°°μ‘ ν΄λ¬΄.*',r'.*κΉμ§ μ£Όλ¬Έ.*',r'.*λ΄μΌ.*λμ°©.*',r'.*\d+,\d+μ.*λ°°μ‘λΉ.*',r'.*λ©€λ²μ κ°μ .*',r'.*ν¬μΈνΈ.*μ 립.*',r'^\d{1,3}(,\d{3})*μ?$', # κ°κ²© ν¨ν΄r'^리뷰.*$',r'^ꡬ맀.*$']for pattern in info_patterns:if re.match(pattern, text):return Falsereturn True43 unmodified lines'μλ', 'μν', 'κΈ°ν', 'μμ', 'μ¬μ©', 'κ°', 'μμ', 'μμ','κΈ°λ³Έ', 'κ°λ₯ν', 'λλ', 'ν¬ν¨λ', 'ν¨κ»', 'κ²½μ°', 'μ 곡','μ μ©', 'μ', 'μ', 'ν¨', 'μ', 'μ΄', 'κ°', 'μ', 'λ₯Ό','μ', 'μμ', 'μΌλ‘', 'λ‘', 'λ', 'μ', 'μ΄λ€', 'μλ€','λ', 'μ', 'κ³Ό', 'ν΄λ']# λͺ¨λ ν€μλλ₯Ό μ μ₯ν λμ λ리: {ν€μλ: [λ±μ₯ μ λͺ© μΈλ±μ€ 리μ€νΈ]}23 unmodified linesreturn keyword_indicesdef analyze_keywords(titles):"""μ λͺ©μμ ν€μλλ₯Ό λΆμνκ³ ν΅κ³ μ 보λ₯Ό μμ±λ°ν:- keyword_stats: ν€μλ λΆμ μ λ³΄κ° λ΄κΈ΄ DataFrame"""# μ λͺ©μμ ν€μλ μΆμΆkeyword_indices = extract_keywords(titles)5 unmodified lines# ν΄λΉ ν€μλκ° λ±μ₯ν μ λͺ© μcount = len(indices)# λ±μ₯ν μ λͺ© μμ λ¬Έμμ΄ranks = ", ".join(str(idx + 1) for idx in indices)# μμ λ ΈμΆ μΉ΄ν κ³ λ¦¬ κ²°μ if any(idx < 10 for idx in indices):exposure_category = "μμ 10κ°"elif any(idx < 20 for idx in indices):exposure_category = "μμ 20κ°"elif any(idx < 30 for idx in indices):exposure_category = "μμ 30κ°"elif any(idx < 40 for idx in indices):exposure_category = "μμ 40κ°"else:exposure_category = "1νμ΄μ§ λ―Έν¬ν¨"keyword_stats.append({'ν€μλ': keyword,'λ±μ₯ μμ': ranks,'μ¬μ© νμ': count,'μμλ ΈμΆ ν€μλ': exposure_category})# μ¬μ© νμ κΈ°μ€μΌλ‘ μ λ ¬50 unmodified linesworksheet.set_column('A:A', 15) # ν€μλ μ΄worksheet.set_column('B:B', 30) # λ±μ₯ μμ μ΄worksheet.set_column('C:C', 10) # μ¬μ© νμ μ΄worksheet.set_column('D:D', 15) # μμλ ΈμΆ ν€μλ μ΄# λ ΈμΆ μΉ΄ν κ³ λ¦¬λ³ ν€μλ μ κ³μ°exposure_counts = keyword_df['μμλ ΈμΆ ν€μλ'].value_counts().to_dict()top10_count = exposure_counts.get('μμ 10κ°', 0)top20_count = exposure_counts.get('μμ 20κ°', 0)top30_count = exposure_counts.get('μμ 30κ°', 0)top40_count = exposure_counts.get('μμ 40κ°', 0)not_included_count = exposure_counts.get('1νμ΄μ§ λ―Έν¬ν¨', 0)# κ²°κ³Ό μμ½ ν μ€νΈ μμ±result_text = f"μ΄ {len(titles)}οΏ½οΏ½μ μ λͺ©μ΄ μΆμΆλμμ΅λλ€.\n\n"for i, title in enumerate(titles, 1):result_text += f"{i}. {title}\n"result_text += f"\n\nν€μλ λΆμ κ²°κ³Ό (μ΄ {len(keyword_df)}κ° ν€μλ):\n"result_text += f"- μμ 10κ° μ λͺ©μ ν¬ν¨λ ν€μλ: {top10_count}κ°\n"result_text += f"- μμ 20κ° μ λͺ©μ ν¬ν¨λ ν€μλ: {top20_count}κ°\n"result_text += f"- μμ 30κ° μ λͺ©μ ν¬ν¨λ ν€μλ: {top30_count}κ°\n"result_text += f"- μμ 40κ° μ λͺ©μ ν¬ν¨λ ν€μλ: {top40_count}κ°\n"result_text += f"- 1νμ΄μ§μ ν¬ν¨λμ§ μμ ν€μλ: {not_included_count}κ°\n\n"result_text += f"κ°μ₯ λ§μ΄ μ¬μ©λ ν€μλ (μμ 20κ°):\n"for i, row in keyword_df.head(20).iterrows():result_text += f"{row['ν€μλ']} - {row['μ¬μ© νμ']}ν λ±μ₯ ({row['μμλ ΈμΆ ν€μλ']})\n"return titles_file.name, keywords_file.name, result_text14 unmodified lines1. μ ν μ λͺ© μΆμΆ2. μΆμΆλ μ λͺ©μμ ν€μλ μΆμΆ λ° λΆμ3. ν€μλ μ¬μ© λΉλ λ° λ±μ₯ μμ λΆμ4. μμ λ ΈμΆ ν€μλ λΆμ (μμ 10κ°, 20κ°, 30κ°, 40κ°)### μ£Όμ νΉμ§:- "*" λ¬Έμ μ κ±°, μ€λ³΅ 곡백 μ²λ¦¬- κ΄κ³ μ£Όλ³ ν μ€νΈλ§ μ μΈνμ¬ μ νν μ λͺ© μΆμΆ- 'ν΄μΈ' μ λμ¬ μλ μ κ±°- ν€μλ μμ λ ΈμΆ λΆμ""")with gr.Row():
app.py+70-11