soojeongcrystal commited on
Commit
9b227e3
โ€ข
1 Parent(s): 2e6bb20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -12
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 os
10
 
11
- # Sentence-BERT ๋ชจ๋ธ ๋กœ๋“œ
12
- model = SentenceTransformer('all-MiniLM-L6-v2')
 
 
 
 
 
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
- return "\n".join(recommendations), plt.gcf(), csv_output
 
 
 
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
- output_text = gr.Textbox(label="๋ถ„์„ ๊ฒฐ๊ณผ", interactive=False, elem_classes="gradio-textbox")
 
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
- analyze_button.click(analyze_data, inputs=[employee_file, program_file], outputs=[output_text, chart_output, csv_download])
 
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()