Spaces:
Sleeping
Sleeping
File size: 1,919 Bytes
5f73052 |
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 |
import pandas as pd
import numpy as np
import faiss
from sentence_transformers import SentenceTransformer
import gradio as gr
# ---------- Load CSV ----------
df = pd.read_csv("shl_products.csv")
# ---------- Description Helper ----------
def create_description(row):
return f"{row['Pre-packaged Job Solutions']} is a {row['Test Type']} test. " \
f"Remote Testing support: {row['Remote Testing']}. Adaptive/IRT: {row['Adaptive/IRT']}."
df["description"] = df.apply(create_description, axis=1)
# ---------- Sentence Embeddings ----------
model = SentenceTransformer("all-MiniLM-L6-v2")
df["embedding"] = df["description"].apply(lambda x: model.encode(str(x)))
# ---------- Build FAISS Index ----------
embedding_matrix = np.stack(df["embedding"].values)
dimension = embedding_matrix.shape[1]
index = faiss.IndexFlatL2(dimension)
index.add(embedding_matrix)
# ---------- Retrieval Function ----------
def recommend_assessments(query, k=10):
query_embedding = model.encode(query)
D, I = index.search(np.array([query_embedding]), k)
results = df.iloc[I[0]][[
"Pre-packaged Job Solutions",
"Remote Testing",
"Adaptive/IRT",
"Test Type"
]]
return results.reset_index(drop=True)
# ---------- Gradio UI ----------
interface = gr.Interface(
fn=recommend_assessments,
inputs=gr.Textbox(lines=3, label="Job Description / Hiring Need"),
outputs=gr.Dataframe(type="pandas"),
title="SHL Assessment Recommender",
description="Enter a natural language hiring query and get relevant SHL assessments.",
examples=[
["Looking for a cognitive test for engineers that supports remote testing."],
["Assessment for sales roles with adaptive questions and remote option."],
["Test for developers that evaluates collaboration and reasoning in under 40 minutes."]
]
)
if __name__ == "__main__":
interface.launch()
|