Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,52 +7,22 @@ import matplotlib.pyplot as plt
|
|
| 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')
|
| 14 |
|
| 15 |
-
# ๋๋๋ฐ๋ฅธ๊ณ ๋ ํฐํธ ์ค์
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 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"
|
| 47 |
-
with open(file_path, mode='w', newline='', encoding='utf-8') as file:
|
| 48 |
-
writer = csv.writer(file)
|
| 49 |
-
writer.writerow(["Employee ID", "Employee Name", "Recommended Programs"])
|
| 50 |
-
|
| 51 |
-
# ์ถ์ฒ ๊ฒฐ๊ณผ CSV ํ์ผ์ ๊ธฐ๋ก
|
| 52 |
-
for rec in recommendations:
|
| 53 |
-
writer.writerow(rec)
|
| 54 |
-
|
| 55 |
-
return file_path
|
| 56 |
|
| 57 |
# ์๋์ผ๋ก ์ด์ ๋งค์นญํ๋ ํจ์
|
| 58 |
def auto_match_columns(df, required_cols):
|
|
@@ -92,7 +62,7 @@ def hybrid_rag(employee_file, program_file):
|
|
| 92 |
|
| 93 |
error_msg, employee_cols, program_cols = validate_and_get_columns(employee_df, program_df)
|
| 94 |
if error_msg:
|
| 95 |
-
return error_msg, None, None
|
| 96 |
|
| 97 |
employee_skills = employee_df[employee_cols["current_skills"]].tolist()
|
| 98 |
program_skills = program_df[program_cols["skills_acquired"]].tolist()
|
|
@@ -118,18 +88,7 @@ def hybrid_rag(employee_file, program_file):
|
|
| 118 |
|
| 119 |
recommendations.append(recommendation)
|
| 120 |
|
| 121 |
-
#
|
| 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']]:
|
|
@@ -145,12 +104,12 @@ def hybrid_rag(employee_file, program_file):
|
|
| 145 |
|
| 146 |
plt.figure(figsize=(10, 8))
|
| 147 |
pos = nx.spring_layout(G)
|
| 148 |
-
nx.draw(G, pos, with_labels=True, node_color='lightblue', node_size=3000, font_size=10, font_weight='bold', edge_color='gray'
|
| 149 |
-
plt.title("์ง์๊ณผ ํ๋ก๊ทธ๋จ ๊ฐ์ ๊ด๊ณ", fontsize=14, fontweight='bold'
|
| 150 |
plt.tight_layout()
|
| 151 |
|
| 152 |
-
# CSV
|
| 153 |
-
csv_output =
|
| 154 |
|
| 155 |
# ๊ฒฐ๊ณผ ํ
์ด๋ธ ๋ฐ์ดํฐํ๋ ์ ์์ฑ
|
| 156 |
result_df = pd.DataFrame(recommendation_rows, columns=["Employee ID", "Employee Name", "Recommended Programs"])
|
|
@@ -177,5 +136,4 @@ with gr.Blocks(css=".gradio-button {background-color: #007bff; color: white;} .g
|
|
| 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()
|
|
|
|
| 7 |
import csv
|
| 8 |
import io
|
| 9 |
import matplotlib.font_manager as fm
|
|
|
|
| 10 |
|
| 11 |
# ํ๊ตญ์ด ์ฒ๋ฆฌ๋ฅผ ์ํ KoSentence-BERT ๋ชจ๋ธ ๋ก๋
|
| 12 |
model = SentenceTransformer('jhgan/ko-sbert-sts')
|
| 13 |
|
| 14 |
+
# ๋๋๋ฐ๋ฅธ๊ณ ๋ ํฐํธ ์ค์ (ํ๊น
ํ์ด์ค ํ๊ฒฝ์ ๋ง๊ฒ ์์ )
|
| 15 |
+
plt.rc('font', family='NanumBarunGothic')
|
| 16 |
+
|
| 17 |
+
# Neo4j ๊ด๋ จ ์ฝ๋ ์ ๊ฑฐ (ํ๊น
ํ์ด์ค ํ๊ฒฝ์์๋ ์ฌ์ฉํ๊ธฐ ์ด๋ ค์)
|
| 18 |
+
|
| 19 |
+
# ์ถ์ฒ ๊ฒฐ๊ณผ๋ฅผ CSV ๋ฌธ์์ด๋ก ๋ณํํ๋ ํจ์
|
| 20 |
+
def recommendations_to_csv(recommendations):
|
| 21 |
+
output = io.StringIO()
|
| 22 |
+
writer = csv.writer(output)
|
| 23 |
+
writer.writerow(["Employee ID", "Employee Name", "Recommended Programs"])
|
| 24 |
+
writer.writerows(recommendations)
|
| 25 |
+
return output.getvalue()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# ์๋์ผ๋ก ์ด์ ๋งค์นญํ๋ ํจ์
|
| 28 |
def auto_match_columns(df, required_cols):
|
|
|
|
| 62 |
|
| 63 |
error_msg, employee_cols, program_cols = validate_and_get_columns(employee_df, program_df)
|
| 64 |
if error_msg:
|
| 65 |
+
return error_msg, None, None
|
| 66 |
|
| 67 |
employee_skills = employee_df[employee_cols["current_skills"]].tolist()
|
| 68 |
program_skills = program_df[program_cols["skills_acquired"]].tolist()
|
|
|
|
| 88 |
|
| 89 |
recommendations.append(recommendation)
|
| 90 |
|
| 91 |
+
# GraphRAG ๋ถ๋ถ ์ ๊ฑฐ (Neo4j ์ฌ์ฉ ๋ถ๊ฐ)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
G = nx.Graph()
|
| 94 |
for employee in employee_df[employee_cols['employee_name']]:
|
|
|
|
| 104 |
|
| 105 |
plt.figure(figsize=(10, 8))
|
| 106 |
pos = nx.spring_layout(G)
|
| 107 |
+
nx.draw(G, pos, with_labels=True, node_color='lightblue', node_size=3000, font_size=10, font_weight='bold', edge_color='gray')
|
| 108 |
+
plt.title("์ง์๊ณผ ํ๋ก๊ทธ๋จ ๊ฐ์ ๊ด๊ณ", fontsize=14, fontweight='bold')
|
| 109 |
plt.tight_layout()
|
| 110 |
|
| 111 |
+
# CSV ๋ฌธ์์ด๋ก ์ถ์ฒ ๊ฒฐ๊ณผ ๋ฐํ
|
| 112 |
+
csv_output = recommendations_to_csv(recommendation_rows)
|
| 113 |
|
| 114 |
# ๊ฒฐ๊ณผ ํ
์ด๋ธ ๋ฐ์ดํฐํ๋ ์ ์์ฑ
|
| 115 |
result_df = pd.DataFrame(recommendation_rows, columns=["Employee ID", "Employee Name", "Recommended Programs"])
|
|
|
|
| 136 |
# ๋ถ์ ๋ฒํผ ํด๋ฆญ ์ ํ
์ด๋ธ, ์ฐจํธ, ํ์ผ ๋ค์ด๋ก๋๋ฅผ ์
๋ฐ์ดํธ
|
| 137 |
analyze_button.click(hybrid_rag, inputs=[employee_file, program_file], outputs=[output_table, chart_output, csv_download])
|
| 138 |
|
|
|
|
| 139 |
demo.launch()
|