Spaces:
Sleeping
Sleeping
soojeongcrystal
commited on
Commit
โข
9b227e3
1
Parent(s):
2e6bb20
Update app.py
Browse files
app.py
CHANGED
@@ -6,10 +6,15 @@ import networkx as nx
|
|
6 |
import matplotlib.pyplot as plt
|
7 |
import csv
|
8 |
import io
|
9 |
-
import
|
10 |
|
11 |
-
#
|
12 |
-
model = SentenceTransformer('
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
# ์ถ์ฒ ๊ฒฐ๊ณผ๋ฅผ ์ค์ ํ์ผ๋ก ์ ์ฅํ๋ ํจ์
|
15 |
def save_recommendations_to_file(recommendations):
|
@@ -54,14 +59,14 @@ def validate_and_get_columns(employee_df, program_df):
|
|
54 |
|
55 |
return None, employee_cols, program_cols
|
56 |
|
57 |
-
# ์ง์ ๋ฐ์ดํฐ๋ฅผ ๋ถ์ํ์ฌ ๊ต์ก ํ๋ก๊ทธ๋จ์
|
58 |
def analyze_data(employee_file, program_file):
|
59 |
employee_df = pd.read_csv(employee_file.name)
|
60 |
program_df = pd.read_csv(program_file.name)
|
61 |
|
62 |
error_msg, employee_cols, program_cols = validate_and_get_columns(employee_df, program_df)
|
63 |
if error_msg:
|
64 |
-
return error_msg, None, None
|
65 |
|
66 |
employee_skills = employee_df[employee_cols["current_skills"]].tolist()
|
67 |
program_skills = program_df[program_cols["skills_acquired"]].tolist()
|
@@ -71,7 +76,7 @@ def analyze_data(employee_file, program_file):
|
|
71 |
similarities = cosine_similarity(employee_embeddings, program_embeddings)
|
72 |
|
73 |
recommendations = []
|
74 |
-
recommendation_rows = [] # CSV๋ก ์ ์ฅํ ๋ฐ์ดํฐ
|
75 |
for i, employee in employee_df.iterrows():
|
76 |
recommended_programs = []
|
77 |
for j, program in program_df.iterrows():
|
@@ -101,14 +106,17 @@ def analyze_data(employee_file, program_file):
|
|
101 |
|
102 |
plt.figure(figsize=(10, 8))
|
103 |
pos = nx.spring_layout(G)
|
104 |
-
nx.draw(G, pos, with_labels=True, node_color='lightblue', node_size=3000, font_size=10, font_weight='bold', edge_color='gray')
|
105 |
-
plt.title("์ง์๊ณผ ํ๋ก๊ทธ๋จ ๊ฐ์ ๊ด๊ณ", fontsize=14, fontweight='bold')
|
106 |
plt.tight_layout()
|
107 |
|
108 |
# CSV ํ์ผ๋ก ์ถ์ฒ ๊ฒฐ๊ณผ ๋ฐํ
|
109 |
csv_output = save_recommendations_to_file(recommendation_rows)
|
110 |
|
111 |
-
|
|
|
|
|
|
|
112 |
|
113 |
# Gradio ๋ธ๋ก
|
114 |
with gr.Blocks(css=".gradio-button {background-color: #007bff; color: white;} .gradio-textbox {border-color: #6c757d;}") as demo:
|
@@ -120,14 +128,15 @@ with gr.Blocks(css=".gradio-button {background-color: #007bff; color: white;} .g
|
|
120 |
employee_file = gr.File(label="์ง์ ๋ฐ์ดํฐ ์
๋ก๋", interactive=True)
|
121 |
program_file = gr.File(label="๊ต์ก ํ๋ก๊ทธ๋จ ๋ฐ์ดํฐ ์
๋ก๋", interactive=True)
|
122 |
analyze_button = gr.Button("๋ถ์ ์์", elem_classes="gradio-button")
|
123 |
-
|
|
|
124 |
|
125 |
with gr.Column(scale=2, min_width=500):
|
126 |
gr.Markdown("<h3 style='color: #34495e;'>2. ๋ถ์ ๊ฒฐ๊ณผ ๋ฐ ์๊ฐํ</h3>")
|
127 |
chart_output = gr.Plot(label="์๊ฐํ ์ฐจํธ")
|
128 |
-
csv_download = gr.File(label="์ถ์ฒ ๊ฒฐ๊ณผ ๋ค์ด๋ก๋")
|
129 |
|
130 |
-
|
|
|
131 |
|
132 |
# Gradio ์ธํฐํ์ด์ค ์คํ
|
133 |
demo.launch()
|
|
|
6 |
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')
|
13 |
+
|
14 |
+
# ๋๋๋ฐ๋ฅธ๊ณ ๋ ํฐํธ ์ค์
|
15 |
+
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):
|
|
|
59 |
|
60 |
return None, employee_cols, program_cols
|
61 |
|
62 |
+
# ์ง์ ๋ฐ์ดํฐ๋ฅผ ๋ถ์ํ์ฌ ๊ต์ก ํ๋ก๊ทธ๋จ์ ์ถ์ฒํ๊ณ , ํ
์ด๋ธ๊ณผ ๊ทธ๋ํ๋ฅผ ์์ฑํ๋ ํจ์
|
63 |
def analyze_data(employee_file, program_file):
|
64 |
employee_df = pd.read_csv(employee_file.name)
|
65 |
program_df = pd.read_csv(program_file.name)
|
66 |
|
67 |
error_msg, employee_cols, program_cols = validate_and_get_columns(employee_df, program_df)
|
68 |
if error_msg:
|
69 |
+
return error_msg, None, None, None
|
70 |
|
71 |
employee_skills = employee_df[employee_cols["current_skills"]].tolist()
|
72 |
program_skills = program_df[program_cols["skills_acquired"]].tolist()
|
|
|
76 |
similarities = cosine_similarity(employee_embeddings, program_embeddings)
|
77 |
|
78 |
recommendations = []
|
79 |
+
recommendation_rows = [] # ํ
์ด๋ธ ๋ฐ CSV๋ก ์ ์ฅํ ๋ฐ์ดํฐ
|
80 |
for i, employee in employee_df.iterrows():
|
81 |
recommended_programs = []
|
82 |
for j, program in program_df.iterrows():
|
|
|
106 |
|
107 |
plt.figure(figsize=(10, 8))
|
108 |
pos = nx.spring_layout(G)
|
109 |
+
nx.draw(G, pos, with_labels=True, node_color='lightblue', node_size=3000, font_size=10, font_weight='bold', edge_color='gray', fontproperties=fontprop)
|
110 |
+
plt.title("์ง์๊ณผ ํ๋ก๊ทธ๋จ ๊ฐ์ ๊ด๊ณ", fontsize=14, fontweight='bold', fontproperties=fontprop)
|
111 |
plt.tight_layout()
|
112 |
|
113 |
# CSV ํ์ผ๋ก ์ถ์ฒ ๊ฒฐ๊ณผ ๋ฐํ
|
114 |
csv_output = save_recommendations_to_file(recommendation_rows)
|
115 |
|
116 |
+
# ๊ฒฐ๊ณผ ํ
์ด๋ธ ๋ฐ์ดํฐํ๋ ์ ์์ฑ
|
117 |
+
result_df = pd.DataFrame(recommendation_rows, columns=["Employee ID", "Employee Name", "Recommended Programs"])
|
118 |
+
|
119 |
+
return result_df, plt.gcf(), csv_output
|
120 |
|
121 |
# Gradio ๋ธ๋ก
|
122 |
with gr.Blocks(css=".gradio-button {background-color: #007bff; color: white;} .gradio-textbox {border-color: #6c757d;}") as demo:
|
|
|
128 |
employee_file = gr.File(label="์ง์ ๋ฐ์ดํฐ ์
๋ก๋", interactive=True)
|
129 |
program_file = gr.File(label="๊ต์ก ํ๋ก๊ทธ๋จ ๋ฐ์ดํฐ ์
๋ก๋", interactive=True)
|
130 |
analyze_button = gr.Button("๋ถ์ ์์", elem_classes="gradio-button")
|
131 |
+
output_table = gr.DataFrame(label="๋ถ์ ๊ฒฐ๊ณผ (ํ
์ด๋ธ)")
|
132 |
+
csv_download = gr.File(label="์ถ์ฒ ๊ฒฐ๊ณผ ๋ค์ด๋ก๋")
|
133 |
|
134 |
with gr.Column(scale=2, min_width=500):
|
135 |
gr.Markdown("<h3 style='color: #34495e;'>2. ๋ถ์ ๊ฒฐ๊ณผ ๋ฐ ์๊ฐํ</h3>")
|
136 |
chart_output = gr.Plot(label="์๊ฐํ ์ฐจํธ")
|
|
|
137 |
|
138 |
+
# ๋ถ์ ๋ฒํผ ํด๋ฆญ ์ ํ
์ด๋ธ, ์ฐจํธ, ํ์ผ ๋ค์ด๋ก๋๋ฅผ ์
๋ฐ์ดํธ
|
139 |
+
analyze_button.click(analyze_data, inputs=[employee_file, program_file], outputs=[output_table, chart_output, csv_download])
|
140 |
|
141 |
# Gradio ์ธํฐํ์ด์ค ์คํ
|
142 |
demo.launch()
|