hybridRAG / app.py
soojeongcrystal's picture
Create app.py
1ec6c27 verified
raw
history blame
3.11 kB
import gradio as gr
import pandas as pd
import matplotlib.pyplot as plt
# 직원 데이터λ₯Ό λΆ„μ„ν•˜μ—¬ ꡐ윑 ν”„λ‘œκ·Έλž¨μ„ μΆ”μ²œν•˜κ³  κ²°κ³Όλ₯Ό μ‹œκ°ν™”ν•˜λŠ” ν•¨μˆ˜
def analyze_data(employee_file, program_file):
# 직원 데이터와 ꡐ윑 ν”„λ‘œκ·Έλž¨ 데이터 뢈러였기
employee_df = pd.read_csv(employee_file.name)
program_df = pd.read_csv(program_file.name)
# 직원별 μΆ”μ²œ ν”„λ‘œκ·Έλž¨ 리슀트
recommendations = []
for _, employee in employee_df.iterrows():
recommended_programs = []
for _, program in program_df.iterrows():
# μ§μ›μ˜ ν˜„μž¬ μ—­λŸ‰κ³Ό ν•™μŠ΅ λͺ©ν‘œλ₯Ό 기반으둜 μ ν•©ν•œ ν”„λ‘œκ·Έλž¨μ„ μΆ”μ²œ
if any(skill in program['skills_acquired'] for skill in employee['current_skills'].split(',')) or \
employee['learning_goal'] in program['learning_objectives']:
recommended_programs.append(f"{program['program_name']} ({program['duration']})")
if recommended_programs:
recommendation = f"직원 {employee['employee_name']}의 μΆ”μ²œ ν”„λ‘œκ·Έλž¨: {', '.join(recommended_programs)}"
else:
recommendation = f"직원 {employee['employee_name']}μ—κ²Œ μ ν•©ν•œ ν”„λ‘œκ·Έλž¨μ΄ μ—†μŠ΅λ‹ˆλ‹€."
recommendations.append(recommendation)
# κ²°κ³Όλ₯Ό ν…μŠ€νŠΈλ‘œ λ°˜ν™˜
result_text = "\n".join(recommendations)
# μ‹œκ°ν™”μš© 차트 생성
plt.figure(figsize=(8, 4))
employee_roles = employee_df['current_role'].value_counts()
employee_roles.plot(kind='bar', color='skyblue')
plt.title('직원별 ν˜„μž¬ 직무 뢄포')
plt.xlabel('직무')
plt.ylabel('직원 수')
# 차트λ₯Ό λ°˜ν™˜
plt.tight_layout()
return result_text, plt.gcf()
# Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
def main(employee_file, program_file):
return analyze_data(employee_file, program_file)
# μ‚¬μ΄λ“œλ°”μ—μ„œ 파일 μ—…λ‘œλ“œ κΈ°λŠ₯ κ΅¬ν˜„
with gr.Blocks() as demo:
with gr.Row():
with gr.Column(scale=1):
gr.Markdown("# HybridRAG μ‹œμŠ€ν…œ")
gr.Markdown("두 개의 CSV νŒŒμΌμ„ μ—…λ‘œλ“œν•˜μ—¬ 뢄석을 μ§„ν–‰ν•˜μ„Έμš”.")
employee_file = gr.File(label="직원 데이터 μ—…λ‘œλ“œ")
program_file = gr.File(label="ꡐ윑 ν”„λ‘œκ·Έλž¨ 데이터 μ—…λ‘œλ“œ")
analyze_button = gr.Button("뢄석 μ‹œμž‘")
output_text = gr.Textbox(label="뢄석 κ²°κ³Ό")
analyze_button.click(main, inputs=[employee_file, program_file], outputs=[output_text])
with gr.Column(scale=2):
gr.Markdown("### 정보 νŒ¨λ„")
gr.Markdown("μ—…λ‘œλ“œλœ 데이터에 λŒ€ν•œ 뢄석 및 κ²°κ³Όλ₯Ό 여기에 ν‘œμ‹œν•©λ‹ˆλ‹€.")
# μ‹œκ°ν™” 차트 좜λ ₯
chart_output = gr.Plot(label="μ‹œκ°ν™” 차트")
# 뢄석 λ²„νŠΌ 클릭 μ‹œ 차트 μ—…λ°μ΄νŠΈ
analyze_button.click(main, inputs=[employee_file, program_file], outputs=[output_text, chart_output])
# Gradio μΈν„°νŽ˜μ΄μŠ€ μ‹€ν–‰
demo.launch()