billyxx commited on
Commit
703050d
·
verified ·
1 Parent(s): 90540d0

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -6,32 +6,30 @@ from recommender import rank_resumes, summarize_resume_flan, extract_applicant_n
6
  UPLOAD_FOLDER = "uploads"
7
  os.makedirs(UPLOAD_FOLDER, exist_ok=True)
8
 
 
9
  def process_resumes(job_description, uploaded_file):
10
  if not job_description.strip():
11
  return "Please provide a job description.", None
12
 
13
- filepath = os.path.join(UPLOAD_FOLDER, uploaded_file.name)
 
14
 
15
- # Fix here: uploaded_file might be a file-like object or just string content
16
- if hasattr(uploaded_file, "read"): # file-like object (e.g., PDF)
17
- with open(filepath, "wb") as f:
18
- f.write(uploaded_file.read())
19
- else: # string content (likely txt)
20
- with open(filepath, "w", encoding="utf-8") as f:
21
- f.write(uploaded_file)
22
 
23
- # Read the saved resume content
24
  if filepath.endswith(".txt"):
25
  with open(filepath, "r", encoding="utf-8") as f:
26
  text = f.read()
27
  elif filepath.endswith(".pdf"):
 
28
  with pdfplumber.open(filepath) as pdf:
29
- pages = [page.extract_text() for page in pdf.pages]
30
  text = "\n".join(pages)
31
  else:
32
  return "Unsupported file format.", None
33
 
34
- resume_texts = [(uploaded_file.name, text)]
35
 
36
  # Rank resumes
37
  results = rank_resumes(job_description, resume_texts)
@@ -53,6 +51,7 @@ def process_resumes(job_description, uploaded_file):
53
 
54
 
55
 
 
56
  with gr.Blocks() as demo:
57
  gr.Markdown("## Candidate Recommendation Engine")
58
  with gr.Row():
 
6
  UPLOAD_FOLDER = "uploads"
7
  os.makedirs(UPLOAD_FOLDER, exist_ok=True)
8
 
9
+
10
  def process_resumes(job_description, uploaded_file):
11
  if not job_description.strip():
12
  return "Please provide a job description.", None
13
 
14
+ # uploaded_file is the file path string, use it directly
15
+ filepath = uploaded_file # no need to save again
16
 
17
+ # Extract filename for display in results
18
+ filename = os.path.basename(filepath)
 
 
 
 
 
19
 
20
+ # Read file content depending on extension
21
  if filepath.endswith(".txt"):
22
  with open(filepath, "r", encoding="utf-8") as f:
23
  text = f.read()
24
  elif filepath.endswith(".pdf"):
25
+ import pdfplumber
26
  with pdfplumber.open(filepath) as pdf:
27
+ pages = [page.extract_text() for page in pdf.pages if page.extract_text() is not None]
28
  text = "\n".join(pages)
29
  else:
30
  return "Unsupported file format.", None
31
 
32
+ resume_texts = [(filename, text)]
33
 
34
  # Rank resumes
35
  results = rank_resumes(job_description, resume_texts)
 
51
 
52
 
53
 
54
+
55
  with gr.Blocks() as demo:
56
  gr.Markdown("## Candidate Recommendation Engine")
57
  with gr.Row():