soojeongcrystal commited on
Commit
3db0045
โ€ข
1 Parent(s): 14a8a48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -18
app.py CHANGED
@@ -1,23 +1,34 @@
1
  import gradio as gr
2
  import pandas as pd
 
 
 
3
  import matplotlib.pyplot as plt
4
 
5
- # ์ง์› ๋ฐ์ดํ„ฐ๋ฅผ ๋ถ„์„ํ•˜์—ฌ ๊ต์œก ํ”„๋กœ๊ทธ๋žจ์„ ์ถ”์ฒœํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ์‹œ๊ฐํ™”ํ•˜๋Š” ํ•จ์ˆ˜
 
 
 
6
  def analyze_data(employee_file, program_file):
7
  # ์ง์› ๋ฐ์ดํ„ฐ์™€ ๊ต์œก ํ”„๋กœ๊ทธ๋žจ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
8
  employee_df = pd.read_csv(employee_file.name)
9
  program_df = pd.read_csv(program_file.name)
10
 
 
 
 
 
 
 
 
 
 
11
  # ์ง์›๋ณ„ ์ถ”์ฒœ ํ”„๋กœ๊ทธ๋žจ ๋ฆฌ์ŠคํŠธ
12
  recommendations = []
13
-
14
- for _, employee in employee_df.iterrows():
15
  recommended_programs = []
16
-
17
- for _, program in program_df.iterrows():
18
- # ์ง์›์˜ ํ˜„์žฌ ์—ญ๋Ÿ‰๊ณผ ํ•™์Šต ๋ชฉํ‘œ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์ ํ•ฉํ•œ ํ”„๋กœ๊ทธ๋žจ์„ ์ถ”์ฒœ
19
- if any(skill in program['skills_acquired'] for skill in employee['current_skills'].split(',')) or \
20
- employee['learning_goal'] in program['learning_objectives']:
21
  recommended_programs.append(f"{program['program_name']} ({program['duration']})")
22
 
23
  if recommended_programs:
@@ -27,26 +38,36 @@ def analyze_data(employee_file, program_file):
27
 
28
  recommendations.append(recommendation)
29
 
30
- # ๊ฒฐ๊ณผ๋ฅผ ํ…์ŠคํŠธ๋กœ ๋ฐ˜ํ™˜
31
  result_text = "\n".join(recommendations)
32
 
33
- # ์‹œ๊ฐํ™”์šฉ ์ฐจํŠธ ์ƒ์„ฑ
34
- plt.figure(figsize=(8, 4))
35
- employee_roles = employee_df['current_role'].value_counts()
36
- employee_roles.plot(kind='bar', color='skyblue')
37
- plt.title('์ง์›๋ณ„ ํ˜„์žฌ ์ง๋ฌด ๋ถ„ํฌ')
38
- plt.xlabel('์ง๋ฌด')
39
- plt.ylabel('์ง์› ์ˆ˜')
40
 
41
- # ์ฐจํŠธ๋ฅผ ๋ฐ˜ํ™˜
 
 
 
 
 
 
 
 
 
 
 
 
42
  plt.tight_layout()
 
43
  return result_text, plt.gcf()
44
 
45
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
46
  def main(employee_file, program_file):
47
  return analyze_data(employee_file, program_file)
48
 
49
- # ์‚ฌ์ด๋“œ๋ฐ”์—์„œ ํŒŒ์ผ ์—…๋กœ๋“œ ๊ธฐ๋Šฅ ๊ตฌํ˜„
50
  with gr.Blocks() as demo:
51
  with gr.Row():
52
  with gr.Column(scale=1):
 
1
  import gradio as gr
2
  import pandas as pd
3
+ from sentence_transformers import SentenceTransformer
4
+ from sklearn.metrics.pairwise import cosine_similarity
5
+ import networkx as nx
6
  import matplotlib.pyplot as plt
7
 
