soojeongcrystal commited on
Commit
6532346
ยท
verified ยท
1 Parent(s): 1755487

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -36
app.py CHANGED
@@ -19,25 +19,21 @@ def log_recommendation(employee_name, recommended_programs, feedback=None):
19
 
20
  # ์ง์› ๋ฐ์ดํ„ฐ๋ฅผ ๋ถ„์„ํ•˜์—ฌ ๊ต์œก ํ”„๋กœ๊ทธ๋žจ์„ ์ถ”์ฒœํ•˜๊ณ  ๊ทธ๋ž˜ํ”„๋ฅผ ๊ทธ๋ฆฌ๋Š” ํ•จ์ˆ˜
21
  def analyze_data(employee_file, program_file, feedback=None):
22
- # ์ง์› ๋ฐ์ดํ„ฐ์™€ ๊ต์œก ํ”„๋กœ๊ทธ๋žจ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
23
  employee_df = pd.read_csv(employee_file.name)
24
  program_df = pd.read_csv(program_file.name)
25
 
26
- # ์ง์› ์—ญ๋Ÿ‰๊ณผ ํ”„๋กœ๊ทธ๋žจ ํ•™์Šต ๋ชฉํ‘œ๋ฅผ ๋ฒกํ„ฐํ™”
27
  employee_skills = employee_df['current_skills'].tolist()
28
  program_skills = program_df['skills_acquired'].tolist()
29
  employee_embeddings = model.encode(employee_skills)
30
  program_embeddings = model.encode(program_skills)
31
 
32
- # ์œ ์‚ฌ๋„ ๊ณ„์‚ฐ
33
  similarities = cosine_similarity(employee_embeddings, program_embeddings)
34
 
35
- # ์ง์›๋ณ„ ์ถ”์ฒœ ํ”„๋กœ๊ทธ๋žจ ๋ฆฌ์ŠคํŠธ
36
  recommendations = []
37
  for i, employee in employee_df.iterrows():
38
  recommended_programs = []
39
  for j, program in program_df.iterrows():
40
- if similarities[i][j] > 0.5: # ์œ ์‚ฌ๋„ ์ž„๊ณ„๊ฐ’ ๊ธฐ์ค€
41
  recommended_programs.append(f"{program['program_name']} ({program['duration']})")
42
 
43
  if recommended_programs:
@@ -45,15 +41,12 @@ def analyze_data(employee_file, program_file, feedback=None):
45
  else:
46
  recommendation = f"์ง์› {employee['employee_name']}์—๊ฒŒ ์ ํ•ฉํ•œ ํ”„๋กœ๊ทธ๋žจ์ด ์—†์Šต๋‹ˆ๋‹ค."
47
 
48
- # ํ”ผ๋“œ๋ฐฑ ๋กœ๊ทธ ๊ธฐ๋ก
49
  log_recommendation(employee['employee_name'], recommended_programs, feedback)
50
 
51
  recommendations.append(recommendation)
52
 
53
- # ๊ฒฐ๊ณผ ํ…์ŠคํŠธ
54
  result_text = "\n".join(recommendations)
55
 
56
- # ๋„คํŠธ์›Œํฌ ๊ทธ๋ž˜ํ”„ ์ƒ์„ฑ
57
  G = nx.Graph()
58
  for employee in employee_df['employee_name']:
59
  G.add_node(employee, type='employee')
@@ -63,10 +56,9 @@ def analyze_data(employee_file, program_file, feedback=None):
63
 
64
  for i, employee in employee_df.iterrows():
65
  for j, program in program_df.iterrows():
66
- if similarities[i][j] > 0.5: # ์œ ์‚ฌ๋„ ์ž„๊ณ„๊ฐ’
67
  G.add_edge(employee['employee_name'], program['program_name'])
68
 
69
- # ๊ทธ๋ž˜ํ”„ ์‹œ๊ฐํ™”
70
  plt.figure(figsize=(10, 8))
71
  pos = nx.spring_layout(G)
72
  nx.draw(G, pos, with_labels=True, node_color='skyblue', node_size=2000, font_size=10, font_weight='bold')
@@ -75,10 +67,6 @@ def analyze_data(employee_file, program_file, feedback=None):
75
 
76
  return result_text, plt.gcf()
77
 
78
- # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
79
- def main(employee_file, program_file, feedback):
80
- return analyze_data(employee_file, program_file, feedback)
81
-
82
  # ์˜ˆ์‹œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ํ•จ์ˆ˜
83
  def show_example_data():
