CSB261 commited on
Commit
b556bb6
ยท
verified ยท
1 Parent(s): 2f8e6e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
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()