Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,30 +7,28 @@ from reranker import rerank
|
|
7 |
def clean_df(df):
|
8 |
df = df.copy()
|
9 |
|
10 |
-
#
|
11 |
-
|
12 |
-
second_col = df.iloc[:, 1].astype(str)
|
13 |
-
if second_col.str.contains('http').any() or second_col.str.contains('www').any():
|
14 |
-
df["url"] = second_col # Already has full URLs
|
15 |
-
else:
|
16 |
-
# Create full URLs from IDs
|
17 |
-
df["url"] = "https://www.shl.com/" + second_col.str.replace(r'^[\s/]*', '', regex=True)
|
18 |
|
19 |
-
|
20 |
-
df["
|
21 |
|
22 |
-
#
|
23 |
-
df["
|
|
|
24 |
|
25 |
-
|
|
|
26 |
|
27 |
-
#
|
28 |
-
df["
|
29 |
-
df.iloc[:, 8].astype(str).str.extract(r'(\d+)')[0],
|
30 |
-
errors='coerce'
|
31 |
-
)
|
32 |
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
try:
|
36 |
df = pd.read_csv("assesments.csv")
|
@@ -69,10 +67,19 @@ def recommend(query):
|
|
69 |
try:
|
70 |
# Print some debug info
|
71 |
print(f"Processing query: {query[:50]}...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
top_k_df = get_relevant_passages(query, df_clean, top_k=20)
|
74 |
|
75 |
-
# Debug: Check
|
76 |
print(f"Retrieved {len(top_k_df)} assessments")
|
77 |
if not top_k_df.empty:
|
78 |
print(f"Sample URLs from retrieval: {top_k_df['url'].iloc[:3].tolist()}")
|
@@ -98,6 +105,7 @@ def recommend(query):
|
|
98 |
print(f"Error: {str(e)}\n{error_details}")
|
99 |
return {"error": f"Error processing request: {str(e)}"}
|
100 |
|
|
|
101 |
iface = gr.Interface(
|
102 |
fn=recommend,
|
103 |
inputs=gr.Textbox(label="Enter Job Description", lines=4),
|
|
|
7 |
def clean_df(df):
|
8 |
df = df.copy()
|
9 |
|
10 |
+
# Extract the assessment name from the URL
|
11 |
+
df["assessment_name"] = df["Pre-packaged Job Solutions"].str.split('/').str[-2].str.replace('-', ' ').str.title()
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
# Create proper URLs
|
14 |
+
df["url"] = "https://www.shl.com" + df["Pre-packaged Job Solutions"]
|
15 |
|
16 |
+
# Convert T/F to Yes/No
|
17 |
+
df["remote_support"] = df["Remote Testing"].map(lambda x: "Yes" if x == "T" else "No")
|
18 |
+
df["adaptive_support"] = df["Adaptive/IRT"].map(lambda x: "Yes" if x == "T" else "No")
|
19 |
|
20 |
+
# Handle test_type properly - it's already in list format as a string
|
21 |
+
df["test_type"] = df["Test Type"]
|
22 |
|
23 |
+
# Keep the description as is
|
24 |
+
df["description"] = df["Description"]
|
|
|
|
|
|
|
25 |
|
26 |
+
# Extract duration with proper handling
|
27 |
+
df["duration"] = df["Assessment_Length"].str.extract(r'(\d+)').fillna("N/A")
|
28 |
+
|
29 |
+
# Select only the columns we need
|
30 |
+
return df[["assessment_name", "url", "remote_support", "adaptive_support",
|
31 |
+
"description", "duration", "test_type"]]
|
32 |
|
33 |
try:
|
34 |
df = pd.read_csv("assesments.csv")
|
|
|
67 |
try:
|
68 |
# Print some debug info
|
69 |
print(f"Processing query: {query[:50]}...")
|
70 |
+
print(f"DataFrame shape: {df_clean.shape}")
|
71 |
+
print(f"DataFrame columns: {df_clean.columns.tolist()}")
|
72 |
+
|
73 |
+
if df_clean.empty:
|
74 |
+
return {"error": "No assessment data available"}
|
75 |
+
|
76 |
+
# Print a sample row for debugging
|
77 |
+
print("Sample row:")
|
78 |
+
print(df_clean.iloc[0].to_dict())
|
79 |
|
80 |
top_k_df = get_relevant_passages(query, df_clean, top_k=20)
|
81 |
|
82 |
+
# Debug: Check retrieved data
|
83 |
print(f"Retrieved {len(top_k_df)} assessments")
|
84 |
if not top_k_df.empty:
|
85 |
print(f"Sample URLs from retrieval: {top_k_df['url'].iloc[:3].tolist()}")
|
|
|
105 |
print(f"Error: {str(e)}\n{error_details}")
|
106 |
return {"error": f"Error processing request: {str(e)}"}
|
107 |
|
108 |
+
|
109 |
iface = gr.Interface(
|
110 |
fn=recommend,
|
111 |
inputs=gr.Textbox(label="Enter Job Description", lines=4),
|