|
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) |
|
|
|
|
|
data = df.iloc[3:, 3].dropna().astype(str) |
|
|
|
|
|
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) |
|
|
|
|
|
with pd.ExcelWriter('keyword_result.xlsx', engine='openpyxl') as writer: |
|
result_df.to_excel(writer, index=False, startrow=3, startcol=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") |
|
|
|
return 'keyword_result.xlsx' |
|
|
|
|
|
interface = gr.Interface( |
|
fn=process_excel, |
|
inputs=gr.File(label="์์
ํ์ผ ์
๋ก๋"), |
|
outputs=gr.File(label="๋ถ์ ๊ฒฐ๊ณผ ํ์ผ") |
|
) |
|
|
|
if __name__ == "__main__": |
|
interface.launch() |