Spaces:
Sleeping
Sleeping
soojeongcrystal
commited on
Commit
โข
402b304
1
Parent(s):
6532346
Update app.py
Browse files
app.py
CHANGED
@@ -6,10 +6,24 @@ import networkx as nx
|
|
6 |
import matplotlib.pyplot as plt
|
7 |
import csv
|
8 |
import datetime
|
|
|
9 |
|
10 |
# Sentence-BERT ๋ชจ๋ธ ๋ก๋
|
11 |
model = SentenceTransformer('all-MiniLM-L6-v2')
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
# ์ถ์ฒ ๊ฒฐ๊ณผ์ ํผ๋๋ฐฑ์ ๊ธฐ๋กํ๋ ํจ์
|
14 |
def log_recommendation(employee_name, recommended_programs, feedback=None):
|
15 |
with open('recommendation_log.csv', mode='a', newline='') as file:
|
@@ -19,34 +33,41 @@ def log_recommendation(employee_name, recommended_programs, feedback=None):
|
|
19 |
|
20 |
# ์ง์ ๋ฐ์ดํฐ๋ฅผ ๋ถ์ํ์ฌ ๊ต์ก ํ๋ก๊ทธ๋จ์ ์ถ์ฒํ๊ณ ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ํจ์
|
21 |
def analyze_data(employee_file, program_file, feedback=None):
|
|
|
22 |
employee_df = pd.read_csv(employee_file.name)
|
23 |
program_df = pd.read_csv(program_file.name)
|
24 |
|
|
|
25 |
employee_skills = employee_df['current_skills'].tolist()
|
26 |
program_skills = program_df['skills_acquired'].tolist()
|
27 |
employee_embeddings = model.encode(employee_skills)
|
28 |
program_embeddings = model.encode(program_skills)
|
29 |
|
|
|
30 |
similarities = cosine_similarity(employee_embeddings, program_embeddings)
|
31 |
|
|
|
32 |
recommendations = []
|
|
|
33 |
for i, employee in employee_df.iterrows():
|
34 |
recommended_programs = []
|
35 |
for j, program in program_df.iterrows():
|
36 |
-
if similarities[i][j] > 0.5:
|
37 |
recommended_programs.append(f"{program['program_name']} ({program['duration']})")
|
38 |
|
39 |
if recommended_programs:
|
40 |
recommendation = f"์ง์ {employee['employee_name']}์ ์ถ์ฒ ํ๋ก๊ทธ๋จ: {', '.join(recommended_programs)}"
|
|
|
41 |
else:
|
42 |
recommendation = f"์ง์ {employee['employee_name']}์๊ฒ ์ ํฉํ ํ๋ก๊ทธ๋จ์ด ์์ต๋๋ค."
|
|
|
43 |
|
|
|
44 |
log_recommendation(employee['employee_name'], recommended_programs, feedback)
|
45 |
|
46 |
recommendations.append(recommendation)
|
47 |
|
48 |
-
|
49 |
-
|
50 |
G = nx.Graph()
|
51 |
for employee in employee_df['employee_name']:
|
52 |
G.add_node(employee, type='employee')
|
@@ -56,16 +77,20 @@ def analyze_data(employee_file, program_file, feedback=None):
|
|
56 |
|
57 |
for i, employee in employee_df.iterrows():
|
58 |
for j, program in program_df.iterrows():
|
59 |
-
if similarities[i][j] > 0.5:
|
60 |
G.add_edge(employee['employee_name'], program['program_name'])
|
61 |
|
|
|
62 |
plt.figure(figsize=(10, 8))
|
63 |
pos = nx.spring_layout(G)
|
64 |
nx.draw(G, pos, with_labels=True, node_color='skyblue', node_size=2000, font_size=10, font_weight='bold')
|
65 |
plt.title("์ง์๊ณผ ํ๋ก๊ทธ๋จ ๊ฐ์ ๊ด๊ณ")
|
66 |
plt.tight_layout()
|
67 |
|
68 |
-
|
|
|
|
|
|
|
69 |
|
70 |
# ์์ ๋ฐ์ดํฐ๋ฅผ ๋ณด์ฌ์ฃผ๋ ํจ์
|
71 |
def show_example_data():
|
@@ -97,30 +122,17 @@ with gr.Blocks() as demo:
|
|
97 |
with gr.Column(scale=1):
|
98 |
gr.Markdown("# HybridRAG ์์คํ
")
|
99 |
|
100 |
-
#
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
output_text = gr.Textbox(label="๋ถ์ ๊ฒฐ๊ณผ")
|
112 |
-
|
113 |
-
# HR ๊ด๋ฆฌ์๋ง ์ฌ์ฉํ ์ ์๋ ๊ธฐ๋ฅ์ ์ถ๊ฐ
|
114 |
-
feedback_input = gr.Radio(choices=["๋ง์กฑ", "๋ถ๋ง์กฑ"], label="์ง์ ํผ๋๋ฐฑ ๊ธฐ๋ก")
|
115 |
-
|
116 |
-
analyze_button.click(analyze_data, inputs=[employee_file, program_file, feedback_input], outputs=[output_text])
|
117 |
-
|
118 |
-
with gr.Tab("์ง์"):
|
119 |
-
with gr.Box(visible=True) as employee_box:
|
120 |
-
gr.Markdown("## ์ง์ ์ธํฐํ์ด์ค")
|
121 |
-
gr.Markdown("์ง์์๊ฒ ๋ง์ถคํ ๊ต์ก ํ๋ก๊ทธ๋จ ์ถ์ฒ์ ์ ๊ณตํฉ๋๋ค.")
|
122 |
-
employee_data = gr.DataFrame(label="์ง์ ๊ฐ์ธ ๋ฐ์ดํฐ ์์")
|
123 |
-
gr.Button("ํ๋ก๊ทธ๋จ ์ถ์ฒ ์์")
|
124 |
|
125 |
# ์์ ๋ฐ์ดํฐ๋ฅผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ๋ก ์ ๊ณต
|
126 |
example_button = gr.Button("์์ ๋ฐ์ดํฐ ๋ณด๊ธฐ")
|
@@ -128,5 +140,16 @@ with gr.Blocks() as demo:
|
|
128 |
program_example_output = gr.DataFrame(label="๊ต์ก ํ๋ก๊ทธ๋จ ๋ฐ์ดํฐ ์์")
|
129 |
example_button.click(show_example_data, outputs=[employee_example_output, program_example_output])
|
130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
# Gradio ์ธํฐํ์ด์ค ์คํ
|
132 |
demo.launch()
|
|
|
6 |
import matplotlib.pyplot as plt
|
7 |
import csv
|
8 |
import datetime
|
9 |
+
import io
|
10 |
|
11 |
# Sentence-BERT ๋ชจ๋ธ ๋ก๋
|
12 |
model = SentenceTransformer('all-MiniLM-L6-v2')
|
13 |
|
14 |
+
# ์ถ์ฒ ๊ฒฐ๊ณผ๋ฅผ CSV ํ์ผ๋ก ์ ์ฅํ๋ ํจ์
|
15 |
+
def save_recommendations_to_csv(recommendations):
|
16 |
+
output = io.StringIO()
|
17 |
+
writer = csv.writer(output)
|
18 |
+
writer.writerow(["Employee ID", "Employee Name", "Recommended Programs"])
|
19 |
+
|
20 |
+
# ์ถ์ฒ ๊ฒฐ๊ณผ CSV ํ์ผ์ ๊ธฐ๋ก
|
21 |
+
for rec in recommendations:
|
22 |
+
writer.writerow(rec)
|
23 |
+
|
24 |
+
output.seek(0)
|
25 |
+
return output
|
26 |
+
|
27 |
# ์ถ์ฒ ๊ฒฐ๊ณผ์ ํผ๋๋ฐฑ์ ๊ธฐ๋กํ๋ ํจ์
|
28 |
def log_recommendation(employee_name, recommended_programs, feedback=None):
|
29 |
with open('recommendation_log.csv', mode='a', newline='') as file:
|
|
|
33 |
|
34 |
# ์ง์ ๋ฐ์ดํฐ๋ฅผ ๋ถ์ํ์ฌ ๊ต์ก ํ๋ก๊ทธ๋จ์ ์ถ์ฒํ๊ณ ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆฌ๋ ํจ์
|
35 |
def analyze_data(employee_file, program_file, feedback=None):
|
36 |
+
# ์ง์ ๋ฐ์ดํฐ์ ๊ต์ก ํ๋ก๊ทธ๋จ ๋ฐ์ดํฐ ๋ถ๋ฌ์ค๊ธฐ
|
37 |
employee_df = pd.read_csv(employee_file.name)
|
38 |
program_df = pd.read_csv(program_file.name)
|
39 |
|
40 |
+
# ์ง์ ์ญ๋๊ณผ ํ๋ก๊ทธ๋จ ํ์ต ๋ชฉํ๋ฅผ ๋ฒกํฐํ
|
41 |
employee_skills = employee_df['current_skills'].tolist()
|
42 |
program_skills = program_df['skills_acquired'].tolist()
|
43 |
employee_embeddings = model.encode(employee_skills)
|
44 |
program_embeddings = model.encode(program_skills)
|
45 |
|
46 |
+
# ์ ์ฌ๋ ๊ณ์ฐ
|
47 |
similarities = cosine_similarity(employee_embeddings, program_embeddings)
|
48 |
|
49 |
+
# ์ง์๋ณ ์ถ์ฒ ํ๋ก๊ทธ๋จ ๋ฆฌ์คํธ
|
50 |
recommendations = []
|
51 |
+
recommendation_rows = [] # CSV ํ์ผ์ ์ ์ฅํ ๋ฐ์ดํฐ๋ฅผ ์ํ ๋ฆฌ์คํธ
|
52 |
for i, employee in employee_df.iterrows():
|
53 |
recommended_programs = []
|
54 |
for j, program in program_df.iterrows():
|
55 |
+
if similarities[i][j] > 0.5: # ์ ์ฌ๋ ์๊ณ๊ฐ ๊ธฐ์ค
|
56 |
recommended_programs.append(f"{program['program_name']} ({program['duration']})")
|
57 |
|
58 |
if recommended_programs:
|
59 |
recommendation = f"์ง์ {employee['employee_name']}์ ์ถ์ฒ ํ๋ก๊ทธ๋จ: {', '.join(recommended_programs)}"
|
60 |
+
recommendation_rows.append([employee['employee_id'], employee['employee_name'], ", ".join(recommended_programs)])
|
61 |
else:
|
62 |
recommendation = f"์ง์ {employee['employee_name']}์๊ฒ ์ ํฉํ ํ๋ก๊ทธ๋จ์ด ์์ต๋๋ค."
|
63 |
+
recommendation_rows.append([employee['employee_id'], employee['employee_name'], "์ ํฉํ ํ๋ก๊ทธ๋จ ์์"])
|
64 |
|
65 |
+
# ํผ๋๋ฐฑ ๋ก๊ทธ ๊ธฐ๋ก
|
66 |
log_recommendation(employee['employee_name'], recommended_programs, feedback)
|
67 |
|
68 |
recommendations.append(recommendation)
|
69 |
|
70 |
+
# ๋คํธ์ํฌ ๊ทธ๋ํ ์์ฑ
|
|
|
71 |
G = nx.Graph()
|
72 |
for employee in employee_df['employee_name']:
|
73 |
G.add_node(employee, type='employee')
|
|
|
77 |
|
78 |
for i, employee in employee_df.iterrows():
|
79 |
for j, program in program_df.iterrows():
|
80 |
+
if similarities[i][j] > 0.5: # ์ ์ฌ๋ ์๊ณ๊ฐ
|
81 |
G.add_edge(employee['employee_name'], program['program_name'])
|
82 |
|
83 |
+
# ๊ทธ๋ํ ์๊ฐํ
|
84 |
plt.figure(figsize=(10, 8))
|
85 |
pos = nx.spring_layout(G)
|
86 |
nx.draw(G, pos, with_labels=True, node_color='skyblue', node_size=2000, font_size=10, font_weight='bold')
|
87 |
plt.title("์ง์๊ณผ ํ๋ก๊ทธ๋จ ๊ฐ์ ๊ด๊ณ")
|
88 |
plt.tight_layout()
|
89 |
|
90 |
+
# CSV ํ์ผ๋ก ์ถ์ฒ ๊ฒฐ๊ณผ ๋ฐํ
|
91 |
+
csv_output = save_recommendations_to_csv(recommendation_rows)
|
92 |
+
|
93 |
+
return "\n".join(recommendations), plt.gcf(), csv_output
|
94 |
|
95 |
# ์์ ๋ฐ์ดํฐ๋ฅผ ๋ณด์ฌ์ฃผ๋ ํจ์
|
96 |
def show_example_data():
|
|
|
122 |
with gr.Column(scale=1):
|
123 |
gr.Markdown("# HybridRAG ์์คํ
")
|
124 |
|
125 |
+
# ์ง์ ๋ฐ์ดํฐ์ ํ๋ก๊ทธ๋จ ๋ฐ์ดํฐ ์
๋ก๋
|
126 |
+
employee_file = gr.File(label="์ง์ ๋ฐ์ดํฐ ์
๋ก๋")
|
127 |
+
program_file = gr.File(label="๊ต์ก ํ๋ก๊ทธ๋จ ๋ฐ์ดํฐ ์
๋ก๋")
|
128 |
+
analyze_button = gr.Button("๋ถ์ ์์")
|
129 |
+
output_text = gr.Textbox(label="๋ถ์ ๊ฒฐ๊ณผ")
|
130 |
+
|
131 |
+
# HR ๊ด๋ฆฌ์๋ ์ง์ ํผ๋๋ฐฑ์ ๊ธฐ๋กํ ์ ์์ต๋๋ค.
|
132 |
+
feedback_input = gr.Radio(choices=["๋ง์กฑ", "๋ถ๋ง์กฑ"], label="์ง์ ํผ๋๋ฐฑ ๊ธฐ๋ก")
|
133 |
+
|
134 |
+
# ๋ถ์ ๋ฒํผ ํด๋ฆญ ์ ์คํ
|
135 |
+
analyze_button.click(analyze_data, inputs=[employee_file, program_file, feedback_input], outputs=[output_text])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
# ์์ ๋ฐ์ดํฐ๋ฅผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ๋ก ์ ๊ณต
|
138 |
example_button = gr.Button("์์ ๋ฐ์ดํฐ ๋ณด๊ธฐ")
|
|
|
140 |
program_example_output = gr.DataFrame(label="๊ต์ก ํ๋ก๊ทธ๋จ ๋ฐ์ดํฐ ์์")
|
141 |
example_button.click(show_example_data, outputs=[employee_example_output, program_example_output])
|
142 |
|
143 |
+
with gr.Column(scale=2):
|
144 |
+
gr.Markdown("### ์ ๋ณด ํจ๋")
|
145 |
+
gr.Markdown("์
๋ก๋๋ ๋ฐ์ดํฐ์ ๋ํ ๋ถ์ ๋ฐ ๊ฒฐ๊ณผ๋ฅผ ์ฌ๊ธฐ์ ํ์ํฉ๋๋ค.")
|
146 |
+
|
147 |
+
# ์๊ฐํ ์ฐจํธ ์ถ๋ ฅ
|
148 |
+
chart_output = gr.Plot(label="์๊ฐํ ์ฐจํธ")
|
149 |
+
|
150 |
+
# ๋ถ์ ๋ฒํผ ํด๋ฆญ ์ ์ฐจํธ ์
๋ฐ์ดํธ ๋ฐ ์ถ์ฒ ๊ฒฐ๊ณผ ๋ค์ด๋ก๋ ์ถ๊ฐ
|
151 |
+
csv_download = gr.File(label="์ถ์ฒ ๊ฒฐ๊ณผ ๋ค์ด๋ก๋")
|
152 |
+
analyze_button.click(analyze_data, inputs=[employee_file, program_file, feedback_input], outputs=[output_text, chart_output, csv_download])
|
153 |
+
|
154 |
# Gradio ์ธํฐํ์ด์ค ์คํ
|
155 |
demo.launch()
|