File size: 1,398 Bytes
d24bb65 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import gradio as gr
import pandas as pd
import re
from collections import Counter
from openpyxl import Workbook
def process_excel(file):
# ์์
ํ์ผ ์ฝ๊ธฐ
df = pd.read_excel(file, sheet_name=0)
# D4๋ถํฐ D์ด์ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ
product_names = df.iloc[3:, 3].dropna() # D4๋ถํฐ ๋ฐ์ดํฐ ์ถ์ถ
# ํค์๋ ์ถ์ถ ๋ฐ ์ ์
all_keywords = []
for name in product_names:
# ํน์ ๋ฌธ์ ์ ๊ฑฐ ๋ฐ ํค์๋ ์ถ์ถ
keywords = re.findall(r'\b\w+\b', name)
# ์ค๋ณต ์ ๊ฑฐ
unique_keywords = set(keywords)
all_keywords.extend(unique_keywords)
# ๋น๋ ๊ณ์ฐ
keyword_counts = Counter(all_keywords)
sorted_keywords = keyword_counts.most_common()
# ๊ฒฐ๊ณผ๋ฅผ ์์
๋ก ์ ์ฅ
wb = Workbook()
ws = wb.active
ws.title = "Keywords"
ws['A4'] = "ํค์๋"
ws['B4'] = "๋น๋"
for idx, (keyword, count) in enumerate(sorted_keywords, start=5):
ws[f'A{idx}'] = keyword
ws[f'B{idx}'] = count
result_file = "keyword_counts.xlsx"
wb.save(result_file)
return result_file
# Gradio ์ธํฐํ์ด์ค ์ค์
iface = gr.Interface(
fn=process_excel,
inputs=gr.File(label="์์
ํ์ผ์ ์
๋ก๋ํ์ธ์"),
outputs=gr.File(label="๊ฒฐ๊ณผ ์์
ํ์ผ"),
title="์์
ํค์๋ ๋ถ์๊ธฐ"
)
if __name__ == "__main__":
iface.launch()
|