VGreatVig07 commited on
Commit
2be7807
Β·
verified Β·
1 Parent(s): d0b26f6

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ import pandas as pd
4
+ import faiss
5
+ import math
6
+ from sentence_transformers import SentenceTransformer
7
+ from dotenv import load_dotenv
8
+ import google.generativeai as genai
9
+
10
+ # Load environment variables and configure Gemini
11
+ load_dotenv()
12
+ genai.configure(api_key=os.getenv("API_KEY"))
13
+ gemini_model = genai.GenerativeModel("gemini-2.0-flash")
14
+
15
+ # Load vector index and dataframe
16
+ index = faiss.read_index("shl_vector_index.faiss")
17
+ df = pd.read_csv("shl_combined_assessments.csv")
18
+ model = SentenceTransformer("all-MiniLM-L6-v2")
19
+
20
+ # Helper to format the result row
21
+ def format_row(row):
22
+ def safe_cast(val, cast_type, default):
23
+ try:
24
+ if val is None or (isinstance(val, float) and math.isnan(val)):
25
+ return default
26
+ return cast_type(val)
27
+ except Exception:
28
+ return default
29
+
30
+ return {
31
+ "Assignment_Name": str(row["Assignment_Name"]),
32
+ "Assignment_Link": str(row["Assignment_Link"]),
33
+ "Test_Type": str(row["Test_Type"]),
34
+ "Approximate_Completion_Time": safe_cast(row["Approximate_Completion_Time"], int, -1),
35
+ "Remote_Testing_Support": bool(row["Remote_Testing_Support"]),
36
+ "Adaptive_IRT_Support": bool(row["Adaptive_IRT_Support"]),
37
+ "Job_Levels": str(row.get("Job_Levels", "N/A")),
38
+ }
39
+
40
+ # Streamlit UI
41
+ st.set_page_config(page_title="SHL Assessment Recommender", layout="centered")
42
+ st.title("πŸ” SHL Assessment Recommender")
43
+
44
+ query = st.text_input("Enter your job role or requirement:", "")
45
+
46
+ if st.button("Search") and query:
47
+ with st.spinner("Finding best assessments..."):
48
+ query_embedding = model.encode([query]).astype("float32")
49
+ D, I = index.search(query_embedding, 10)
50
+ results = [format_row(df.iloc[idx]) for idx in I[0]]
51
+
52
+ st.subheader("πŸ” Top Recommendations")
53
+ if results:
54
+ for idx, r in enumerate(results, 1):
55
+ with st.container():
56
+ st.markdown(f"### πŸ† Rank {idx}: {r['Assignment_Name']}")
57
+ st.markdown(f"[πŸ”— Assignment Link]({r['Assignment_Link']})")
58
+ st.markdown(f"- πŸ§ͺ **Test Type**: {r['Test_Type']}")
59
+ st.markdown(f"- ⏱️ **Duration**: {r['Approximate_Completion_Time']} mins")
60
+ st.markdown(f"- 🌐 **Remote Testing**: {r['Remote_Testing_Support']}")
61
+ st.markdown(f"- πŸ“Š **Adaptive/IRT**: {r['Adaptive_IRT_Support']}")
62
+ st.markdown(f"- πŸ‘€ **Job Levels**: {r['Job_Levels']}")
63
+ st.markdown("---")
64
+ else:
65
+ st.warning("No results found.")