Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -59,9 +59,24 @@ Skills: Backend Engineer, Node.js, AWS, Microservices, IoT, SaaS, Serverless, AP
|
|
| 59 |
|
| 60 |
|
| 61 |
def parse_csv_to_candidates(filepath: str) -> tuple[List[Candidate], pd.DataFrame, str]:
|
| 62 |
-
"""Parse uploaded CSV into Candidate objects.
|
| 63 |
try:
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
candidates = []
|
| 66 |
|
| 67 |
# Smart column detection
|
|
@@ -94,9 +109,9 @@ def parse_csv_to_candidates(filepath: str) -> tuple[List[Candidate], pd.DataFram
|
|
| 94 |
))
|
| 95 |
|
| 96 |
return candidates, df, ""
|
| 97 |
-
except Exception as e:
|
| 98 |
-
return [], pd.DataFrame(), f"Error parsing CSV: {e}"
|
| 99 |
|
|
|
|
|
|
|
| 100 |
|
| 101 |
def build_shortlist_table(response: EvaluationResponse) -> pd.DataFrame:
|
| 102 |
rows = []
|
|
|
|
| 59 |
|
| 60 |
|
| 61 |
def parse_csv_to_candidates(filepath: str) -> tuple[List[Candidate], pd.DataFrame, str]:
|
| 62 |
+
"""Parse uploaded file (CSV/XLSX) into Candidate objects."""
|
| 63 |
try:
|
| 64 |
+
# ✅ Handle CSV + encoding fallback
|
| 65 |
+
if filepath.endswith(".csv"):
|
| 66 |
+
try:
|
| 67 |
+
df = pd.read_csv(filepath, encoding="utf-8")
|
| 68 |
+
except UnicodeDecodeError:
|
| 69 |
+
df = pd.read_csv(filepath, encoding="latin-1")
|
| 70 |
+
|
| 71 |
+
# ✅ Handle Excel
|
| 72 |
+
elif filepath.endswith(".xlsx"):
|
| 73 |
+
df = pd.read_excel(filepath)
|
| 74 |
+
|
| 75 |
+
else:
|
| 76 |
+
return [], pd.DataFrame(), "Unsupported file type. Use CSV or XLSX."
|
| 77 |
+
|
| 78 |
+
df = df.fillna("")
|
| 79 |
+
|
| 80 |
candidates = []
|
| 81 |
|
| 82 |
# Smart column detection
|
|
|
|
| 109 |
))
|
| 110 |
|
| 111 |
return candidates, df, ""
|
|
|
|
|
|
|
| 112 |
|
| 113 |
+
except Exception as e:
|
| 114 |
+
return [], pd.DataFrame(), f"Error parsing file: {e}"
|
| 115 |
|
| 116 |
def build_shortlist_table(response: EvaluationResponse) -> pd.DataFrame:
|
| 117 |
rows = []
|