Spaces:
Sleeping
Sleeping
soojeongcrystal
commited on
Commit
โข
afea222
1
Parent(s):
160f223
Update app.py
Browse files
app.py
CHANGED
@@ -14,9 +14,10 @@ model = SentenceTransformer('jhgan/ko-sbert-sts')
|
|
14 |
# ๋๋๋ฐ๋ฅธ๊ณ ๋ ํฐํธ ์ค์ (ํ๊น
ํ์ด์ค ํ๊ฒฝ์ ๋ง๊ฒ ์์ )
|
15 |
plt.rc('font', family='NanumBarunGothic')
|
16 |
|
17 |
-
#
|
|
|
18 |
|
19 |
-
#
|
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 |
-
|
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()
|