Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import re
|
4 |
+
from collections import Counter
|
5 |
+
|
6 |
+
def process_excel(file):
|
7 |
+
# 엑셀 파일 읽기
|
8 |
+
df = pd.read_excel(file)
|
9 |
+
|
10 |
+
# D열의 데이터 추출
|
11 |
+
product_names = df.iloc[:, 3].dropna() # D열은 0부터 시작하므로 index는 3
|
12 |
+
|
13 |
+
# 키워드 추출 및 빈도 계산
|
14 |
+
all_keywords = []
|
15 |
+
|
16 |
+
for name in product_names:
|
17 |
+
# 특수문자 제거 및 공백 기준으로 분할
|
18 |
+
words = re.sub(r'[^\w\s]', '', name).split()
|
19 |
+
# 중복 제거
|
20 |
+
unique_words = set(words)
|
21 |
+
all_keywords.extend(unique_words)
|
22 |
+
|
23 |
+
# 빈도 계산
|
24 |
+
keyword_counts = Counter(all_keywords)
|
25 |
+
|
26 |
+
# 결과를 데이터프레임으로 정리
|
27 |
+
result_df = pd.DataFrame(keyword_counts.items(), columns=['Keyword', 'Frequency'])
|
28 |
+
result_df = result_df.sort_values(by='Frequency', ascending=False).reset_index(drop=True)
|
29 |
+
|
30 |
+
# 엑셀 파일로 저장
|
31 |
+
output_file = "/mnt/data/keyword_counts.xlsx"
|
32 |
+
result_df.to_excel(output_file, index=False)
|
33 |
+
|
34 |
+
return output_file
|
35 |
+
|
36 |
+
# Gradio 인터페이스 정의
|
37 |
+
iface = gr.Interface(
|
38 |
+
fn=process_excel,
|
39 |
+
inputs="file",
|
40 |
+
outputs="file",
|
41 |
+
title="Excel Keyword Extractor",
|
42 |
+
description="엑셀 파일의 D열에서 키워드를 추출하고 빈도를 계산하여 새로운 엑셀 파일로 출력합니다."
|
43 |
+
)
|
44 |
+
|
45 |
+
if __name__ == "__main__":
|
46 |
+
iface.launch()
|
47 |
+
|