Spaces:
Sleeping
Sleeping
File size: 2,957 Bytes
a5b44fe |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
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" |