File size: 2,204 Bytes
d24bb65 a5ab553 d24bb65 a5ab553 d24bb65 a5ab553 d24bb65 a5ab553 d24bb65 a5ab553 d24bb65 a5ab553 |
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 |
import gradio as gr
import pandas as pd
import re
from collections import Counter
from openpyxl import Workbook
from openpyxl.chart import BarChart, Reference
def process_excel(file):
# ์์
ํ์ผ ์ฝ๊ธฐ
df = pd.read_excel(file)
# D์ด(D4๋ถํฐ)์ ์ํ๋ช
๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ
data = df.iloc[3:, 3].dropna().astype(str) # D4๋ถํฐ D์ด ์ ์ฒด ๊ฐ์ ธ์ค๊ธฐ (4๋ฒ์งธ ํ๋ถํฐ ์์)
# ํค์๋ ์ถ์ถ ๋ฐ ์ฒ๋ฆฌ
keyword_list = []
for item in data:
keywords = re.findall(r'\b\w+\b', item) # ํน์๋ฌธ์ ์ ๊ฑฐํ๊ณ ํค์๋ ์ถ์ถ
keywords = list(set(keywords)) # ์ค๋ณต ์ ๊ฑฐ
keyword_list.extend(keywords)
# ํค์๋ ๋น๋์ ๊ณ์ฐ
keyword_count = Counter(keyword_list)
# ๊ฒฐ๊ณผ๋ฅผ ๋ฐ์ดํฐํ๋ ์์ผ๋ก ๋ณํ
result_df = pd.DataFrame(keyword_count.items(), columns=['ํค์๋', '๋น๋']).sort_values(by='๋น๋', ascending=False).reset_index(drop=True)
# A4์ B4 ์
๋ถํฐ ๋ฐ์ดํฐ๊ฐ ๋ค์ด๊ฐ๋๋ก ์์
with pd.ExcelWriter('keyword_result.xlsx', engine='openpyxl') as writer:
result_df.to_excel(writer, index=False, startrow=3, startcol=0) # A4 ์
์ ํด๋นํ๋ 3๋ฒ์งธ ํ, 0๋ฒ์งธ ์ด๋ถํฐ ์์
# ์ํฌ๋ถ ๋ฐ ์ํธ ๊ฐ์ ธ์ค๊ธฐ
workbook =
sheet = writer.sheets['Sheet1']
# ์ฐจํธ ์์ฑ
chart = BarChart()
data = Reference(sheet, min_col=2, min_row=4, max_row=3 + len(result_df), max_col=2)
categories = Reference(sheet, min_col=1, min_row=4, max_row=3 + len(result_df))
chart.add_data(data, titles_from_data=True)
chart.set_categories(categories)
chart.title = "ํค์๋ ๋น๋์"
chart.x_axis.title = "ํค์๋"
chart.y_axis.title = "๋น๋"
# ์ฐจํธ๋ฅผ ์ํธ์ ์ถ๊ฐ
sheet.add_chart(chart, "E4") # E4 ์
์ ์ฐจํธ๋ฅผ ์ถ๊ฐ
return 'keyword_result.xlsx'
# Gradio ์ธํฐํ์ด์ค ์์ฑ
interface = gr.Interface(
fn=process_excel,
inputs=gr.File(label="์์
ํ์ผ ์
๋ก๋"),
outputs=gr.File(label="๋ถ์ ๊ฒฐ๊ณผ ํ์ผ")
)
if __name__ == "__main__":
interface.launch() |