soojeongcrystal commited on
Commit
afea222
โ€ข
1 Parent(s): 160f223

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -5
app.py CHANGED
@@ -14,9 +14,10 @@ model = SentenceTransformer('jhgan/ko-sbert-sts')
14
  # ๋‚˜๋ˆ”๋ฐ”๋ฅธ๊ณ ๋”• ํฐํŠธ ์„ค์ • (ํ—ˆ๊น…ํŽ˜์ด์Šค ํ™˜๊ฒฝ์— ๋งž๊ฒŒ ์ˆ˜์ •)
15
  plt.rc('font', family='NanumBarunGothic')
16
 
17
- # Neo4j ๊ด€๋ จ ์ฝ”๋“œ ์ œ๊ฑฐ (ํ—ˆ๊น…ํŽ˜์ด์Šค ํ™˜๊ฒฝ์—์„œ๋Š” ์‚ฌ์šฉํ•˜๊ธฐ ์–ด๋ ค์›€)
 
18
 
19
- # ์ถ”์ฒœ ๊ฒฐ๊ณผ๋ฅผ CSV ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜
20
  def recommendations_to_csv(recommendations):
21
  output = io.StringIO()
22
  writer = csv.writer(output)
@@ -24,7 +25,7 @@ def recommendations_to_csv(recommendations):
24
  writer.writerows(recommendations)
25
  return output.getvalue()
26
 
27
- # ์ž๋™์œผ๋กœ ์—ด์„ ๋งค์นญํ•˜๋Š” ํ•จ์ˆ˜
28
  def auto_match_columns(df, required_cols):
29
  matched_cols = {}
30
  for req_col in required_cols:
@@ -36,7 +37,7 @@ def auto_match_columns(df, required_cols):
36
  matched_cols[req_col] = matched_col
37
  return matched_cols
38
 
39
- # ์ง์› ๋ฐ ํ”„๋กœ๊ทธ๋žจ ๋ฐ์ดํ„ฐ์˜ ์—ด์„ ์ž๋™์œผ๋กœ ๋งค์นญํ•˜๊ฑฐ๋‚˜, ์„ ํƒํ•˜๊ฒŒ ํ•˜๋Š” ํ•จ์ˆ˜
40
  def validate_and_get_columns(employee_df, program_df):
41
  required_employee_cols = ["employee_id", "employee_name", "current_skills"]
42
  required_program_cols = ["program_name", "skills_acquired", "duration"]
@@ -56,6 +57,8 @@ def validate_and_get_columns(employee_df, program_df):
56
 
57
  # ์ง์› ๋ฐ์ดํ„ฐ๋ฅผ ๋ถ„์„ํ•˜์—ฌ ๊ต์œก ํ”„๋กœ๊ทธ๋žจ์„ ์ถ”์ฒœํ•˜๊ณ , ํ…Œ์ด๋ธ”๊ณผ ๊ทธ๋ž˜ํ”„๋ฅผ ์ƒ์„ฑํ•˜๋Š” ํ•จ์ˆ˜
58
  def hybrid_rag(employee_file, program_file):
 
 
59
  # 1. VectorRAG: KoSentence-BERT๋ฅผ ์ด์šฉํ•œ ์œ ์‚ฌ๋„ ๊ณ„์‚ฐ
60
  employee_df = pd.read_csv(employee_file.name)
61
  program_df = pd.read_csv(program_file.name)
@@ -88,7 +91,7 @@ def hybrid_rag(employee_file, program_file):
88
 
89
  recommendations.append(recommendation)
90
 
91
- # GraphRAG ๋ถ€๋ถ„ ์ œ๊ฑฐ (Neo4j ์‚ฌ์šฉ ๋ถˆ๊ฐ€)
92
 
93
  G = nx.Graph()
94
  for employee in employee_df[employee_cols['employee_name']]:
@@ -116,6 +119,18 @@ def hybrid_rag(employee_file, program_file):
116
 
117
  return result_df, plt.gcf(), csv_output
118
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  # Gradio ๋ธ”๋ก
120
  with gr.Blocks(css=".gradio-button {background-color: #007bff; color: white;} .gradio-textbox {border-color: #6c757d;}") as demo:
121
  gr.Markdown("<h1 style='text-align: center; color: #2c3e50;'>๐Ÿ’ผ HybridRAG ์‹œ์Šคํ…œ</h1>")
