Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,8 +13,8 @@ import colorsys
|
|
| 13 |
# Streamlit 페이지 설정 (반드시 첫 번째 st 명령어여야 함)
|
| 14 |
st.set_page_config(
|
| 15 |
layout="wide",
|
| 16 |
-
page_title="토픽모델링 Tool for SK",
|
| 17 |
-
page_icon="🔍"
|
| 18 |
)
|
| 19 |
|
| 20 |
# KoNLPy 형태소 분석기 초기화
|
|
@@ -29,15 +29,9 @@ default_stop_words = ['이', '그', '저', '것', '수', '등', '들', '및', '
|
|
| 29 |
|
| 30 |
@st.cache_data
|
| 31 |
def preprocess_text(text, stop_words):
|
| 32 |
-
# 숫자 및 특수 문자 제거
|
| 33 |
text = re.sub(r'[^가-힣\s]', '', text)
|
| 34 |
-
|
| 35 |
-
# 형태소 분석 및 명사 추출
|
| 36 |
nouns = okt.nouns(text)
|
| 37 |
-
|
| 38 |
-
# 불용어 제거 및 길이가 1인 단어 제거
|
| 39 |
processed = [word for word in nouns if word not in stop_words and len(word) > 1]
|
| 40 |
-
|
| 41 |
return ' '.join(processed)
|
| 42 |
|
| 43 |
# HSL 색상 생성
|
|
@@ -45,7 +39,7 @@ def generate_colors(n):
|
|
| 45 |
HSV_tuples = [(x * 1.0 / n, 0.5, 0.9) for x in range(n)]
|
| 46 |
return ['#%02x%02x%02x' % tuple(int(x*255) for x in colorsys.hsv_to_rgb(*hsv)) for hsv in HSV_tuples]
|
| 47 |
|
| 48 |
-
# CSS
|
| 49 |
st.markdown("""
|
| 50 |
<style>
|
| 51 |
.header {
|
|
@@ -65,8 +59,8 @@ st.markdown("""
|
|
| 65 |
padding-right: 20px;
|
| 66 |
}
|
| 67 |
.main-content {
|
| 68 |
-
margin-top: 50px;
|
| 69 |
-
padding: 20px;
|
| 70 |
}
|
| 71 |
.stDataFrame {
|
| 72 |
width: 100%;
|
|
@@ -83,61 +77,48 @@ st.markdown("""
|
|
| 83 |
</style>
|
| 84 |
""", unsafe_allow_html=True)
|
| 85 |
|
| 86 |
-
# 헤더
|
| 87 |
-
|
| 88 |
<div class="header">
|
| 89 |
<div class="header-content">
|
| 90 |
mySUNI 행복 College 행복담당조직 Meet-Up
|
| 91 |
</div>
|
| 92 |
</div>
|
| 93 |
-
"""
|
| 94 |
-
|
| 95 |
-
# 헤더 렌더링
|
| 96 |
-
st.markdown(header_html, unsafe_allow_html=True)
|
| 97 |
|
| 98 |
-
# 사이드바 접기/펼치기 기능
|
| 99 |
if 'sidebar_state' not in st.session_state:
|
| 100 |
-
st.session_state.sidebar_state =
|
| 101 |
|
| 102 |
def toggle_sidebar():
|
| 103 |
-
st.session_state.sidebar_state =
|
|
|
|
|
|
|
|
|
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
st.button("사이드바 접기/펼치기", on_click=toggle_sidebar)
|
| 106 |
|
| 107 |
-
|
|
|
|
| 108 |
with st.sidebar:
|
| 109 |
st.header('설정')
|
| 110 |
-
|
| 111 |
# Claude API 키 설정
|
| 112 |
api_key = st.text_input("Claude API 키를 입력하세요", type="password")
|
| 113 |
if not api_key:
|
| 114 |
api_key = os.environ.get("ANTHROPIC_API_KEY")
|
| 115 |
-
|
| 116 |
# 불용어 설정
|
| 117 |
stop_words_input = st.text_area("불용어 목록 (쉼표로 구분)", ', '.join(default_stop_words))
|
| 118 |
stop_words = [word.strip() for word in stop_words_input.split(',') if word.strip()]
|
| 119 |
-
|
| 120 |
# 파일 업로드
|
| 121 |
uploaded_file = st.file_uploader("CSV 파일을 업로드하세요", type="csv")
|
| 122 |
|
| 123 |
-
st.markdown('<div class="main-content">', unsafe_allow_html=True)
|
| 124 |
-
st.title('토픽모델링 Tool for SK')
|
| 125 |
-
|
| 126 |
-
# 사이드바 설정
|
| 127 |
-
st.sidebar.header('설정')
|
| 128 |
-
|
| 129 |
-
# Claude API 키 설정
|
| 130 |
-
api_key = st.sidebar.text_input("Claude API 키를 입력하세요", type="password")
|
| 131 |
-
if not api_key:
|
| 132 |
-
api_key = os.environ.get("ANTHROPIC_API_KEY")
|
| 133 |
-
|
| 134 |
-
# 불용어 설정
|
| 135 |
-
stop_words_input = st.sidebar.text_area("불용어 목록 (쉼표로 구분)", ', '.join(default_stop_words))
|
| 136 |
-
stop_words = [word.strip() for word in stop_words_input.split(',') if word.strip()]
|
| 137 |
-
|
| 138 |
-
# 파일 업로드
|
| 139 |
-
uploaded_file = st.sidebar.file_uploader("CSV 파일을 업로드하세요", type="csv")
|
| 140 |
-
|
| 141 |
if uploaded_file is not None:
|
| 142 |
# 데이터 읽기
|
| 143 |
df = pd.read_csv(uploaded_file)
|
|
|
|
| 13 |
# Streamlit 페이지 설정 (반드시 첫 번째 st 명령어여야 함)
|
| 14 |
st.set_page_config(
|
| 15 |
layout="wide",
|
| 16 |
+
page_title="토픽모델링 Tool for SK",
|
| 17 |
+
page_icon="🔍"
|
| 18 |
)
|
| 19 |
|
| 20 |
# KoNLPy 형태소 분석기 초기화
|
|
|
|
| 29 |
|
| 30 |
@st.cache_data
|
| 31 |
def preprocess_text(text, stop_words):
|
|
|
|
| 32 |
text = re.sub(r'[^가-힣\s]', '', text)
|
|
|
|
|
|
|
| 33 |
nouns = okt.nouns(text)
|
|
|
|
|
|
|
| 34 |
processed = [word for word in nouns if word not in stop_words and len(word) > 1]
|
|
|
|
| 35 |
return ' '.join(processed)
|
| 36 |
|
| 37 |
# HSL 색상 생성
|
|
|
|
| 39 |
HSV_tuples = [(x * 1.0 / n, 0.5, 0.9) for x in range(n)]
|
| 40 |
return ['#%02x%02x%02x' % tuple(int(x*255) for x in colorsys.hsv_to_rgb(*hsv)) for hsv in HSV_tuples]
|
| 41 |
|
| 42 |
+
# CSS 스타일 정의
|
| 43 |
st.markdown("""
|
| 44 |
<style>
|
| 45 |
.header {
|
|
|
|
| 59 |
padding-right: 20px;
|
| 60 |
}
|
| 61 |
.main-content {
|
| 62 |
+
margin-top: 50px;
|
| 63 |
+
padding: 20px;
|
| 64 |
}
|
| 65 |
.stDataFrame {
|
| 66 |
width: 100%;
|
|
|
|
| 77 |
</style>
|
| 78 |
""", unsafe_allow_html=True)
|
| 79 |
|
| 80 |
+
# 헤더 렌더링
|
| 81 |
+
st.markdown("""
|
| 82 |
<div class="header">
|
| 83 |
<div class="header-content">
|
| 84 |
mySUNI 행복 College 행복담당조직 Meet-Up
|
| 85 |
</div>
|
| 86 |
</div>
|
| 87 |
+
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
+
# 사이드바 접기/펼치기 기능
|
| 90 |
if 'sidebar_state' not in st.session_state:
|
| 91 |
+
st.session_state.sidebar_state = 'expanded'
|
| 92 |
|
| 93 |
def toggle_sidebar():
|
| 94 |
+
if st.session_state.sidebar_state == 'expanded':
|
| 95 |
+
st.session_state.sidebar_state = 'collapsed'
|
| 96 |
+
else:
|
| 97 |
+
st.session_state.sidebar_state = 'expanded'
|
| 98 |
|
| 99 |
+
# 메인 컨텐츠
|
| 100 |
+
st.markdown('<div class="main-content">', unsafe_allow_html=True)
|
| 101 |
+
st.title('토픽모델링 Tool for SK')
|
| 102 |
+
|
| 103 |
+
# 사이드바 토글 버튼
|
| 104 |
st.button("사이드바 접기/펼치기", on_click=toggle_sidebar)
|
| 105 |
|
| 106 |
+
# 사이드바 내용
|
| 107 |
+
if st.session_state.sidebar_state == 'expanded':
|
| 108 |
with st.sidebar:
|
| 109 |
st.header('설정')
|
|
|
|
| 110 |
# Claude API 키 설정
|
| 111 |
api_key = st.text_input("Claude API 키를 입력하세요", type="password")
|
| 112 |
if not api_key:
|
| 113 |
api_key = os.environ.get("ANTHROPIC_API_KEY")
|
| 114 |
+
|
| 115 |
# 불용어 설정
|
| 116 |
stop_words_input = st.text_area("불용어 목록 (쉼표로 구분)", ', '.join(default_stop_words))
|
| 117 |
stop_words = [word.strip() for word in stop_words_input.split(',') if word.strip()]
|
| 118 |
+
|
| 119 |
# 파일 업로드
|
| 120 |
uploaded_file = st.file_uploader("CSV 파일을 업로드하세요", type="csv")
|
| 121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
if uploaded_file is not None:
|
| 123 |
# 데이터 읽기
|
| 124 |
df = pd.read_csv(uploaded_file)
|