Kims12 commited on
Commit
238794e
ยท
verified ยท
1 Parent(s): 10af70f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -13
app.py CHANGED
@@ -1,22 +1,28 @@
 
1
  import pandas as pd
2
  from collections import Counter
3
- import re
 
 
 
 
 
 
 
 
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
- input_file = "input.xlsx" # ์ž…๋ ฅ ํŒŒ์ผ๋ช…
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)