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