84
  employee_example = pd.DataFrame({
@@ -108,13 +96,31 @@ with gr.Blocks() as demo:
108
  with gr.Row():
109
  with gr.Column(scale=1):
110
  gr.Markdown("# HybridRAG ์‹œ์Šคํ…œ")
111
- gr.Markdown("๋‘ ๊ฐœ์˜ CSV ํŒŒ์ผ์„ ์ขŒ์ธก ์‚ฌ์ด๋“œ๋ฐ”์—์„œ ์—…๋กœ๋“œํ•˜์—ฌ ๋ถ„์„์„ ์ง„ํ–‰ํ•˜์„ธ์š”.")
112
-
113
- # ์‚ฌ์ด๋“œ๋ฐ”์— ํŒŒ์ผ ์—…๋กœ๋“œ ์˜ต์…˜ ์ถ”๊ฐ€
114
- with gr.Sidebar():
115
- employee_file = gr.File(label="์ง์› ๋ฐ์ดํ„ฐ ์—…๋กœ๋“œ")
116
- program_file = gr.File(label="๊ต์œก ํ”„๋กœ๊ทธ๋žจ ๋ฐ์ดํ„ฐ ์—…๋กœ๋“œ")
117
- feedback_input = gr.Radio(choices=["๋งŒ์กฑ", "๋ถˆ๋งŒ์กฑ"], label="์ถ”์ฒœ ๊ฒฐ๊ณผ์— ๋Œ€ํ•œ ํ”ผ๋“œ๋ฐฑ")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
  # ์˜ˆ์‹œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ๋กœ ์ œ๊ณต
120
  example_button = gr.Button("์˜ˆ์‹œ ๋ฐ์ดํ„ฐ ๋ณด๊ธฐ")
@@ -122,20 +128,5 @@ with gr.Blocks() as demo:
122
  program_example_output = gr.DataFrame(label="๊ต์œก ํ”„๋กœ๊ทธ๋žจ ๋ฐ์ดํ„ฐ ์˜ˆ์‹œ")
123
  example_button.click(show_example_data, outputs=[employee_example_output, program_example_output])
124
 
125
- analyze_button = gr.Button("๋ถ„์„ ์‹œ์ž‘")
126
- output_text = gr.Textbox(label="๋ถ„์„ ๊ฒฐ๊ณผ")
127
-
128
- analyze_button.click(main, inputs=[employee_file, program_file, feedback_input], outputs=[output_text])
129
-
130
- with gr.Column(scale=2):
131
- gr.Markdown("### ์ •๋ณด ํŒจ๋„")
132
- gr.Markdown("์—…๋กœ๋“œ๋œ ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•œ ๋ถ„์„ ๋ฐ ๊ฒฐ๊ณผ๋ฅผ ์—ฌ๊ธฐ์— ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.")
133
-
134
- # ์‹œ๊ฐํ™” ์ฐจํŠธ ์ถœ๋ ฅ
135
- chart_output = gr.Plot(label="์‹œ๊ฐํ™” ์ฐจํŠธ")
136
-
137
- # ๋ถ„์„ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ์ฐจํŠธ ์—…๋ฐ์ดํŠธ
138
- analyze_button.click(main, inputs=[employee_file, program_file, feedback_input], outputs=[output_text, chart_output])
139
-
140
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰
141
  demo.launch()
 
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:
 
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
  result_text = "\n".join(recommendations)
49
 
 
50
  G = nx.Graph()
51
  for employee in employee_df['employee_name']:
52
  G.add_node(employee, type='employee')
 
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')
 
67
 
68
  return result_text, plt.gcf()
69
 
 
 
 
 
70
  # ์˜ˆ์‹œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ํ•จ์ˆ˜
71
  def show_example_data():
72
  employee_example = pd.DataFrame({
 
96
  with gr.Row():
97
  with gr.Column(scale=1):
98
  gr.Markdown("# HybridRAG ์‹œ์Šคํ…œ")
99
+
100
+ # ์—ญํ•  ์„ ํƒ (HR vs ์ง์›)
101
+ role = gr.Radio(["HR ๊ด€๋ฆฌ์ž", "์ง์›"], label="์—ญํ• ์„ ์„ ํƒํ•˜์„ธ์š”")
102
+
103
+ # ์—ญํ• ์— ๋”ฐ๋ฅธ ์กฐ๊ฑด ๋ถ„๊ธฐ
104
+ with gr.Tabs() as tabs:
105
+ with gr.Tab("HR ๊ด€๋ฆฌ์ž"):
106
+ with gr.Box(visible=True) as hr_admin_box:
107
+ gr.Markdown("## HR ๊ด€๋ฆฌ์ž ์ธํ„ฐํŽ˜์ด์Šค")
108
+ employee_file = gr.File(label="์ง์› ๋ฐ์ดํ„ฐ ์—…๋กœ๋“œ")
109
+ program_file = gr.File(label="๊ต์œก ํ”„๋กœ๊ทธ๋žจ ๋ฐ์ดํ„ฐ ์—…๋กœ๋“œ")
110
+ analyze_button = gr.Button("๋ถ„์„ ์‹œ์ž‘")
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
  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()