keyword / app.py
CSB261's picture
Update app.py
b556bb6 verified
import gradio as gr
import pandas as pd
import re
from collections import Counter
from openpyxl import Workbook
def process_excel(file):
# ์—‘์…€ ํŒŒ์ผ ์ฝ๊ธฐ
df = pd.read_excel(file, sheet_name=0)
# D4๋ถ€ํ„ฐ D์—ด์˜ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ
product_names = df.iloc[3:, 3].dropna() # D4๋ถ€ํ„ฐ ๋ฐ์ดํ„ฐ ์ถ”์ถœ
# ํ‚ค์›Œ๋“œ ์ถ”์ถœ ๋ฐ ์ •์ œ
all_keywords = []
for name in product_names:
# ํŠน์ˆ˜ ๋ฌธ์ž ์ œ๊ฑฐ ๋ฐ ํ‚ค์›Œ๋“œ ์ถ”์ถœ
keywords = re.findall(r'\b\w+\b', name)
# ์ค‘๋ณต ์ œ๊ฑฐ
unique_keywords = set(keywords)
all_keywords.extend(unique_keywords)
# ๋นˆ๋„ ๊ณ„์‚ฐ
keyword_counts = Counter(all_keywords)
sorted_keywords = keyword_counts.most_common()
# ๊ฒฐ๊ณผ๋ฅผ ์—‘์…€๋กœ ์ €์žฅ
wb = Workbook()
ws = wb.active
ws.title = "Keywords"
ws['A4'] = "ํ‚ค์›Œ๋“œ"
ws['B4'] = "๋นˆ๋„"
for idx, (keyword, count) in enumerate(sorted_keywords, start=5):
ws[f'A{idx}'] = keyword
ws[f'B{idx}'] = count
result_file = "keyword_counts.xlsx"
wb.save(result_file)
return result_file
# Gradio ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ •
iface = gr.Interface(
fn=process_excel,
inputs=gr.File(label="์—‘์…€ ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•˜์„ธ์š”"),
outputs=gr.File(label="๊ฒฐ๊ณผ ์—‘์…€ ํŒŒ์ผ"),
title="์—‘์…€ ํ‚ค์›Œ๋“œ ๋ถ„์„๊ธฐ"
)
if __name__ == "__main__":
iface.launch()