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()