Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,24 +4,54 @@ from retriever import get_relevant_passages
|
|
4 |
from reranker import rerank
|
5 |
|
6 |
# Load and clean CSV
|
7 |
-
df = pd.read_csv("assesments.csv")
|
8 |
-
|
9 |
def clean_df(df):
|
10 |
df = df.copy()
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
df["remote_support"] = df.iloc[:, 2].map(lambda x: "Yes" if x == "T" else "No")
|
13 |
df["adaptive_support"] = df.iloc[:, 3].map(lambda x: "Yes" if x == "T" else "No")
|
|
|
|
|
14 |
df["test_type"] = df.iloc[:, 4].astype(str).str.split("\\n")
|
|
|
15 |
df["description"] = df.iloc[:, 5]
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
return df[["url", "adaptive_support", "remote_support", "description", "duration", "test_type"]]
|
18 |
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
def recommend(query):
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
iface = gr.Interface(
|
27 |
fn=recommend,
|
@@ -32,4 +62,4 @@ iface = gr.Interface(
|
|
32 |
)
|
33 |
|
34 |
if __name__ == "__main__":
|
35 |
-
iface.launch()
|
|
|
4 |
from reranker import rerank
|
5 |
|
6 |
# Load and clean CSV
|
|
|
|
|
7 |
def clean_df(df):
|
8 |
df = df.copy()
|
9 |
+
|
10 |
+
# Ensure clean URLs
|
11 |
+
# Check if the second column contains URLs or just IDs
|
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 |
df["remote_support"] = df.iloc[:, 2].map(lambda x: "Yes" if x == "T" else "No")
|
20 |
df["adaptive_support"] = df.iloc[:, 3].map(lambda x: "Yes" if x == "T" else "No")
|
21 |
+
|
22 |
+
# Handle test_type with error checking
|
23 |
df["test_type"] = df.iloc[:, 4].astype(str).str.split("\\n")
|
24 |
+
|
25 |
df["description"] = df.iloc[:, 5]
|
26 |
+
|
27 |
+
# Extract duration with error handling
|
28 |
+
df["duration"] = pd.to_numeric(
|
29 |
+
df.iloc[:, 8].astype(str).str.extract(r'(\d+)')[0],
|
30 |
+
errors='coerce'
|
31 |
+
)
|
32 |
+
|
33 |
return df[["url", "adaptive_support", "remote_support", "description", "duration", "test_type"]]
|
34 |
|
35 |
+
try:
|
36 |
+
df = pd.read_csv("assesments.csv")
|
37 |
+
df_clean = clean_df(df)
|
38 |
+
except Exception as e:
|
39 |
+
print(f"Error loading or cleaning data: {e}")
|
40 |
+
# Create an empty DataFrame with required columns as fallback
|
41 |
+
df_clean = pd.DataFrame(columns=["url", "adaptive_support", "remote_support",
|
42 |
+
"description", "duration", "test_type"])
|
43 |
|
44 |
def recommend(query):
|
45 |
+
if not query.strip():
|
46 |
+
return {"error": "Please enter a job description"}
|
47 |
+
|
48 |
+
try:
|
49 |
+
top_k_df = get_relevant_passages(query, df_clean, top_k=20)
|
50 |
+
candidates = top_k_df.to_dict(orient="records")
|
51 |
+
result = rerank(query, candidates)
|
52 |
+
return result
|
53 |
+
except Exception as e:
|
54 |
+
return {"error": f"Error processing request: {str(e)}"}
|
55 |
|
56 |
iface = gr.Interface(
|
57 |
fn=recommend,
|
|
|
62 |
)
|
63 |
|
64 |
if __name__ == "__main__":
|
65 |
+
iface.launch()
|