|
from flask import Flask, request, send_file |
|
import pandas as pd |
|
import re |
|
from collections import Counter |
|
from werkzeug.utils import secure_filename |
|
import os |
|
|
|
app = Flask(__name__) |
|
UPLOAD_FOLDER = 'uploads' |
|
OUTPUT_FOLDER = 'outputs' |
|
|
|
os.makedirs(UPLOAD_FOLDER, exist_ok=True) |
|
os.makedirs(OUTPUT_FOLDER, exist_ok=True) |
|
|
|
@app.route('/') |
|
def index(): |
|
return ''' |
|
<h1>μμ
ν€μλ μΆμΆκΈ°</h1> |
|
<form action="/process" method="post" enctype="multipart/form-data"> |
|
<input type="file" name="file" accept=".xlsx"/> |
|
<button type="submit">μ
λ‘λ λ° μ²λ¦¬</button> |
|
</form> |
|
''' |
|
|
|
@app.route('/process', methods=['POST']) |
|
def process(): |
|
file = request.files['file'] |
|
filename = secure_filename(file.filename) |
|
filepath = os.path.join(UPLOAD_FOLDER, filename) |
|
file.save(filepath) |
|
|
|
|
|
df = pd.read_excel(filepath, engine='openpyxl') |
|
|
|
|
|
data = df.iloc[3:, 3].dropna().astype(str) |
|
|
|
|
|
keywords = [] |
|
for text in data: |
|
text = re.sub(r'[^\w\s]', '', text) |
|
keywords.extend(text.split()) |
|
|
|
|
|
keyword_counts = Counter(keywords) |
|
sorted_keywords = sorted(keyword_counts.items(), key=lambda x: x[1], reverse=True) |
|
|
|
|
|
result_df = pd.DataFrame(sorted_keywords, columns=['ν€μλ', 'λΉλ']) |
|
|
|
|
|
output_path = os.path.join(OUTPUT_FOLDER, 'result.xlsx') |
|
with pd.ExcelWriter(output_path, engine='openpyxl') as writer: |
|
result_df.to_excel(writer, index=False, startrow=4, startcol=0, header=False) |
|
sheet = writer.sheets['Sheet1'] |
|
sheet.cell(row=4, column=1).value = "A5μ
λͺ
" |
|
sheet.cell(row=4, column=2).value = "B5μ
λͺ
" |
|
|
|
return send_file(output_path, as_attachment=True, download_name='result.xlsx') |
|
|
|
if __name__ == '__main__': |
|
app.run(debug=True) |
|
|