soojeongcrystal commited on
Commit
7a733b2
โ€ข
1 Parent(s): 702c25c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -14
app.py CHANGED
@@ -12,7 +12,9 @@ from datetime import datetime, timedelta
12
  # ํ•œ๊ตญ์–ด ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ KoSentence-BERT ๋ชจ๋ธ ๋กœ๋“œ
13
  model = SentenceTransformer('jhgan/ko-sbert-sts')
14
 
15
- # ๋‚˜๋ˆ”๋ฐ”๋ฅธ๊ณ ๋”• ํฐํŠธ ์„ค์ • (ํ—ˆ๊น…ํŽ˜์ด์Šค ํ™˜๊ฒฝ์— ๋งž๊ฒŒ ์ˆ˜์ •)
 
 
16
  plt.rc('font', family='NanumBarunGothic')
17
 
18
  # ์ „์—ญ ๋ณ€์ˆ˜
@@ -73,6 +75,7 @@ def validate_and_get_columns(employee_df, program_df):
73
 
74
  return None, employee_cols, program_cols
75
 
 
76
  def select_youtube_columns(youtube_file):
77
  global youtube_columns
78
  youtube_df = pd.read_csv(youtube_file.name)
@@ -93,7 +96,6 @@ def load_youtube_content(file_path, title_col, description_col, url_col, upload_
93
  selected_columns = [col for col in [title_col, description_col, url_col, upload_date_col] if col]
94
  youtube_df = youtube_df[selected_columns]
95
 
96
- # ์„ ํƒ๋œ ์—ด ์ด๋ฆ„์„ ํ•„์š”ํ•œ ์—ด ์ด๋ฆ„์œผ๋กœ ๋งคํ•‘
97
  column_mapping = {
98
  title_col: 'title',
99
  description_col: 'description',
@@ -127,7 +129,7 @@ def hybrid_rag(employee_file, program_file, youtube_file, title_col, description
127
 
128
  error_msg, employee_cols, program_cols = validate_and_get_columns(employee_df, program_df)
129
  if error_msg:
130
- return error_msg, None, None
131
 
132
  employee_skills = employee_df[employee_cols["current_skills"]].tolist()
133
  program_skills = program_df[program_cols["skills_acquired"]].tolist()
@@ -151,7 +153,6 @@ def hybrid_rag(employee_file, program_file, youtube_file, title_col, description
151
  if similarities[i][j] > 0.5:
152
  recommended_programs.append(f"{program[program_cols['program_name']]} ({program[program_cols['duration']]})")
153
 
154
- # ํ•ด๋‹น ํ”„๋กœ๊ทธ๋žจ๊ณผ ๊ฐ€์žฅ ์œ ์‚ฌํ•œ ์œ ํŠœ๋ธŒ ์ฝ˜ํ…์ธ  ์ฐพ๊ธฐ
155
  if youtube_similarities is not None:
156
  top_youtube_indices = youtube_similarities[j].argsort()[-3:][::-1] # ์ƒ์œ„ 3๊ฐœ
157
  for idx in top_youtube_indices:
@@ -194,7 +195,7 @@ def hybrid_rag(employee_file, program_file, youtube_file, title_col, description
194
  # ๊ฒฐ๊ณผ ํ…Œ์ด๋ธ” ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„ ์ƒ์„ฑ
195
  result_df = pd.DataFrame(recommendation_rows, columns=["Employee ID", "Employee Name", "Recommended Programs", "Recommended YouTube Content"])
196
 
197
- return result_df, chart_buffer, gr.File.update(visible=True)
198
 
199
  # ์ฑ„ํŒ… ์‘๋‹ต ํ•จ์ˆ˜
200
  def chat_response(message, history):
@@ -208,13 +209,6 @@ def chat_response(message, history):
208
 
209
  return "์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค. ํ•ด๋‹น ์ง์›์˜ ์ •๋ณด๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ์ง์› ์ด๋ฆ„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
210
 
211
- # CSV ๋‹ค์šด๋กœ๋“œ ํ•จ์ˆ˜
212
- def download_csv():
213
- global global_csv_string
214
- if global_csv_string is None:
215
- return gr.File.update(visible=False)
216
- return gr.File.update(value=global_csv_string, visible=True, filename="recommendations.csv")
217
-
218
  # Gradio ๋ธ”๋ก
219
  with gr.Blocks(css=".gradio-button {background-color: #007bff; color: white;} .gradio-textbox {border-color: #6c757d;}") as demo:
220
  gr.Markdown("<h1 style='text-align: center; color: #2c3e50;'>๐Ÿ’ผ HybridRAG ์‹œ์Šคํ…œ (์œ ํŠœ๋ธŒ ์ฝ˜ํ…์ธ  ํฌํ•จ)</h1>")
@@ -249,14 +243,14 @@ with gr.Blocks(css=".gradio-button {background-color: #007bff; color: white;} .g
249
  clear = gr.Button("๋Œ€ํ™” ๋‚ด์—ญ ์ง€์šฐ๊ธฐ")
250
 
251
  # ๋ถ„์„ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ํ…Œ์ด๋ธ”, ์ฐจํŠธ, ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ๋ฅผ ์—…๋ฐ์ดํŠธ
252
- analyze_result = analyze_button.click(
253
  hybrid_rag,
254
  inputs=[employee_file, program_file, youtube_file, title_col, description_col, url_col, upload_date_col],
255
  outputs=[output_table, chart_output, csv_download, download_button]
256
  )
257
 
258
  # CSV ๋‹ค์šด๋กœ๋“œ ๋ฒ„ํŠผ
259
- download_button.click(download_csv, inputs=[], outputs=[csv_download])
260
 
261
  # ์ฑ„ํŒ… ๊ธฐ๋Šฅ
262
  msg.submit(chat_response, [msg, chatbot], [chatbot])
 
12
  # ํ•œ๊ตญ์–ด ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ KoSentence-BERT ๋ชจ๋ธ ๋กœ๋“œ
13
  model = SentenceTransformer('jhgan/ko-sbert-sts')
14
 
15
+ # ๋‚˜๋ˆ”๋ฐ”๋ฅธ๊ณ ๋”• ํฐํŠธ ์„ค์ •
16
+ font_path = "./NanumBarunGothic.ttf"
17
+ fm.fontManager.addfont(font_path)
18
  plt.rc('font', family='NanumBarunGothic')
19
 
20
  # ์ „์—ญ ๋ณ€์ˆ˜
 
75
 
76
  return None, employee_cols, program_cols
77
 
78
+ # ์œ ํŠœ๋ธŒ ๋ฐ์ดํ„ฐ ์—ด ์„ ํƒ ํ•จ์ˆ˜
79
  def select_youtube_columns(youtube_file):
80
  global youtube_columns
81
  youtube_df = pd.read_csv(youtube_file.name)
 
96
  selected_columns = [col for col in [title_col, description_col, url_col, upload_date_col] if col]
97
  youtube_df = youtube_df[selected_columns]
98
 
 
99
  column_mapping = {
100
  title_col: 'title',
101
  description_col: 'description',
 
129
 
130
  error_msg, employee_cols, program_cols = validate_and_get_columns(employee_df, program_df)
131
  if error_msg:
132
+ return error_msg, None, None, None
133
 
134
  employee_skills = employee_df[employee_cols["current_skills"]].tolist()
135
  program_skills = program_df[program_cols["skills_acquired"]].tolist()
 
153
  if similarities[i][j] > 0.5:
154
  recommended_programs.append(f"{program[program_cols['program_name']]} ({program[program_cols['duration']]})")
155
 
 
156
  if youtube_similarities is not None:
157
  top_youtube_indices = youtube_similarities[j].argsort()[-3:][::-1] # ์ƒ์œ„ 3๊ฐœ
158
  for idx in top_youtube_indices:
 
195
  # ๊ฒฐ๊ณผ ํ…Œ์ด๋ธ” ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„ ์ƒ์„ฑ
196
  result_df = pd.DataFrame(recommendation_rows, columns=["Employee ID", "Employee Name", "Recommended Programs", "Recommended YouTube Content"])
197
 
198
+ return result_df, chart_buffer, gr.File(value=global_csv_string, visible=True, filename="recommendations.csv"), gr.Button.update(visible=True)
199
 
200
  # ์ฑ„ํŒ… ์‘๋‹ต ํ•จ์ˆ˜
201
  def chat_response(message, history):
 
209
 
210
  return "์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค. ํ•ด๋‹น ์ง์›์˜ ์ •๋ณด๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ์ง์› ์ด๋ฆ„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
211
 
 
 
 
 
 
 
 
212
  # Gradio ๋ธ”๋ก
213
  with gr.Blocks(css=".gradio-button {background-color: #007bff; color: white;} .gradio-textbox {border-color: #6c757d;}") as demo:
214
  gr.Markdown("<h1 style='text-align: center; color: #2c3e50;'>๐Ÿ’ผ HybridRAG ์‹œ์Šคํ…œ (์œ ํŠœ๋ธŒ ์ฝ˜ํ…์ธ  ํฌํ•จ)</h1>")
 
243
  clear = gr.Button("๋Œ€ํ™” ๋‚ด์—ญ ์ง€์šฐ๊ธฐ")
244
 
245
  # ๋ถ„์„ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ํ…Œ์ด๋ธ”, ์ฐจํŠธ, ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ๋ฅผ ์—…๋ฐ์ดํŠธ
246
+ analyze_button.click(
247
  hybrid_rag,
248
  inputs=[employee_file, program_file, youtube_file, title_col, description_col, url_col, upload_date_col],
249
  outputs=[output_table, chart_output, csv_download, download_button]
250
  )
251
 
252
  # CSV ๋‹ค์šด๋กœ๋“œ ๋ฒ„ํŠผ
253
+ download_button.click(lambda: gr.File(value=global_csv_string, visible=True, filename="recommendations.csv"), inputs=[], outputs=[csv_download])
254
 
255
  # ์ฑ„ํŒ… ๊ธฐ๋Šฅ
256
  msg.submit(chat_response, [msg, chatbot], [chatbot])