import streamlit as st from utils import load_datasets, save_session_cache from streamlit_extras.grid import grid import pandas as pd from streamlit_extras.dataframe_explorer import dataframe_explorer st.title("πŸ’ 데이터 직접 μ„ νƒν•˜κΈ°") # Section 1: Data Selection st.header("1️⃣ 데이터 λͺ©λ‘ 필터링 ν•˜κΈ°") dataframe = load_datasets() dataframe['keywords'] = dataframe['keywords'].apply(lambda x: ', '.join(x) if isinstance(x, list) else x) list_columns = [col for col in dataframe.columns if dataframe[col].apply(lambda x: isinstance(x, list)).all()] dict_columns = [col for col in dataframe.columns if dataframe[col].apply(lambda x: isinstance(x, dict)).all()] # list νƒ€μž…μ˜ μ»¬λŸΌμ„ λ“œλž dataframe = dataframe.drop(columns=list_columns) dataframe = dataframe.drop(columns=dict_columns) filtered_df = dataframe_explorer(dataframe, case=False) st.dataframe(filtered_df, use_container_width=True) st.divider() st.header("2️⃣ 뢄석 데이터 μ„ νƒν•˜κΈ°") selectable_dataset_list = [None] + filtered_df['title'].values.tolist() # Select data for analysis selected_dataset = st.selectbox( "πŸ” 뢄석할 데이터λ₯Ό μ„ νƒν•˜μ„Έμš”", selectable_dataset_list, index=selectable_dataset_list.index(st.session_state.selected_dataset) if st.session_state.selected_dataset in selectable_dataset_list else 0) st.session_state['selected_dataset'] = selected_dataset st.divider() # session_id=save_session_cache(st.session_state.to_dict()) def switch_to_summarization(): st.switch_page(f"_pages/summarization.py") st.header("3️⃣ 데이터 μš”μ•½μœΌλ‘œ λ„˜μ–΄κ°€κΈ°") next_page = st.button(label=f"οΈβœ… {st.session_state.selected_dataset}으둜 μš”μ•½ν•˜κΈ°" if st.session_state.selected_dataset else "β›” 데이터λ₯Ό 선택해야 μš”μ•½μ„ λ³Ό 수 μžˆμŠ΅λ‹ˆλ‹€.", use_container_width=True, type="secondary", disabled=st.session_state.selected_dataset is None, ) if next_page: switch_to_summarization() st.divider()