Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -9,35 +9,42 @@ UPLOAD_FOLDER = "uploads"
|
|
9 |
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
10 |
|
11 |
|
12 |
-
def process_resumes(job_description,
|
13 |
if not job_description.strip():
|
14 |
return "Please provide a job description.", None
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
# Rank resumes
|
39 |
results = rank_resumes(job_description, resume_texts)
|
40 |
|
|
|
41 |
for i, candidate in enumerate(results):
|
42 |
candidate["name"] = resume_texts[i][0]
|
43 |
|
@@ -51,12 +58,12 @@ def process_resumes(job_description, uploaded_file):
|
|
51 |
candidate.get("name", "Unknown"),
|
52 |
f"{candidate['score']:.4f}",
|
53 |
candidate["summary"]
|
54 |
-
]
|
55 |
]
|
56 |
|
57 |
-
|
58 |
return "", table_data
|
59 |
|
|
|
60 |
def extract_text_from_docx(filepath):
|
61 |
doc = Document(filepath)
|
62 |
full_text = []
|
@@ -73,7 +80,7 @@ with gr.Blocks() as demo:
|
|
73 |
with gr.Row():
|
74 |
job_desc = gr.Textbox(label="Job Description", lines=10, placeholder="Paste job description here...")
|
75 |
|
76 |
-
resumes = gr.File(label="Upload
|
77 |
|
78 |
btn = gr.Button("Rank Candidates")
|
79 |
|
|
|
9 |
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
10 |
|
11 |
|
12 |
+
def process_resumes(job_description, uploaded_files):
|
13 |
if not job_description.strip():
|
14 |
return "Please provide a job description.", None
|
15 |
|
16 |
+
if not uploaded_files:
|
17 |
+
return "Please upload at least one resume file.", None
|
18 |
+
|
19 |
+
resume_texts = []
|
20 |
+
|
21 |
+
for uploaded_file in uploaded_files:
|
22 |
+
filepath = uploaded_file.name # uploaded_file is a NamedTemporaryFile-like object
|
23 |
+
|
24 |
+
# Read file content depending on extension
|
25 |
+
if filepath.endswith(".txt"):
|
26 |
+
text = uploaded_file.read().decode("utf-8")
|
27 |
+
elif filepath.endswith(".pdf"):
|
28 |
+
import pdfplumber
|
29 |
+
uploaded_file.seek(0)
|
30 |
+
with pdfplumber.open(uploaded_file) as pdf:
|
31 |
+
pages = [page.extract_text() for page in pdf.pages if page.extract_text() is not None]
|
32 |
+
text = "\n".join(pages)
|
33 |
+
elif filepath.endswith(".docx"):
|
34 |
+
from docx import Document
|
35 |
+
uploaded_file.seek(0)
|
36 |
+
doc = Document(uploaded_file)
|
37 |
+
full_text = [para.text for para in doc.paragraphs]
|
38 |
+
text = "\n".join(full_text)
|
39 |
+
else:
|
40 |
+
return f"Unsupported file format: {filepath}", None
|
41 |
+
|
42 |
+
resume_texts.append((filepath, text))
|
43 |
|
44 |
# Rank resumes
|
45 |
results = rank_resumes(job_description, resume_texts)
|
46 |
|
47 |
+
# Add filename to candidate info
|
48 |
for i, candidate in enumerate(results):
|
49 |
candidate["name"] = resume_texts[i][0]
|
50 |
|
|
|
58 |
candidate.get("name", "Unknown"),
|
59 |
f"{candidate['score']:.4f}",
|
60 |
candidate["summary"]
|
61 |
+
] for candidate in results
|
62 |
]
|
63 |
|
|
|
64 |
return "", table_data
|
65 |
|
66 |
+
|
67 |
def extract_text_from_docx(filepath):
|
68 |
doc = Document(filepath)
|
69 |
full_text = []
|
|
|
80 |
with gr.Row():
|
81 |
job_desc = gr.Textbox(label="Job Description", lines=10, placeholder="Paste job description here...")
|
82 |
|
83 |
+
resumes = gr.File(label="Upload Resumes (.txt, .pdf, .docx)", file_types=[".txt", ".pdf", ".docx"], file_types_multiple=True, multiple=True)
|
84 |
|
85 |
btn = gr.Button("Rank Candidates")
|
86 |
|