8
+ # Sentence-BERT ๋ชจ๋ธ ๋กœ๋“œ
9
+ model = SentenceTransformer('all-MiniLM-L6-v2')
10
+
11
+ # ์ง์› ๋ฐ์ดํ„ฐ๋ฅผ ๋ถ„์„ํ•˜์—ฌ ๊ต์œก ํ”„๋กœ๊ทธ๋žจ์„ ์ถ”์ฒœํ•˜๊ณ  ๊ทธ๋ž˜ํ”„๋ฅผ ๊ทธ๋ฆฌ๋Š” ํ•จ์ˆ˜
12
  def analyze_data(employee_file, program_file):
13
  # ์ง์› ๋ฐ์ดํ„ฐ์™€ ๊ต์œก ํ”„๋กœ๊ทธ๋žจ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
14
  employee_df = pd.read_csv(employee_file.name)
15
  program_df = pd.read_csv(program_file.name)
16
 
17
+ # ์ง์› ์—ญ๋Ÿ‰๊ณผ ํ”„๋กœ๊ทธ๋žจ ํ•™์Šต ๋ชฉํ‘œ๋ฅผ ๋ฒกํ„ฐํ™”
18
+ employee_skills = employee_df['current_skills'].tolist()
19
+ program_skills = program_df['skills_acquired'].tolist()
20
+ employee_embeddings = model.encode(employee_skills)
21
+ program_embeddings = model.encode(program_skills)
22
+
23
+ # ์œ ์‚ฌ๋„ ๊ณ„์‚ฐ
24
+ similarities = cosine_similarity(employee_embeddings, program_embeddings)
25
+
26
  # ์ง์›๋ณ„ ์ถ”์ฒœ ํ”„๋กœ๊ทธ๋žจ ๋ฆฌ์ŠคํŠธ
27
  recommendations = []
28
+ for i, employee in employee_df.iterrows():
 
29
  recommended_programs = []
30
+ for j, program in program_df.iterrows():
31
+ if similarities[i][j] > 0.5: # ์œ ์‚ฌ๋„ ์ž„๊ณ„๊ฐ’ ๊ธฐ์ค€
 
 
 
32
  recommended_programs.append(f"{program['program_name']} ({program['duration']})")
33
 
34
  if recommended_programs:
 
38
 
39
  recommendations.append(recommendation)
40
 
41
+ # ๊ฒฐ๊ณผ ํ…์ŠคํŠธ
42
  result_text = "\n".join(recommendations)
43
 
44
+ # ๋„คํŠธ์›Œํฌ ๊ทธ๋ž˜ํ”„ ์ƒ์„ฑ
45
+ G = nx.Graph()
46
+ for employee in employee_df['employee_name']:
47
+ G.add_node(employee, type='employee')
 
 
 
48
 
49
+ for program in program_df['program_name']:
50
+ G.add_node(program, type='program')
51
+
52
+ for i, employee in employee_df.iterrows():
53
+ for j, program in program_df.iterrows():
54
+ if similarities[i][j] > 0.5: # ์œ ์‚ฌ๋„ ์ž„๊ณ„๊ฐ’
55
+ G.add_edge(employee['employee_name'], program['program_name'])
56
+
57
+ # ๊ทธ๋ž˜ํ”„ ์‹œ๊ฐํ™”
58
+ plt.figure(figsize=(10, 8))
59
+ pos = nx.spring_layout(G)
60
+ nx.draw(G, pos, with_labels=True, node_color='skyblue', node_size=2000, font_size=10, font_weight='bold')
61
+ plt.title("์ง์›๊ณผ ํ”„๋กœ๊ทธ๋žจ ๊ฐ„์˜ ๊ด€๊ณ„")
62
  plt.tight_layout()
63
+
64
  return result_text, plt.gcf()
65
 
66
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
67
  def main(employee_file, program_file):
68
  return analyze_data(employee_file, program_file)
69
 
70
+ # Gradio ๋ธ”๋ก
71
  with gr.Blocks() as demo:
72
  with gr.Row():
73
  with gr.Column(scale=1):