rak-301 commited on
Commit
9ff1a7e
1 Parent(s): aa85a69

Upload 2 files

Browse files
Files changed (2) hide show
  1. main.py +153 -0
  2. requirements.txt +12 -0
main.py ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import aiohttp
2
+ import asyncio
3
+ import nest_asyncio
4
+ import streamlit as st
5
+ import time
6
+ from PyPDF2 import PdfReader
7
+ from pdfminer.high_level import extract_text
8
+ from docx import Document
9
+ import os
10
+ from openai import OpenAI
11
+
12
+ nest_asyncio.apply()
13
+
14
+ prompt = """
15
+
16
+ You will receive a user's resume and a corresponding job description. Your task is to analyze the resume to identify any gaps between the user's skills, experience, and qualifications and the requirements specified in the job description. Based on this analysis, create a 10-15 day interview preparation plan tailored to the job's specific requirements. The plan should focus on strengthening the areas where the user already meets the requirements, while also addressing and highlighting any skill gaps that need attention.
17
+
18
+ Before creating the Interview Preparation Guide, check if there is a large in the requirements listed in the job description and what is listed in the resume in terms of years of experience, and necessary skills. You must assess if it feasible for the user to be able to apply and prepare for an interview for the given job. If not then simply tell the user that there are significant gaps between their skills and qualification and what the job requires
19
+
20
+ Important Note:
21
+
22
+ - Speak to the user - "Your Resume..."
23
+
24
+ - Do not include the gaps or analysis in the output. Only include the Interview Preparation Guide
25
+
26
+
27
+ """
28
+
29
+ def extract_text_from_pdf(file):
30
+ try:
31
+ # Reset file pointer to the start of the file
32
+ file.seek(0)
33
+ text = extract_text(file)
34
+ return text
35
+ except Exception as e:
36
+ print(f"An error occurred: {e}")
37
+ return None
38
+
39
+
40
+ def extract_text_from_file(file):
41
+ file_extension = os.path.splitext(file.name)[1]
42
+
43
+ if file_extension == '.pdf':
44
+ return extract_text_from_pdf(file)
45
+
46
+ elif file_extension == '.docx':
47
+ doc = Document(file)
48
+ return "\n".join([paragraph.text for paragraph in doc.paragraphs])
49
+
50
+ elif file_extension == '.txt':
51
+ return file.read().decode('utf-8')
52
+
53
+ else:
54
+ return "Unsupported file type"
55
+
56
+
57
+
58
+ def call_openai_api(job_description, resume_text):
59
+ client = OpenAI(api_key ="sk-learning-bot-staging-account-SmwsiBUPWrJdslovYypiT3BlbkFJ70FRptLQcReZElmMFv6P")
60
+
61
+ completion = client.chat.completions.create(
62
+ model="gpt-4o",
63
+ temperature=0.1,
64
+ messages=[
65
+ {"role": "system", "content": prompt},
66
+ {"role": "user", "content": f"Here is the resume text: {resume_text} \n Here is the job description: {job_description}"}
67
+ ]
68
+ )
69
+
70
+ return completion.choices[0].message.content
71
+ # async def generate_completion(prompt, user_prompt, api_key):
72
+ # url = "https://api.openai.com/v1/chat/completions"
73
+ # headers = {
74
+ # "Content-Type": "application/json",
75
+ # "Authorization": f"Bearer {api_key}"
76
+ # }
77
+ #
78
+ # payload = {
79
+ # "model": "gpt-4o",
80
+ # "messages": [
81
+ # {"role": "system", "content": prompt},
82
+ # {"role": "user",
83
+ # "content": user_prompt}
84
+ # ],
85
+ # "temperature": 0.1,
86
+ # # "max_tokens": 385
87
+ # }
88
+ #
89
+ # async with aiohttp.ClientSession() as session:
90
+ # async with session.post(url, headers=headers, json=payload) as response:
91
+ # if response.status != 200:
92
+ # print(f"Error: {response.status}")
93
+ # return None
94
+ # response_json = await response.json()
95
+ # return response_json
96
+
97
+ def call_api(resume_text, job_description):
98
+ task = call_openai_api(job_description, resume_text)
99
+ return task
100
+ # async def main(resume_text, job_description):
101
+ # api_key = "sk-learning-bot-staging-account-SmwsiBUPWrJdslovYypiT3BlbkFJ70FRptLQcReZElmMFv6P"
102
+ #
103
+ # default_prompt = construct_default_prompt(resume_text, job_description)
104
+ # objective_prompt = construct_objective_prompt(resume_text)
105
+ #
106
+ # task1 = generate_completion(prompt, default_prompt, api_key)
107
+ # responses_async = await asyncio.gather(task1)
108
+ #
109
+ # return responses_async
110
+
111
+
112
+ st.set_page_config(page_title="Resume Analyzer", layout="centered")
113
+
114
+ st.title("Resume Analyzer")
115
+
116
+ job_description_source = st.radio("Job Description Source", ("Upload File", "Paste Text"))
117
+
118
+ if job_description_source == "Upload File":
119
+ job_description_file = st.file_uploader("Upload Job Description", type=['pdf', 'docx', 'txt'])
120
+ job_description = extract_text_from_file(job_description_file) if job_description_file else None
121
+ else:
122
+ job_description = st.text_area("Paste Job Description Here")
123
+
124
+ resume_file = st.file_uploader("Upload Resume", type=['pdf', 'docx', 'txt'])
125
+
126
+ if job_description:
127
+ st.subheader("Job Description Preview")
128
+ st.text_area("Job Description", job_description, height=200)
129
+
130
+ resume_text = None
131
+ if resume_file:
132
+ resume_text = extract_text_from_file(resume_file)
133
+ st.subheader("Resume Preview")
134
+ st.text_area("Resume", resume_text, height=200)
135
+
136
+ # def construct_default_prompt(resume_text, job_description):
137
+ # return f"Here is the resume text: {resume_text} \n Here is the job description: {job_description}"
138
+ #
139
+ # def construct_objective_prompt(resume_text):
140
+ # return f"Here is the resume text: {resume_text}"
141
+
142
+ if st.button("Analyze Resume"):
143
+ if job_description and resume_file:
144
+ start_time = time.time()
145
+ responses_async = call_api(resume_text, job_description)
146
+ end_time = time.time()
147
+ total_time = end_time - start_time
148
+ st.subheader("Analysis Result")
149
+ st.text_area("Result", responses_async, height=400)
150
+ # st.write(f"Time taken for OpenAI response: {response_time:.2f} seconds")
151
+ st.write(f"Total time taken for execution: {total_time:.2f} seconds")
152
+ else:
153
+ st.error("Please provide both the job description and resume.")
requirements.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiohttp
2
+ asyncio
3
+ nest-asyncio
4
+ streamlit
5
+ PyPDF2
6
+ python-docx
7
+ docx
8
+ pdfminer
9
+ pdfminer.six
10
+ pdf2image
11
+ pillow
12
+ openai