Spaces:
Sleeping
Sleeping
soojeongcrystal
commited on
Commit
โข
7a733b2
1
Parent(s):
702c25c
Update app.py
Browse files
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 |
-
|
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(
|
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])
|