Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,28 @@
|
|
|
|
1 |
import pandas as pd
|
2 |
from collections import Counter
|
3 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
def extract_keywords(text):
|
6 |
-
# ํ
์คํธ์์
|
7 |
-
keywords = text.split(" ")
|
8 |
return keywords
|
9 |
|
10 |
def process_excel(input_file, output_file):
|
11 |
# ์์
ํ์ผ ์ฝ๊ธฐ
|
12 |
df = pd.read_excel(input_file)
|
13 |
-
|
14 |
-
# ๊ฒฐ๊ณผ ์ ์ฅ์ ์ํ ๋ฆฌ์คํธ ์ด๊ธฐํ
|
15 |
all_keywords = []
|
16 |
|
17 |
-
# D4 ์
๋ถํฐ ๋๊น์ง ์ํ๋ช
๋ฐ์ดํฐ๋ฅผ ์ฒ๋ฆฌ
|
18 |
for index, row in df.iterrows():
|
19 |
-
product_name = row['์ํ๋ช
(๋งํฌ)']
|
20 |
if pd.notna(product_name):
|
21 |
keywords = extract_keywords(product_name)
|
22 |
all_keywords.extend(keywords)
|
@@ -26,15 +32,33 @@ def process_excel(input_file, output_file):
|
|
26 |
|
27 |
# ๊ฒฐ๊ณผ๋ฅผ ๋ฐ์ดํฐํ๋ ์์ผ๋ก ๋ณํ
|
28 |
result_df = pd.DataFrame(keyword_counter.items(), columns=['ํค์๋', '๋น๋์'])
|
29 |
-
|
30 |
-
# ๋น๋์ ๊ธฐ์ค์ผ๋ก ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ
|
31 |
result_df = result_df.sort_values(by='๋น๋์', ascending=False)
|
32 |
|
33 |
# ๊ฒฐ๊ณผ๋ฅผ ์๋ก์ด ์์
ํ์ผ๋ก ์ ์ฅ
|
34 |
result_df.to_excel(output_file, index=False)
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
if __name__ == "__main__":
|
37 |
-
|
38 |
-
output_file = "output.xlsx" # ์ถ๋ ฅ ํ์ผ๋ช
|
39 |
-
|
40 |
-
process_excel(input_file, output_file)
|
|
|
1 |
+
from flask import Flask, request, redirect, url_for, send_file, render_template
|
2 |
import pandas as pd
|
3 |
from collections import Counter
|
4 |
+
import os
|
5 |
+
|
6 |
+
app = Flask(__name__)
|
7 |
+
app.config['UPLOAD_FOLDER'] = 'uploads/'
|
8 |
+
app.config['PROCESSED_FOLDER'] = 'processed/'
|
9 |
+
|
10 |
+
# ๋๋ ํ ๋ฆฌ ์์ฑ
|
11 |
+
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
12 |
+
os.makedirs(app.config['PROCESSED_FOLDER'], exist_ok=True)
|
13 |
|
14 |
def extract_keywords(text):
|
15 |
+
# ํ
์คํธ์์ ์ค๋ณต์ ์ ๊ฑฐํ๊ณ ๊ณต๋ฐฑ์ผ๋ก ๋ถ๋ฆฌํ์ฌ ํค์๋ ๋ฆฌ์คํธ ๋ฐํ
|
16 |
+
keywords = list(set(text.split(" ")))
|
17 |
return keywords
|
18 |
|
19 |
def process_excel(input_file, output_file):
|
20 |
# ์์
ํ์ผ ์ฝ๊ธฐ
|
21 |
df = pd.read_excel(input_file)
|
|
|
|
|
22 |
all_keywords = []
|
23 |
|
|
|
24 |
for index, row in df.iterrows():
|
25 |
+
product_name = row['์ํ๋ช
(๋งํฌ)']
|
26 |
if pd.notna(product_name):
|
27 |
keywords = extract_keywords(product_name)
|
28 |
all_keywords.extend(keywords)
|
|
|
32 |
|
33 |
# ๊ฒฐ๊ณผ๋ฅผ ๋ฐ์ดํฐํ๋ ์์ผ๋ก ๋ณํ
|
34 |
result_df = pd.DataFrame(keyword_counter.items(), columns=['ํค์๋', '๋น๋์'])
|
|
|
|
|
35 |
result_df = result_df.sort_values(by='๋น๋์', ascending=False)
|
36 |
|
37 |
# ๊ฒฐ๊ณผ๋ฅผ ์๋ก์ด ์์
ํ์ผ๋ก ์ ์ฅ
|
38 |
result_df.to_excel(output_file, index=False)
|
39 |
|
40 |
+
@app.route('/', methods=['GET', 'POST'])
|
41 |
+
def upload_file():
|
42 |
+
if request.method == 'POST':
|
43 |
+
file = request.files['file']
|
44 |
+
if file and file.filename.endswith('.xlsx'):
|
45 |
+
filepath = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
|
46 |
+
file.save(filepath)
|
47 |
+
|
48 |
+
output_file = os.path.join(app.config['PROCESSED_FOLDER'], 'output.xlsx')
|
49 |
+
process_excel(filepath, output_file)
|
50 |
+
|
51 |
+
return send_file(output_file, as_attachment=True)
|
52 |
+
|
53 |
+
return '''
|
54 |
+
<!doctype html>
|
55 |
+
<title>Upload Excel File</title>
|
56 |
+
<h1>Excel ํ์ผ์ ์
๋ก๋ํ์ธ์</h1>
|
57 |
+
<form method=post enctype=multipart/form-data>
|
58 |
+
<input type=file name=file>
|
59 |
+
<input type=submit value=Upload>
|
60 |
+
</form>
|
61 |
+
'''
|
62 |
+
|
63 |
if __name__ == "__main__":
|
64 |
+
app.run(debug=True)
|
|
|
|
|
|