Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
from collections import Counter
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import openpyxl
|
| 5 |
+
|
| 6 |
+
def extract_keywords(file):
|
| 7 |
+
# 엑셀 파일 읽기
|
| 8 |
+
df = pd.read_excel(file, engine='openpyxl')
|
| 9 |
+
|
| 10 |
+
# 상품명 열에서 D4부터 끝까지 텍스트 추출
|
| 11 |
+
product_names = df['상품명'][3:] # D4 셀부터
|
| 12 |
+
|
| 13 |
+
keywords = []
|
| 14 |
+
|
| 15 |
+
for name in product_names:
|
| 16 |
+
if pd.notna(name): # NaN 값 체크
|
| 17 |
+
words = name.split(" ") # 공백 기준으로 단어 분리
|
| 18 |
+
keywords.extend(words)
|
| 19 |
+
|
| 20 |
+
# 키워드 빈도수 계산
|
| 21 |
+
keyword_count = Counter(keywords)
|
| 22 |
+
|
| 23 |
+
# 데이터프레임으로 변환
|
| 24 |
+
result_df = pd.DataFrame(keyword_count.items(), columns=['키워드', '빈도수'])
|
| 25 |
+
|
| 26 |
+
# 빈도수 기준으로 내림차순 정렬
|
| 27 |
+
result_df = result_df.sort_values(by='빈도수', ascending=False).reset_index(drop=True)
|
| 28 |
+
|
| 29 |
+
# 결과를 새로운 엑셀 파일로 저장
|
| 30 |
+
output_path = "/mnt/data/키워드_분석_결과.xlsx"
|
| 31 |
+
result_df.to_excel(output_path, index=False)
|
| 32 |
+
|
| 33 |
+
return result_df, output_path
|
| 34 |
+
|
| 35 |
+
def keyword_analysis_interface(file):
|
| 36 |
+
result_df, output_path = extract_keywords(file)
|
| 37 |
+
return result_df, output_path
|
| 38 |
+
|
| 39 |
+
# Gradio 인터페이스 설정
|
| 40 |
+
interface = gr.Interface(
|
| 41 |
+
fn=keyword_analysis_interface,
|
| 42 |
+
inputs=gr.File(label="엑셀 파일 업로드"),
|
| 43 |
+
outputs=[gr.Dataframe(headers=["키워드", "빈도수"]), gr.File(label="결과 엑셀 파일 다운로드")],
|
| 44 |
+
title="키워드 빈도수 분석기",
|
| 45 |
+
description="업로드된 엑셀 파일에서 상품명에 대한 키워드를 분석하여 빈도수를 계산합니다."
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
if __name__ == "__main__":
|
| 49 |
+
interface.launch()
|