Update app.py
Browse files
app.py
CHANGED
|
@@ -1,52 +1,62 @@
|
|
| 1 |
-
import
|
| 2 |
import pandas as pd
|
| 3 |
import re
|
| 4 |
from collections import Counter
|
| 5 |
-
from
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
)
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, send_file
|
| 2 |
import pandas as pd
|
| 3 |
import re
|
| 4 |
from collections import Counter
|
| 5 |
+
from werkzeug.utils import secure_filename
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
app = Flask(__name__)
|
| 9 |
+
UPLOAD_FOLDER = 'uploads'
|
| 10 |
+
OUTPUT_FOLDER = 'outputs'
|
| 11 |
+
|
| 12 |
+
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
| 13 |
+
os.makedirs(OUTPUT_FOLDER, exist_ok=True)
|
| 14 |
+
|
| 15 |
+
@app.route('/')
|
| 16 |
+
def index():
|
| 17 |
+
return '''
|
| 18 |
+
<h1>์์
ํค์๋ ์ถ์ถ๊ธฐ</h1>
|
| 19 |
+
<form action="/process" method="post" enctype="multipart/form-data">
|
| 20 |
+
<input type="file" name="file" accept=".xlsx"/>
|
| 21 |
+
<button type="submit">์
๋ก๋ ๋ฐ ์ฒ๋ฆฌ</button>
|
| 22 |
+
</form>
|
| 23 |
+
'''
|
| 24 |
+
|
| 25 |
+
@app.route('/process', methods=['POST'])
|
| 26 |
+
def process():
|
| 27 |
+
file = request.files['file']
|
| 28 |
+
filename = secure_filename(file.filename)
|
| 29 |
+
filepath = os.path.join(UPLOAD_FOLDER, filename)
|
| 30 |
+
file.save(filepath)
|
| 31 |
+
|
| 32 |
+
# ์์
๋ฐ์ดํฐ ์ฝ๊ธฐ
|
| 33 |
+
df = pd.read_excel(filepath, engine='openpyxl')
|
| 34 |
+
|
| 35 |
+
# D4:D์ด์ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ
|
| 36 |
+
data = df.iloc[3:, 3].dropna().astype(str)
|
| 37 |
+
|
| 38 |
+
# ํค์๋ ์ฒ๋ฆฌ
|
| 39 |
+
keywords = []
|
| 40 |
+
for text in data:
|
| 41 |
+
text = re.sub(r'[^\w\s]', '', text) # ํน์๋ฌธ์ ์ ๊ฑฐ
|
| 42 |
+
keywords.extend(text.split())
|
| 43 |
+
|
| 44 |
+
# ํค์๋ ๋น๋ ๊ณ์ฐ
|
| 45 |
+
keyword_counts = Counter(keywords)
|
| 46 |
+
sorted_keywords = sorted(keyword_counts.items(), key=lambda x: x[1], reverse=True)
|
| 47 |
+
|
| 48 |
+
# ๊ฒฐ๊ณผ ๋ฐ์ดํฐํ๋ ์ ์์ฑ
|
| 49 |
+
result_df = pd.DataFrame(sorted_keywords, columns=['ํค์๋', '๋น๋'])
|
| 50 |
+
|
| 51 |
+
# ๊ฒฐ๊ณผ ์์
๋ก ์ ์ฅ
|
| 52 |
+
output_path = os.path.join(OUTPUT_FOLDER, 'result.xlsx')
|
| 53 |
+
with pd.ExcelWriter(output_path, engine='openpyxl') as writer:
|
| 54 |
+
result_df.to_excel(writer, index=False, startrow=4, startcol=0, header=False)
|
| 55 |
+
sheet = writer.sheets['Sheet1']
|
| 56 |
+
sheet.cell(row=4, column=1).value = "A5์
๋ช
"
|
| 57 |
+
sheet.cell(row=4, column=2).value = "B5์
๋ช
"
|
| 58 |
+
|
| 59 |
+
return send_file(output_path, as_attachment=True, download_name='result.xlsx')
|
| 60 |
+
|
| 61 |
+
if __name__ == '__main__':
|
| 62 |
+
app.run(debug=True)
|