Skip to content

Commit

Permalink
Merge pull request #17 from aniketdarp190301/chatGPT_pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyavaidya2311 authored Oct 19, 2023
2 parents 76441da + 5db137e commit 9024390
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 0 deletions.
67 changes: 67 additions & 0 deletions Controller/chat_gpt_pipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from PyPDF2 import PdfReader
import numpy as np
import requests
import os
import openai


def pdf_to_text(pdf_path, text_path):
with open(pdf_path, 'rb') as pdf_file:
# Create a PDF reader object
pdf_reader = PdfReader(pdf_file)

# Initialize an empty string to store the text
text = ""

# Iterate through each page of the PDF
for page_num in range(len(pdf_reader.pages)):
# Extract text from the current page
text += pdf_reader.pages[page_num].extract_text()

# Open a text file in write mode and save the extracted text
with open(text_path, 'w', encoding='utf-8') as text_file:
text_file.write(text)


# chatgpt pipeline
def chatgpt(resume_textfile_path):
with open(resume_textfile_path, 'r') as file:
content = file.read()
openai_api_key = os.environ.get('OPENAI_API_KEY')

# Set the API endpoint
api_url = "https://api.openai.com/v1/chat/completions"

# Set the request headers
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {openai_api_key}"
}

# Set the request payload
payload = {
"model": "gpt-3.5-turbo",
"messages": [{"role":"system","content":"critique the following resume text on the basis of its conciseness, use of action words and numbers. Give suggestions on the 1. education section, then the 2. experiences section, then the 3. skills section and finally the 4. projects section. Give these suggestions on these four sections in the form of four paragraphs and label them Section 1, Section 2, Section 3 and Section 4 respectively, each separated by a line. Make sure each paragraph is atleast 50-70 words long."},{"role": "user", "content": content}],
"temperature": 0.7
}

# Make the POST request
try:
response = requests.post(api_url, json=payload, headers=headers)

# Check if the request was successful (status code 200)
if response.status_code == 200:
# Print or process the response content
print("API Response:")
json_data = response.json()
final_suggestions = json_data['choices'][0]['message']['content']
# print(final_suggestions)
return final_suggestions
else:
print(f"Error: {response.status_code}")
print(response.text)

except Exception as e:
print(f"An error occurred: {e}")


38 changes: 38 additions & 0 deletions Controller/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
from flask import send_file, current_app as app
from Controller.data import data, upcoming_events, profile
from Controller.chat_gpt_pipeline import pdf_to_text,chatgpt

home_route = Blueprint('home_route', __name__)

Expand Down Expand Up @@ -120,3 +121,40 @@ def display():
filename = os.listdir(path)
print(filename, path)
return send_file(path+str(filename[0]), attachment_filename= str(filename[0]))


@home_route.route('/chat_gpt_analyzer/', methods=['GET'])
def chat_gpt_analyzer():
files = os.listdir(os.getcwd()+'/Controller/resume')
print(files[0])
pdf_path = os.getcwd()+'//Controller/resume/'+files[0]
text_path = os.getcwd()+'//Controller/resume_txt/'+files[0][:-3]+'txt'
with open(text_path, 'w'):
pass
pdf_to_text(pdf_path, text_path)
suggestions = chatgpt(text_path)
flag = 0
final_sugges_send = []
final_sugges = ""

# Initialize an empty string to store the result
result_string = ""

# Iterate through each character in the original string
for char in suggestions:
# If the character is not a newline character, add it to the result string
if char != '\n':
final_sugges += char
sections = final_sugges.split("Section")
for section in sections:
section = section.strip() # Remove leading and trailing whitespace
# if section: # Check if the section is not empty (e.g., due to leading/trailing "Section")
# print("Section:", section)
print(sections)
sections = sections[1:]
section_names = ['Education', 'Experience','Skills', 'Projects']
sections[0] = sections[0][3:]
sections[1] = sections[1][3:]
sections[2] = sections[2][3:]
sections[3] = sections[3][3:]
return render_template('chat_gpt_analyzer.html', suggestions=sections, pdf_path=pdf_path, section_names = section_names)
151 changes: 151 additions & 0 deletions templates/chat_gpt_analyzer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<!DOCTYPE html>
<html lang="en">

