Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2023-24-051 Resume_Ranker
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TMP-2023-24-051
2023-24-051 Resume_Ranker
Commits
173bd475
Commit
173bd475
authored
Mar 23, 2024
by
Sewwandi W.M.C
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create job_to_cv_openai.ipynb
cv generation
parent
d117e872
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
137 additions
and
0 deletions
+137
-0
Function 01/Function 01/Function1/March_Update/OpenAI/job_to_cv_openai.ipynb
...n 01/Function1/March_Update/OpenAI/job_to_cv_openai.ipynb
+137
-0
No files found.
Function 01/Function 01/Function1/March_Update/OpenAI/job_to_cv_openai.ipynb
0 → 100644
View file @
173bd475
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test with OpenAI Server"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"from openai import OpenAI\n",
"import os\n",
"from dotenv import load_dotenv\n",
"load_dotenv()\n",
"\n",
"# Point to the OpenAI server\n",
"client = OpenAI(api_key=os.environ.get(\"OPENAI_API_KEY\"))\n",
"\n",
"# Point to the local server\n",
"# client = OpenAI(base_url=\"http://localhost:1234/v1\", api_key=\"not-needed\")\n",
"\n",
"def generate_resumes(job_description):\n",
"\n",
" # Create completions\n",
" completion = client.chat.completions.create(\n",
" model=\"gpt-3.5-turbo\",\n",
" messages=[\n",
" {\"role\": \"system\", \"content\": \"You need to create 100% matching 3 different separate BEST RESUMES for the following job description. Number the Resumes as Resume 1, Resume 2, Resume 3. Don't Include like Personal Details Sections.\"},\n",
" {\"role\": \"user\", \"content\": job_description}\n",
" ]\n",
" )\n",
"\n",
" cvs = completion.choices[0].message.content\n",
" return cvs"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"import re\n",
"import pandas as pd\n",
"\n",
"def preprocess_text(text):\n",
" # Remove characters like * - + # _\n",
" processed_text = re.sub(r'[\\*\\-\\+#_]', '', text)\n",
" # Replace '\\n\\n' with a space, and '\\n' with a single newline\n",
" processed_text = re.sub(r'\\n\\n', ' ', processed_text)\n",
" processed_text = re.sub(r'\\n', ' ', processed_text)\n",
" return processed_text\n",
"\n",
"def separate_resumes(cvs):\n",
" # Try the first option: Resume 1:\n",
" resume_match = re.search(r'Resume 1:(.*?)Resume 2', cvs, re.DOTALL)\n",
" resume1 = resume_match.group(1).strip() if resume_match else \"\"\n",
"\n",
" # If the first option is not found, try the second option: Resume 1\n",
" if not resume1:\n",
" resume_match = re.search(r'Resume 1(.*?)Resume 2', cvs, re.DOTALL)\n",
" resume1 = resume_match.group(1).strip() if resume_match else \"\"\n",
"\n",
" resume1 = preprocess_text(resume1)\n",
"\n",
" # Repeat the process for Resume 2 and Resume 3\n",
" resume_match = re.search(r'Resume 2:(.*?)Resume 3', cvs, re.DOTALL)\n",
" resume2 = resume_match.group(1).strip() if resume_match else \"\"\n",
" if not resume2:\n",
" resume_match = re.search(r'Resume 2(.*?)Resume 3', cvs, re.DOTALL)\n",
" resume2 = resume_match.group(1).strip() if resume_match else \"\"\n",
" resume2 = preprocess_text(resume2)\n",
"\n",
" resume_match = re.search(r'Resume 3:(.*)', cvs, re.DOTALL)\n",
" resume3 = resume_match.group(1).strip() if resume_match else \"\"\n",
" if not resume3:\n",
" resume_match = re.search(r'Resume 3(.*)', cvs, re.DOTALL)\n",
" resume3 = resume_match.group(1).strip() if resume_match else \"\"\n",
" resume3 = preprocess_text(resume3)\n",
"\n",
" data = {'Resume 1': [resume1], 'Resume 2': [resume2], 'Resume 3': [resume3]}\n",
" df = pd.DataFrame(data)\n",
" return df"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"# Load the job data\n",
"job_data = pd.read_csv('Job_ad.csv')\n",
"\n",
"# Create new columns 'Resume 1', 'Resume 2', 'Resume 3' in the job data\n",
"for index, row in job_data.iterrows():\n",
" job_description = f\"{row['jobTitle']} {row['jobSummary']} {row['keyResponsibilities']} {row['requiredQualification']}\"\n",
" cvs_result = generate_resumes(job_description)\n",
" df_separate_result = separate_resumes(cvs_result)\n",
"\n",
" # Add new columns to the job data\n",
" job_data.loc[index, 'Resume 1'] = df_separate_result['Resume 1'][0]\n",
" job_data.loc[index, 'Resume 2'] = df_separate_result['Resume 2'][0]\n",
" job_data.loc[index, 'Resume 3'] = df_separate_result['Resume 3'][0]\n",
"\n",
"# Save the updated job data to a new CSV file\n",
"job_data.to_csv('Job_ad_with_resumes.csv', index=False)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "resume-ranker",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment