Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import json | |
| import os | |
| import uuid | |
| import glob | |
| from datetime import datetime | |
| import numpy as np | |
| import platform | |
| import networkx as nx | |
| import plotly.graph_objects as go | |
| from sklearn.metrics.pairwise import cosine_similarity | |
| import plotly | |
| import matplotlib.pyplot as plt | |
| import matplotlib.font_manager as fm | |
| from sklearn.manifold import TSNE | |
| import warnings | |
| warnings.filterwarnings('ignore') | |
| # ํ์ด์ง ์ค์ | |
| st.set_page_config( | |
| page_title="ํ๊ตญ์ด ๋จ์ด ์๋ฏธ ๋คํธ์ํฌ ์๊ฐํ", | |
| page_icon="๐ค", | |
| layout="wide" | |
| ) | |
| # ํด๋ ๊ฒฝ๋ก ์ค์ | |
| DATA_FOLDER = 'data' | |
| UPLOAD_FOLDER = 'uploads' | |
| # ํด๋ ์์ฑ | |
| if not os.path.exists(UPLOAD_FOLDER): | |
| os.makedirs(UPLOAD_FOLDER) | |
| # ์ธ์ ์ํ ์ด๊ธฐํ | |
| if 'model' not in st.session_state: | |
| st.session_state.model = None | |
| if 'embeddings_cache' not in st.session_state: | |
| st.session_state.embeddings_cache = {} | |
| if 'graph_cache' not in st.session_state: | |
| st.session_state.graph_cache = {} | |
| if 'data_files' not in st.session_state: | |
| st.session_state.data_files = {} | |
| if 'selected_files' not in st.session_state: | |
| st.session_state.selected_files = [] | |
| if 'threshold' not in st.session_state: | |
| st.session_state.threshold = 0.7 | |
| # --- ํ๊ธ ํฐํธ ์ค์ ํจ์ --- | |
| def set_korean_font(): | |
| """ | |
| ํ์ฌ ์ด์์ฒด์ ์ ๋ง๋ ํ๊ธ ํฐํธ๋ฅผ matplotlib ๋ฐ Plotly์ฉ์ผ๋ก ์ค์ ์๋ํ๊ณ , | |
| Plotly์์ ์ฌ์ฉํ ํฐํธ ์ด๋ฆ์ ๋ฐํํฉ๋๋ค. | |
| """ | |
| system_name = platform.system() | |
| plotly_font_name = None # Plotly์์ ์ฌ์ฉํ ํฐํธ ์ด๋ฆ | |
| # Matplotlib ํฐํธ ์ค์ | |
| if system_name == "Windows": | |
| font_name = "Malgun Gothic" | |
| plotly_font_name = "Malgun Gothic" | |
| elif system_name == "Darwin": # MacOS | |
| font_name = "AppleGothic" | |
| plotly_font_name = "AppleGothic" | |
| elif system_name == "Linux": | |
| # Linux์์ ์ ํธํ๋ ํ๊ธ ํฐํธ ๊ฒฝ๋ก ๋๋ ์ด๋ฆ ์ค์ | |
| font_path = "/usr/share/fonts/truetype/nanum/NanumGothic.ttf" | |
| plotly_font_name_linux = "NanumGothic" # Plotly๋ ํฐํธ '์ด๋ฆ'์ ์ฃผ๋ก ์ฌ์ฉ | |
| if os.path.exists(font_path): | |
| font_name = fm.FontProperties(fname=font_path).get_name() | |
| plotly_font_name = plotly_font_name_linux | |
| else: | |
| # ์์คํ ์์ 'Nanum' ํฌํจ ํฐํธ ์ฐพ๊ธฐ ์๋ | |
| try: | |
| available_fonts = [f.name for f in fm.fontManager.ttflist] | |
| nanum_fonts = [name for name in available_fonts if 'Nanum' in name] | |
| if nanum_fonts: | |
| font_name = nanum_fonts[0] | |
| # Plotly์์ ์ฌ์ฉํ ์ด๋ฆ๋ ๋น์ทํ๊ฒ ์ค์ (์ ํํ ์ด๋ฆ์ ์์คํ ๋ง๋ค ๋ค๋ฅผ ์ ์์) | |
| plotly_font_name = font_name if 'Nanum' in font_name else plotly_font_name_linux | |
| else: | |
| # ๋ค๋ฅธ OS ํฐํธ ์๋ | |
| if "Malgun Gothic" |