File size: 1,973 Bytes
c3a7e1f
b556bb6
 
 
c3a7e1f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
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
53
54
55
56
57
58
59
60
61
62
63
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')

    # D4:D์—ด์˜ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ
    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)