deepsu commited on
Commit
1412979
Β·
1 Parent(s): 19c90e8

The gitignore and print steps

Browse files
Files changed (2) hide show
  1. .gitignore +7 -0
  2. main.py +71 -9
.gitignore ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ **/__pycache__/
2
+
3
+ env/
4
+ venv/
5
+ .venv/
6
+
7
+ /temp
main.py CHANGED
@@ -3,7 +3,6 @@ from typing import List
3
  import json, time, os, uuid
4
  from pathlib import Path
5
 
6
-
7
  from modules.pdf_to_json import PDFToJSON
8
  from modules.comparison import CompareData
9
 
@@ -16,6 +15,20 @@ app = FastAPI()
16
  THRESHOLD = 0.675
17
 
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  # ---------------------------------------------
20
  # πŸš€ STARTUP: LOAD ALL MODELS ONCE
21
  # ---------------------------------------------
@@ -50,6 +63,7 @@ def load_models():
50
 
51
  print("βœ… All models loaded once")
52
 
 
53
  # ---------------------------------------------
54
  # HEALTH CHECK
55
  # ---------------------------------------------
@@ -77,46 +91,94 @@ async def match_resumes(
77
  temp_dir = "./temp"
78
  os.makedirs(temp_dir, exist_ok=True)
79
 
80
- # βœ… Process JD ONCE
 
 
81
  processed_jd = compare.process_jd(jd)
82
  jd_emb = compare.encode(processed_jd)
83
 
 
 
 
 
 
84
  for file in files:
 
85
  file_path = os.path.join(temp_dir, f"{uuid.uuid4()}.pdf")
86
 
 
 
87
  try:
88
- # Save file
 
 
89
  with open(file_path, "wb") as f:
90
- f.write(await file.read())
 
91
 
92
- # Extract + parse
 
 
 
 
93
  resume_texts = pdf_to_json.extract_text([file_path])
 
 
 
 
 
94
  resume_json = pdf_to_json.generate_json(resume_texts)[0]
95
 
96
- # ⚠️ Skip if parsing failed
97
  if "error" in resume_json:
 
 
98
  continue
99
 
100
- # Process resume
 
 
 
 
101
  processed_resume = compare.process_resume(resume_json)
 
102
 
103
- # Encode
 
 
104
  resume_emb = compare.encode(processed_resume)
 
105
 
106
- # Compare
 
 
107
  score = compare.compare(resume_emb, jd_emb)
 
108
 
 
 
 
109
  if score >= THRESHOLD:
 
 
110
  results.append({
111
  "name": resume_json.get("name", "Unknown"),
112
  "score": float(score),
113
  "resume": resume_json
114
  })
 
 
 
 
 
115
 
116
  finally:
117
  if os.path.exists(file_path):
118
  os.remove(file_path)
 
119
 
 
 
 
120
  return {
121
  "total_matched": len(results),
122
  "processing_time": round(time.time() - start_time, 2),
 
3
  import json, time, os, uuid
4
  from pathlib import Path
5
 
 
6
  from modules.pdf_to_json import PDFToJSON
7
  from modules.comparison import CompareData
8
 
 
15
  THRESHOLD = 0.675
16
 
17
 
18
+ # ---------------------------------------------
19
+ # 🧠 RESUME STEP LOGGER
20
+ # ---------------------------------------------
21
+ def log_resume_steps(filename: str, steps: list):
22
+ print("\n" + "=" * 60)
23
+ print(f"πŸ“„ RESUME: {filename}")
24
+ print("=" * 60)
25
+
26
+ for i, step in enumerate(steps, 1):
27
+ print(f"{i}. {step}")
28
+
29
+ print("=" * 60 + "\n")
30
+
31
+
32
  # ---------------------------------------------
33
  # πŸš€ STARTUP: LOAD ALL MODELS ONCE
34
  # ---------------------------------------------
 
63
 
64
  print("βœ… All models loaded once")
65
 
66
+
67
  # ---------------------------------------------
68
  # HEALTH CHECK
69
  # ---------------------------------------------
 
91
  temp_dir = "./temp"
92
  os.makedirs(temp_dir, exist_ok=True)
93
 
94
+ # ---------------------------------
95
+ # JD PROCESSING (ONCE)
96
+ # ---------------------------------
97
  processed_jd = compare.process_jd(jd)
98
  jd_emb = compare.encode(processed_jd)
99
 
100
+ print("πŸ“Œ JD processed + embedded successfully")
101
+
102
+ # ---------------------------------
103
+ # LOOP EACH RESUME
104
+ # ---------------------------------
105
  for file in files:
106
+ steps = []
107
  file_path = os.path.join(temp_dir, f"{uuid.uuid4()}.pdf")
108
 
109
+ steps.append(f"Received file: {file.filename}")
110
+
111
  try:
112
+ # -------------------------
113
+ # SAVE FILE
114
+ # -------------------------
115
  with open(file_path, "wb") as f:
116
+ content = await file.read()
117
+ f.write(content)
118
 
119
+ steps.append("PDF saved to temp storage")
120
+
121
+ # -------------------------
122
+ # EXTRACT TEXT
123
+ # -------------------------
124
  resume_texts = pdf_to_json.extract_text([file_path])
125
+ steps.append(f"Text extracted (size={len(resume_texts)})")
126
+
127
+ # -------------------------
128
+ # JSON GENERATION
129
+ # -------------------------
130
  resume_json = pdf_to_json.generate_json(resume_texts)[0]
131
 
 
132
  if "error" in resume_json:
133
+ steps.append("❌ JSON generation failed β€” skipping resume")
134
+ log_resume_steps(file.filename, steps)
135
  continue
136
 
137
+ steps.append("Structured JSON generated from resume")
138
+
139
+ # -------------------------
140
+ # PROCESS RESUME
141
+ # -------------------------
142
  processed_resume = compare.process_resume(resume_json)
143
+ steps.append("Resume text processed/normalized")
144
 
145
+ # -------------------------
146
+ # ENCODING
147
+ # -------------------------
148
  resume_emb = compare.encode(processed_resume)
149
+ steps.append("Resume embedding created")
150
 
151
+ # -------------------------
152
+ # SIMILARITY
153
+ # -------------------------
154
  score = compare.compare(resume_emb, jd_emb)
155
+ steps.append(f"Similarity score computed: {score:.4f}")
156
 
157
+ # -------------------------
158
+ # DECISION
159
+ # -------------------------
160
  if score >= THRESHOLD:
161
+ steps.append(f"βœ… MATCHED (threshold={THRESHOLD})")
162
+
163
  results.append({
164
  "name": resume_json.get("name", "Unknown"),
165
  "score": float(score),
166
  "resume": resume_json
167
  })
168
+ else:
169
+ steps.append(f"❌ REJECTED (below threshold {THRESHOLD})")
170
+
171
+ # FINAL LOG FOR THIS RESUME
172
+ log_resume_steps(file.filename, steps)
173
 
174
  finally:
175
  if os.path.exists(file_path):
176
  os.remove(file_path)
177
+ steps.append("Temp file deleted")
178
 
179
+ # ---------------------------------
180
+ # RESPONSE
181
+ # ---------------------------------
182
  return {
183
  "total_matched": len(results),
184
  "processing_time": round(time.time() - start_time, 2),