@@ -133,7 +148,16 @@ with gr.Blocks(css=".gradio-button {background-color: #007bff; color: white;} .g
133
  gr.Markdown("<h3 style='color: #34495e;'>2. ๋ถ„์„ ๊ฒฐ๊ณผ ๋ฐ ์‹œ๊ฐํ™”</h3>")
134
  chart_output = gr.Plot(label="์‹œ๊ฐํ™” ์ฐจํŠธ")
135
 
 
 
 
 
 
136
  # ๋ถ„์„ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ํ…Œ์ด๋ธ”, ์ฐจํŠธ, ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ๋ฅผ ์—…๋ฐ์ดํŠธ
137
  analyze_button.click(hybrid_rag, inputs=[employee_file, program_file], outputs=[output_table, chart_output, csv_download])
138
 
 
 
 
 
139
  demo.launch()
 
14
  # ๋‚˜๋ˆ”๋ฐ”๋ฅธ๊ณ ๋”• ํฐํŠธ ์„ค์ • (ํ—ˆ๊น…ํŽ˜์ด์Šค ํ™˜๊ฒฝ์— ๋งž๊ฒŒ ์ˆ˜์ •)
15
  plt.rc('font', family='NanumBarunGothic')
16
 
17
+ # ์ „์—ญ ๋ณ€์ˆ˜๋กœ ๋ถ„์„ ๊ฒฐ๊ณผ ์ €์žฅ
18
+ global_recommendations = None
19
 
20
+ # CSV ๋ฌธ์ž์—ด ์ƒ์„ฑ ํ•จ์ˆ˜
21
  def recommendations_to_csv(recommendations):
22
  output = io.StringIO()
23
  writer = csv.writer(output)
 
25
  writer.writerows(recommendations)
26
  return output.getvalue()
27
 
28
+ # ์—ด ๋งค์นญ ํ•จ์ˆ˜
29
  def auto_match_columns(df, required_cols):
30
  matched_cols = {}
31
  for req_col in required_cols:
 
37
  matched_cols[req_col] = matched_col
38
  return matched_cols
39
 
40
+ # ์—ด ๊ฒ€์ฆ ํ•จ์ˆ˜
41
  def validate_and_get_columns(employee_df, program_df):
42
  required_employee_cols = ["employee_id", "employee_name", "current_skills"]
43
  required_program_cols = ["program_name", "skills_acquired", "duration"]
 
57
 
58
  # ์ง์› ๋ฐ์ดํ„ฐ๋ฅผ ๋ถ„์„ํ•˜์—ฌ ๊ต์œก ํ”„๋กœ๊ทธ๋žจ์„ ์ถ”์ฒœํ•˜๊ณ , ํ…Œ์ด๋ธ”๊ณผ ๊ทธ๋ž˜ํ”„๋ฅผ ์ƒ์„ฑํ•˜๋Š” ํ•จ์ˆ˜
59
  def hybrid_rag(employee_file, program_file):
60
+ global global_recommendations
61
+
62
  # 1. VectorRAG: KoSentence-BERT๋ฅผ ์ด์šฉํ•œ ์œ ์‚ฌ๋„ ๊ณ„์‚ฐ
63
  employee_df = pd.read_csv(employee_file.name)
64
  program_df = pd.read_csv(program_file.name)
 
91
 
92
  recommendations.append(recommendation)
93
 
94
+ global_recommendations = recommendation_rows
95
 
96
  G = nx.Graph()
97
  for employee in employee_df[employee_cols['employee_name']]:
 
119
 
120
  return result_df, plt.gcf(), csv_output
121
 
122
+ # ์ฑ„ํŒ… ์‘๋‹ต ํ•จ์ˆ˜
123
+ def chat_response(message, history):
124
+ global global_recommendations
125
+ if global_recommendations is None:
126
+ return "๋จผ์ € '๋ถ„์„ ์‹œ์ž‘' ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ๋ฐ์ดํ„ฐ๋ฅผ ๋ถ„์„ํ•ด์ฃผ์„ธ์š”."
127
+
128
+ for employee in global_recommendations:
129
+ if employee[1].lower() in message.lower():
130
+ return f"{employee[1]}๋‹˜์—๊ฒŒ ์ถ”์ฒœ๋œ ํ”„๋กœ๊ทธ๋žจ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค: {employee[2]}"
131
+
132
+ return "์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค. ํ•ด๋‹น ์ง์›์˜ ์ •๋ณด๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ์ง์› ์ด๋ฆ„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
133
+
134
  # Gradio ๋ธ”๋ก
135
  with gr.Blocks(css=".gradio-button {background-color: #007bff; color: white;} .gradio-textbox {border-color: #6c757d;}") as demo:
136
  gr.Markdown("<h1 style='text-align: center; color: #2c3e50;'>๐Ÿ’ผ HybridRAG ์‹œ์Šคํ…œ</h1>")
 
148
  gr.Markdown("<h3 style='color: #34495e;'>2. ๋ถ„์„ ๊ฒฐ๊ณผ ๋ฐ ์‹œ๊ฐํ™”</h3>")
149
  chart_output = gr.Plot(label="์‹œ๊ฐํ™” ์ฐจํŠธ")
150
 
151
+ gr.Markdown("<h3 style='color: #34495e;'>3. ์ง์›๋ณ„ ์ถ”์ฒœ ํ”„๋กœ๊ทธ๋žจ ํ™•์ธ</h3>")
152
+ chatbot = gr.Chatbot()
153
+ msg = gr.Textbox(label="์ง์› ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”")
154
+ clear = gr.Button("๋Œ€ํ™” ๋‚ด์—ญ ์ง€์šฐ๊ธฐ")
155
+
156
  # ๋ถ„์„ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ํ…Œ์ด๋ธ”, ์ฐจํŠธ, ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ๋ฅผ ์—…๋ฐ์ดํŠธ
157
  analyze_button.click(hybrid_rag, inputs=[employee_file, program_file], outputs=[output_table, chart_output, csv_download])
158
 
159
+ # ์ฑ„ํŒ… ๊ธฐ๋Šฅ
160
+ msg.submit(chat_response, [msg, chatbot], [chatbot])
161
+ clear.click(lambda: None, None, chatbot, queue=False)
162
+
163
  demo.launch()