Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ import matplotlib.pyplot as plt
|
|
7 |
import csv
|
8 |
import io
|
9 |
import matplotlib.font_manager as fm
|
|
|
10 |
|
11 |
# ํ๊ตญ์ด ์ฒ๋ฆฌ๋ฅผ ์ํ KoSentence-BERT ๋ชจ๋ธ ๋ก๋
|
12 |
model = SentenceTransformer('jhgan/ko-sbert-sts')
|
@@ -16,6 +17,30 @@ font_path = "/root/fonts/NanumBarunGothic.ttf" # Hugging Face ๋ฃจํธ์ ์ ์ฅ
|
|
16 |
fontprop = fm.FontProperties(fname=font_path)
|
17 |
plt.rc('font', family=fontprop.get_name())
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
# ์ถ์ฒ ๊ฒฐ๊ณผ๋ฅผ ์ค์ ํ์ผ๋ก ์ ์ฅํ๋ ํจ์
|
20 |
def save_recommendations_to_file(recommendations):
|
21 |
file_path = "recommendations.csv"
|
@@ -60,7 +85,8 @@ def validate_and_get_columns(employee_df, program_df):
|
|
60 |
return None, employee_cols, program_cols
|
61 |
|
62 |
# ์ง์ ๋ฐ์ดํฐ๋ฅผ ๋ถ์ํ์ฌ ๊ต์ก ํ๋ก๊ทธ๋จ์ ์ถ์ฒํ๊ณ , ํ
์ด๋ธ๊ณผ ๊ทธ๋ํ๋ฅผ ์์ฑํ๋ ํจ์
|
63 |
-
def
|
|
|
64 |
employee_df = pd.read_csv(employee_file.name)
|
65 |
program_df = pd.read_csv(program_file.name)
|
66 |
|
@@ -92,6 +118,19 @@ def analyze_data(employee_file, program_file):
|
|
92 |
|
93 |
recommendations.append(recommendation)
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
G = nx.Graph()
|
96 |
for employee in employee_df[employee_cols['employee_name']]:
|
97 |
G.add_node(employee, type='employee')
|
@@ -136,7 +175,7 @@ with gr.Blocks(css=".gradio-button {background-color: #007bff; color: white;} .g
|
|
136 |
chart_output = gr.Plot(label="์๊ฐํ ์ฐจํธ")
|
137 |
|
138 |
# ๋ถ์ ๋ฒํผ ํด๋ฆญ ์ ํ
์ด๋ธ, ์ฐจํธ, ํ์ผ ๋ค์ด๋ก๋๋ฅผ ์
๋ฐ์ดํธ
|
139 |
-
analyze_button.click(
|
140 |
|
141 |
# Gradio ์ธํฐํ์ด์ค ์คํ
|
142 |
demo.launch()
|
|
|
7 |
import csv
|
8 |
import io
|
9 |
import matplotlib.font_manager as fm
|
10 |
+
from neo4j import GraphDatabase
|
11 |
|
12 |
# ํ๊ตญ์ด ์ฒ๋ฆฌ๋ฅผ ์ํ KoSentence-BERT ๋ชจ๋ธ ๋ก๋
|
13 |
model = SentenceTransformer('jhgan/ko-sbert-sts')
|
|
|
17 |
fontprop = fm.FontProperties(fname=font_path)
|
18 |
plt.rc('font', family=fontprop.get_name())
|
19 |
|
20 |
+
# Neo4j ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐ ํด๋์ค
|
21 |
+
class Neo4jConnection:
|
22 |
+
def __init__(self, uri, user, pwd):
|
23 |
+
self.driver = GraphDatabase.driver(uri, auth=(user, pwd))
|
24 |
+
|
25 |
+
def close(self):
|
26 |
+
self.driver.close()
|
27 |
+
|
28 |
+
def query(self, query, parameters=None, db=None):
|
29 |
+
session = None
|
30 |
+
response = None
|
31 |
+
try:
|
32 |
+
session = self.driver.session(database=db) if db else self.driver.session()
|
33 |
+
response = list(session.run(query, parameters))
|
34 |
+
except Exception as e:
|
35 |
+
print("Query failed:", e)
|
36 |
+
finally:
|
37 |
+
if session:
|
38 |
+
session.close()
|
39 |
+
return response
|
40 |
+
|
41 |
+
# Neo4j ์ฐ๊ฒฐ ์ค์
|
42 |
+
conn = Neo4jConnection(uri="bolt://localhost:7687", user="neo4j", pwd="your_password")
|
43 |
+
|
44 |
# ์ถ์ฒ ๊ฒฐ๊ณผ๋ฅผ ์ค์ ํ์ผ๋ก ์ ์ฅํ๋ ํจ์
|
45 |
def save_recommendations_to_file(recommendations):
|
46 |
file_path = "recommendations.csv"
|
|
|
85 |
return None, employee_cols, program_cols
|
86 |
|
87 |
# ์ง์ ๋ฐ์ดํฐ๋ฅผ ๋ถ์ํ์ฌ ๊ต์ก ํ๋ก๊ทธ๋จ์ ์ถ์ฒํ๊ณ , ํ
์ด๋ธ๊ณผ ๊ทธ๋ํ๋ฅผ ์์ฑํ๋ ํจ์
|
88 |
+
def hybrid_rag(employee_file, program_file):
|
89 |
+
# 1. VectorRAG: KoSentence-BERT๋ฅผ ์ด์ฉํ ์ ์ฌ๋ ๊ณ์ฐ
|
90 |
employee_df = pd.read_csv(employee_file.name)
|
91 |
program_df = pd.read_csv(program_file.name)
|
92 |
|
|
|
118 |
|
119 |
recommendations.append(recommendation)
|
120 |
|
121 |
+
# 2. GraphRAG: Neo4j์์ ํ๋ก๊ทธ๋จ ์ถ์ฒ์ ๊ฐ์ ธ์ด
|
122 |
+
query = """
|
123 |
+
MATCH (e:Employee)-[:HAS_SKILL]->(p:Program)
|
124 |
+
RETURN e.name AS employee_name, p.name AS program_name, p.duration AS duration
|
125 |
+
"""
|
126 |
+
graph_rag_results = conn.query(query)
|
127 |
+
|
128 |
+
# GraphRAG ๊ฒฐ๊ณผ ์ถ๊ฐ
|
129 |
+
for record in graph_rag_results:
|
130 |
+
for row in recommendation_rows:
|
131 |
+
if record['employee_name'] == row[1]:
|
132 |
+
row[2] += f", {record['program_name']} (GraphRAG)"
|
133 |
+
|
134 |
G = nx.Graph()
|
135 |
for employee in employee_df[employee_cols['employee_name']]:
|
136 |
G.add_node(employee, type='employee')
|
|
|
175 |
chart_output = gr.Plot(label="์๊ฐํ ์ฐจํธ")
|
176 |
|
177 |
# ๋ถ์ ๋ฒํผ ํด๋ฆญ ์ ํ
์ด๋ธ, ์ฐจํธ, ํ์ผ ๋ค์ด๋ก๋๋ฅผ ์
๋ฐ์ดํธ
|
178 |
+
analyze_button.click(hybrid_rag, inputs=[employee_file, program_file], outputs=[output_table, chart_output, csv_download])
|
179 |
|
180 |
# Gradio ์ธํฐํ์ด์ค ์คํ
|
181 |
demo.launch()
|