Spaces:
Sleeping
Sleeping
File size: 3,861 Bytes
1ec6c27 3db0045 1ec6c27 3db0045 1ec6c27 3db0045 1ec6c27 3db0045 1ec6c27 3db0045 1ec6c27 3db0045 1ec6c27 3db0045 1ec6c27 3db0045 1ec6c27 3db0045 1ec6c27 3db0045 1ec6c27 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
import gradio as gr
import pandas as pd
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity
import networkx as nx
import matplotlib.pyplot as plt
# Sentence-BERT λͺ¨λΈ λ‘λ
model = SentenceTransformer('all-MiniLM-L6-v2')
# μ§μ λ°μ΄ν°λ₯Ό λΆμνμ¬ κ΅μ‘ νλ‘κ·Έλ¨μ μΆμ²νκ³ κ·Έλνλ₯Ό 그리λ ν¨μ
def analyze_data(employee_file, program_file):
# μ§μ λ°μ΄ν°μ κ΅μ‘ νλ‘κ·Έλ¨ λ°μ΄ν° λΆλ¬μ€κΈ°
employee_df = pd.read_csv(employee_file.name)
program_df = pd.read_csv(program_file.name)
# μ§μ μλκ³Ό νλ‘κ·Έλ¨ νμ΅ λͺ©νλ₯Ό 벑ν°ν
employee_skills = employee_df['current_skills'].tolist()
program_skills = program_df['skills_acquired'].tolist()
employee_embeddings = model.encode(employee_skills)
program_embeddings = model.encode(program_skills)
# μ μ¬λ κ³μ°
similarities = cosine_similarity(employee_embeddings, program_embeddings)
# μ§μλ³ μΆμ² νλ‘κ·Έλ¨ λ¦¬μ€νΈ
recommendations = []
for i, employee in employee_df.iterrows():
recommended_programs = []
for j, program in program_df.iterrows():
if similarities[i][j] > 0.5: # μ μ¬λ μκ³κ° κΈ°μ€
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)
# λ€νΈμν¬ κ·Έλν μμ±
G = nx.Graph()
for employee in employee_df['employee_name']:
G.add_node(employee, type='employee')
for program in program_df['program_name']:
G.add_node(program, type='program')
for i, employee in employee_df.iterrows():
for j, program in program_df.iterrows():
if similarities[i][j] > 0.5: # μ μ¬λ μκ³κ°
G.add_edge(employee['employee_name'], program['program_name'])
# κ·Έλν μκ°ν
plt.figure(figsize=(10, 8))
pos = nx.spring_layout(G)
nx.draw(G, pos, with_labels=True, node_color='skyblue', node_size=2000, font_size=10, font_weight='bold')
plt.title("μ§μκ³Ό νλ‘κ·Έλ¨ κ°μ κ΄κ³")
plt.tight_layout()
return result_text, plt.gcf()
# Gradio μΈν°νμ΄μ€ μ μ
def main(employee_file, program_file):
return analyze_data(employee_file, program_file)
# Gradio λΈλ‘
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() |