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"