<head>
<title>JavaScript example</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />

<!-- Bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous" />
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
crossorigin="anonymous"></script>

<link rel="stylesheet" href="{{ url_for('static', filename='css/layout.css') }}" />
<link rel="stylesheet" href="{{ url_for('static', filename='css/admin.css') }}" />
<style media="only screen">
html,
body {
height: 100%;
width: 100%;
margin: 0;
box-sizing: border-box;
-webkit-overflow-scrolling: touch;
}

html {
position: absolute;
top: 0;
left: 0;
padding: 0;
overflow: auto;
}

body {
overflow: auto;
}

#myElement {
color: black;
}

h1 {
text-align: center;
}

.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}

.container {
display: flex;
/* Use flexbox to arrange the divs horizontally */
justify-content: space-between;
/* Spread the divs evenly in the container */
}

.card {
/* Add any additional styling for your cards here */
margin: 10px;
/* Optional margin between the cards */
}

.text-black {
color: black;
}

.row {
height: 100vh;
/* Make the row take up the full viewport height */
}
</style>
</head>

<body></body>

<body>
<nav class="navbar navbar-expand-sm navbar-dark sticky-top">
<ul class="navbar-nav">
<img class="rounded-circle project-icon" alt="100x100"
src="https://ih1.redbubble.net/image.1703296696.9941/st,small,507x507-pad,600x600,f8f8f8.jpg"
height="30px" width="30px" style="margin-right: 5px; margin-top: 5px" data-holder-rendered="true" />
<a class="navbar-brand" href="/">WolfTrack</a>
</ul>
<ul class="navbar-nav ml-auto">
<a href="/resumeAnalyzer" style="color: #facaca; text-decoration: none">Analyze Resume</a>
</ul>
<ul class="navbar-nav ml-auto">
<a href="/findJobs" style="color: #facaca; text-decoration: none">Recommended Jobs</a>
</ul>
<ul class="navbar-nav ml-auto">
<a href="/chat_gpt_analyzer" style="color: #facaca; text-decoration: none">Resume Suggestions</a>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="/logout">Logout</a>
</li>
</ul>
</nav>
<h1 id="myElement">Suggestions:</h1>
<div class="row">
<div class="col-3">
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title text-black">{{section_names[0]}}</h5>
<p class="card-text text-black">{{suggestions[0]}}</p>
</div>
</div>
</div>
<div class="col-3">
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title text-black">{{section_names[1]}}</h5>
<p class="card-text text-black">{{suggestions[1]}}</p>
</div>
</div>
</div>
<div class="col-3">
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title text-black">{{section_names[2]}}</h5>
<p class="card-text text-black">{{suggestions[2]}}</p>
</div>
</div>
</div>
<div class="col-3">
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title text-black">{{section_names[3]}}</h5>
<p class="card-text text-black">{{suggestions[3]}}</p>
</div>
</div>
</div>
</div>


<!-- </ul> -->
</body>

</html>
3 changes: 3 additions & 0 deletions templates/companies_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@
>Recommended Jobs</a
>
</ul>
<ul class="navbar-nav ml-auto">
<a href="/chat_gpt_analyzer" style="color: #facaca; text-decoration: none">Resume Suggestions</a>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="/logout">Logout</a>
Expand Down
3 changes: 3 additions & 0 deletions templates/layout/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@
>Recommended Jobs</a
>
</ul>
<ul class="navbar-nav ml-auto">
<a href="/chat_gpt_analyzer" style="color: #facaca; text-decoration: none">Resume Suggestions</a>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="/logout">Logout</a>
Expand Down
3 changes: 3 additions & 0 deletions templates/resume_analyzer.html
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,9 @@
>Recommended Jobs</a
>
</ul>
<ul class="navbar-nav ml-auto">
<a href="/chat_gpt_analyzer" style="color: #facaca; text-decoration: none">Resume Suggestions</a>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="/logout">Logout</a>
Expand Down

0 comments on commit 9024390

Please sign in to comment.