Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,6 @@ from nltk.tokenize import word_tokenize
|
|
| 6 |
from nltk.corpus import wordnet
|
| 7 |
import requests
|
| 8 |
from typing import Optional
|
| 9 |
-
import os
|
| 10 |
import pandas as pd
|
| 11 |
from sqlalchemy import create_engine, Column, Integer, String, Float
|
| 12 |
from sqlalchemy.ext.declarative import declarative_base
|
|
@@ -107,11 +106,10 @@ def get_docparser_data(file, api_key, parser_id) -> Optional[dict]:
|
|
| 107 |
st.error(f"Error fetching data from Docparser: {e}")
|
| 108 |
return None
|
| 109 |
|
| 110 |
-
def get_openai_data(
|
| 111 |
openai.api_key = openai_key
|
| 112 |
try:
|
| 113 |
-
|
| 114 |
-
file_content = file.read()
|
| 115 |
response = openai.Completion.create(
|
| 116 |
engine="text-davinci-003",
|
| 117 |
prompt=f"Extract and analyze the resume content: {file_content}",
|
|
@@ -213,31 +211,23 @@ def process_resume(file, job_description, filename, parser_choice, openai_key=No
|
|
| 213 |
session.rollback()
|
| 214 |
return None
|
| 215 |
|
| 216 |
-
def process_resumes(
|
| 217 |
-
if not os.path.isdir(folder_path):
|
| 218 |
-
st.error("Invalid folder path")
|
| 219 |
-
return []
|
| 220 |
-
|
| 221 |
scores = []
|
| 222 |
processed_count = 0
|
| 223 |
|
| 224 |
try:
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
if not pdf_files:
|
| 228 |
-
st.warning("No PDF files found in the folder")
|
| 229 |
return []
|
| 230 |
|
| 231 |
-
total_files = len(
|
| 232 |
progress_bar = st.progress(0)
|
| 233 |
|
| 234 |
-
for index,
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
result
|
| 238 |
-
|
| 239 |
-
scores.append(result)
|
| 240 |
-
processed_count += 1
|
| 241 |
|
| 242 |
progress = (index + 1) / total_files
|
| 243 |
progress_bar.progress(progress)
|
|
@@ -389,7 +379,7 @@ def main():
|
|
| 389 |
choice = st.sidebar.selectbox("Menu", menu)
|
| 390 |
|
| 391 |
if choice == "Home":
|
| 392 |
-
analysis_type = st.selectbox("Select Analysis Type:", ["Single Resume", "
|
| 393 |
method_choice = st.selectbox("Select Method:", ["Use LLM", "Use Field Extraction"])
|
| 394 |
|
| 395 |
openai_key = None # Initialize openai_key
|
|
@@ -435,12 +425,12 @@ def main():
|
|
| 435 |
else:
|
| 436 |
st.warning("Failed to process the resume.")
|
| 437 |
|
| 438 |
-
elif analysis_type == "
|
| 439 |
-
|
| 440 |
|
| 441 |
if st.button("Analyze Resumes"):
|
| 442 |
-
if not
|
| 443 |
-
st.error("Please
|
| 444 |
return
|
| 445 |
if not job_description:
|
| 446 |
st.error("Please enter a job description")
|
|
@@ -452,7 +442,7 @@ def main():
|
|
| 452 |
st.error("Please enter the Docparser API key and Parser ID")
|
| 453 |
return
|
| 454 |
with st.spinner("Processing resumes..."):
|
| 455 |
-
scores = process_resumes(
|
| 456 |
if scores:
|
| 457 |
st.success("Analysis complete!")
|
| 458 |
for result in scores:
|
|
@@ -462,11 +452,11 @@ def main():
|
|
| 462 |
|
| 463 |
with st.expander("ℹ️ How to use"):
|
| 464 |
st.markdown("""
|
| 465 |
-
1. Select the analysis type: Single Resume or
|
| 466 |
2. Choose the method: Use LLM or Use Field Extraction.
|
| 467 |
3. If using LLM, enter the OpenAI API key.
|
| 468 |
4. If using Field Extraction, enter the Docparser API key and Parser ID.
|
| 469 |
-
5. Upload a resume PDF file or
|
| 470 |
6. Paste the job description.
|
| 471 |
7. Configure the weights for skills, certifications, experience, education, and projects.
|
| 472 |
8. Click 'Analyze' to start processing.
|
|
|
|
| 6 |
from nltk.corpus import wordnet
|
| 7 |
import requests
|
| 8 |
from typing import Optional
|
|
|
|
| 9 |
import pandas as pd
|
| 10 |
from sqlalchemy import create_engine, Column, Integer, String, Float
|
| 11 |
from sqlalchemy.ext.declarative import declarative_base
|
|
|
|
| 106 |
st.error(f"Error fetching data from Docparser: {e}")
|
| 107 |
return None
|
| 108 |
|
| 109 |
+
def get_openai_data(file, openai_key: str) -> Optional[dict]:
|
| 110 |
openai.api_key = openai_key
|
| 111 |
try:
|
| 112 |
+
file_content = file.read()
|
|
|
|
| 113 |
response = openai.Completion.create(
|
| 114 |
engine="text-davinci-003",
|
| 115 |
prompt=f"Extract and analyze the resume content: {file_content}",
|
|
|
|
| 211 |
session.rollback()
|
| 212 |
return None
|
| 213 |
|
| 214 |
+
def process_resumes(files, job_description, parser_choice, openai_key=None, api_key=None, parser_id=None, skill_weight=0.9, certification_weight=0.05, experience_weight=0.03, education_weight=0.02, project_weight=0.1):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
scores = []
|
| 216 |
processed_count = 0
|
| 217 |
|
| 218 |
try:
|
| 219 |
+
if not files:
|
| 220 |
+
st.warning("No PDF files uploaded")
|
|
|
|
|
|
|
| 221 |
return []
|
| 222 |
|
| 223 |
+
total_files = len(files)
|
| 224 |
progress_bar = st.progress(0)
|
| 225 |
|
| 226 |
+
for index, file in enumerate(files):
|
| 227 |
+
result = process_resume(file, job_description, file.name, parser_choice, openai_key, api_key, parser_id, skill_weight, certification_weight, experience_weight, education_weight, project_weight)
|
| 228 |
+
if result:
|
| 229 |
+
scores.append(result)
|
| 230 |
+
processed_count += 1
|
|
|
|
|
|
|
| 231 |
|
| 232 |
progress = (index + 1) / total_files
|
| 233 |
progress_bar.progress(progress)
|
|
|
|
| 379 |
choice = st.sidebar.selectbox("Menu", menu)
|
| 380 |
|
| 381 |
if choice == "Home":
|
| 382 |
+
analysis_type = st.selectbox("Select Analysis Type:", ["Single Resume", "Multiple Resumes"])
|
| 383 |
method_choice = st.selectbox("Select Method:", ["Use LLM", "Use Field Extraction"])
|
| 384 |
|
| 385 |
openai_key = None # Initialize openai_key
|
|
|
|
| 425 |
else:
|
| 426 |
st.warning("Failed to process the resume.")
|
| 427 |
|
| 428 |
+
elif analysis_type == "Multiple Resumes":
|
| 429 |
+
uploaded_files = st.file_uploader("Upload multiple resume PDF files", type="pdf", accept_multiple_files=True)
|
| 430 |
|
| 431 |
if st.button("Analyze Resumes"):
|
| 432 |
+
if not uploaded_files:
|
| 433 |
+
st.error("Please upload resume PDF files")
|
| 434 |
return
|
| 435 |
if not job_description:
|
| 436 |
st.error("Please enter a job description")
|
|
|
|
| 442 |
st.error("Please enter the Docparser API key and Parser ID")
|
| 443 |
return
|
| 444 |
with st.spinner("Processing resumes..."):
|
| 445 |
+
scores = process_resumes(uploaded_files, job_description, parser_choice, openai_key, api_key, parser_id, skill_weight, certification_weight, experience_weight, education_weight, project_weight)
|
| 446 |
if scores:
|
| 447 |
st.success("Analysis complete!")
|
| 448 |
for result in scores:
|
|
|
|
| 452 |
|
| 453 |
with st.expander("ℹ️ How to use"):
|
| 454 |
st.markdown("""
|
| 455 |
+
1. Select the analysis type: Single Resume or Multiple Resumes.
|
| 456 |
2. Choose the method: Use LLM or Use Field Extraction.
|
| 457 |
3. If using LLM, enter the OpenAI API key.
|
| 458 |
4. If using Field Extraction, enter the Docparser API key and Parser ID.
|
| 459 |
+
5. Upload a resume PDF file or multiple files.
|
| 460 |
6. Paste the job description.
|
| 461 |
7. Configure the weights for skills, certifications, experience, education, and projects.
|
| 462 |
8. Click 'Analyze' to start processing.
|