Spaces:
Running
Running
File size: 11,495 Bytes
69a84e8 3781bd4 5af086a 69eddf8 5af086a 69eddf8 5af086a 69eddf8 5af086a 69eddf8 7562c31 3781bd4 6319188 3781bd4 919ef1e 3781bd4 919ef1e 3781bd4 919ef1e 3781bd4 6319188 d2213c1 3781bd4 6319188 3781bd4 6319188 3781bd4 6319188 3781bd4 d2213c1 6319188 3781bd4 6319188 3781bd4 a876ac5 3781bd4 5af086a 3781bd4 5af086a 3781bd4 a876ac5 5af086a a876ac5 3264ac4 a876ac5 3264ac4 5af086a a876ac5 5af086a 3264ac4 a876ac5 3781bd4 3264ac4 3781bd4 a876ac5 d2213c1 3781bd4 d2213c1 3264ac4 3781bd4 d2213c1 3781bd4 6319188 3781bd4 3264ac4 5af086a 3264ac4 3781bd4 6d0143e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
import gradio as gr
import os
from groq import Groq
from PyPDF2 import PdfReader
from docx import Document
GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
client = Groq(api_key=GROQ_API_KEY)
CSS = """
.duplicate-button {
margin: auto !important;
color: white !important;
background: black !important;
border-radius: 100vh !important;
}
h3, p, h1 {
text-align: center;
color: white;
}
footer {
text-align: center;
padding: 10px;
width: 100%;
background-color: rgba(240, 240, 240, 0.8);
z-index: 1000;
position: relative;
margin-top: 10px;
color: black;
}
"""
FOOTER_TEXT = """
<footer>
<p>If you enjoyed the functionality of the app, please leave a like!<br>
Check out more on <a href="https://www.linkedin.com/in/girish-wangikar/" target="_blank">LinkedIn</a> |
<a href="https://girishwangikar.github.io/Girish_Wangikar_Portfolio.github.io/" target="_blank">Portfolio</a></p>
</footer>
"""
RESUME_ANALYZER_INSTRUCTIONS = """
<div style="background-color: #000000; color: #ffffff; padding: 10px; border-radius: 5px; margin-bottom: 10px;">
<p><strong>Instructions:</strong></p>
<ul>
<li>Upload your resume (PDF or DOCX) in the file upload area.</li>
<li>If you want to analyze your resume against a specific job description, keep the checkbox checked and enter the job description in the text box.</li>
<li>If you want a general resume analysis without a job description, uncheck the "Analyze with Job Description" box.</li>
<li>Click "Analyze Resume" to get your results.</li>
</ul>
</div>
"""
COVER_LETTER_INSTRUCTIONS = """
<div style="background-color: #000000; color: #ffffff; padding: 10px; border-radius: 5px; margin-bottom: 10px;">
<p><strong>Instructions for Cover Letter Generation:</strong></p>
<ol>
<li>First, go to the "Resume Analyzer" tab.</li>
<li>Upload your resume and enter the job description there.</li>
<li>Then, come back to this tab and click "Generate Cover Letter".</li>
</ol>
</div>
"""
INTERVIEW_QUESTIONS_INSTRUCTIONS = """
<div style="background-color: #000000; color: #ffffff; padding: 10px; border-radius: 5px; margin-bottom: 10px;">
<p><strong>Instructions for Interview Questions Generation:</strong></p>
<p>Enter the job description in the text box below and click "Generate Interview Questions".</p>
</div>
"""
# Also update the disclaimer styles to match
COVER_LETTER_DISCLAIMER = """
<p style="font-style: italic; color: #cccccc; background-color: #000000; padding: 10px; border-radius: 5px;">
Disclaimer: This cover letter is generated based on the provided job description and resume.
It should be carefully reviewed and tailored to your specific needs and the company's requirements before use.
</p>
"""
INTERVIEW_QUESTIONS_DISCLAIMER = """
<p style="font-style: italic; color: #cccccc; background-color: #000000; padding: 10px; border-radius: 5px;">
Disclaimer: These interview questions are generated based on the provided job description.
They should be reviewed and adjusted to better fit the specific role, company culture, and interview process.
</p>
"""
TITLE = "<h1>π ATS Resume Analyzer π</h1>"
PLACEHOLDER = "Chat with AI about your resume and job descriptions..."
def extract_text_from_pdf(pdf_file):
reader = PdfReader(pdf_file)
text = ""
for page in reader.pages:
text += page.extract_text()
return text
def extract_text_from_docx(docx_file):
doc = Document(docx_file)
text = ""
for para in doc.paragraphs:
text += para.text + "\n"
return text
def generate_response(message: str, system_prompt: str, temperature: float, max_tokens: int):
conversation = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": message}
]
response = client.chat.completions.create(
model="llama-3.1-8B-Instant",
messages=conversation,
temperature=temperature,
max_tokens=max_tokens,
stream=False
)
return response.choices[0].message.content
def analyze_resume_with_job_description(resume_text, job_description, temperature, max_tokens):
prompt = f"""
Please analyze the following resume in the context of the job description provided. Strictly check every single line in the job description and analyze the resume for exact matches. Maintain high ATS standards and give scores only to the correct matches. Focus on missing core skills and soft skills. Provide the following details:
1. The match percentage of the resume to the job description.
2. A list of missing keywords.
3. Final thoughts on the resume's overall match with the job description in 3 lines.
4. Recommendations on how to add the missing keywords and improve the resume in 3-4 points with examples.
Job Description: {job_description}
Resume: {resume_text}
"""
return generate_response(prompt, "You are an expert ATS resume analyzer.", temperature, max_tokens)
def analyze_resume_without_job_description(resume_text, temperature, max_tokens):
prompt = f"""
Please analyze the following resume without a specific job description. Provide the following details:
1. An overall score out of 10 for the resume.
2. Suggestions for improvements based on the following criteria:
- Impact (quantification, repetition, verb usage, tenses, responsibilities, spelling & consistency)
- Brevity (length, bullet points, filler words)
- Style (buzzwords, dates, contact details, personal pronouns, active voice, consistency)
- Sections (summary, education, skills, unnecessary sections)
3. A cumulative assessment of all the above fields.
4. Recommendations for improving the resume in 3-4 points with examples.
Resume: {resume_text}
"""
return generate_response(prompt, "You are an expert ATS resume analyzer.", temperature, max_tokens)
def analyze_resume(resume_text, job_description, with_job_description, temperature, max_tokens):
if with_job_description:
return analyze_resume_with_job_description(resume_text, job_description, temperature, max_tokens)
else:
return analyze_resume_without_job_description(resume_text, temperature, max_tokens)
def rephrase_text(text, temperature, max_tokens):
prompt = f"""
Please rephrase the following text according to ATS standards, including quantifiable measures and improvements where possible. Maintain precise and concise points which will pass ATS screening:
Original Text: {text}
"""
return generate_response(prompt, "You are an expert in rephrasing content for ATS optimization.", temperature, max_tokens)
def clear_conversation():
return [], None
def generate_cover_letter(resume_text, job_description, temperature, max_tokens):
prompt = f"""
Using the provided resume and job description, create a compelling cover letter. The cover letter should:
1. Be tailored to the specific job and company.
2. Highlight relevant skills and experiences from the resume.
3. Show enthusiasm for the role and company.
4. Be professional and concise (about 250-300 words).
Resume: {resume_text}
Job Description: {job_description}
"""
return generate_response(prompt, "You are an expert in writing tailored cover letters.", temperature, max_tokens)
def generate_interview_questions(job_description, temperature, max_tokens):
prompt = f"""
Based on the following job description, generate a list of 10 probable interview questions. Include a mix of:
1. Role-specific technical questions (if applicable)
2. Behavioral questions related to the required skills
3. Questions about the candidate's experience and background
4. Questions to assess cultural fit
Ensure the questions are tailored to the specific job role and requirements.
Job Description: {job_description}
"""
return generate_response(prompt, "You are an expert in creating relevant interview questions based on job descriptions.", temperature, max_tokens)
with gr.Blocks(css=CSS, theme="Nymbo/Nymbo_Theme") as demo:
gr.HTML(TITLE)
with gr.Tab("Resume Analyzer"):
gr.HTML(RESUME_ANALYZER_INSTRUCTIONS)
with gr.Row():
with gr.Column():
with_job_description = gr.Checkbox(
label="Analyze with Job Description",
value=True,
info="Uncheck this box for a general resume analysis without a specific job description."
)
job_description = gr.Textbox(label="Job Description", lines=5)
resume_file = gr.File(label="Upload Resume (PDF or DOCX)")
with gr.Column():
resume_content = gr.Textbox(label="Parsed Resume Content", lines=10)
analyze_btn = gr.Button("Analyze Resume")
output = gr.Markdown()
with gr.Tab("Content Rephraser"):
text_to_rephrase = gr.Textbox(label="Text to Rephrase", lines=5)
rephrase_btn = gr.Button("Rephrase")
rephrased_output = gr.Markdown()
with gr.Tab("Cover Letter Generator"):
gr.HTML(COVER_LETTER_INSTRUCTIONS)
gr.HTML(COVER_LETTER_DISCLAIMER)
generate_cl_btn = gr.Button("Generate Cover Letter")
cover_letter_output = gr.Markdown()
with gr.Tab("Interview Questions Generator"):
gr.HTML(INTERVIEW_QUESTIONS_INSTRUCTIONS)
gr.HTML(INTERVIEW_QUESTIONS_DISCLAIMER)
interview_job_description = gr.Textbox(label="Job Description for Interview Questions", lines=5)
generate_iq_btn = gr.Button("Generate Interview Questions")
interview_questions_output = gr.Markdown()
with gr.Accordion("βοΈ Parameters", open=False):
temperature = gr.Slider(
minimum=0, maximum=1, step=0.1, value=0.5, label="Temperature",
)
max_tokens = gr.Slider(
minimum=50, maximum=1024, step=1, value=1024, label="Max tokens",
)
def update_job_description_visibility(with_job_description):
return gr.update(visible=with_job_description)
with_job_description.change(
update_job_description_visibility,
inputs=[with_job_description],
outputs=[job_description]
)
def process_resume(file):
if file is not None:
file_type = file.name.split('.')[-1].lower()
if file_type == 'pdf':
return extract_text_from_pdf(file.name)
elif file_type == 'docx':
return extract_text_from_docx(file.name)
return ""
resume_file.upload(process_resume, resume_file, resume_content)
analyze_btn.click(
analyze_resume,
inputs=[resume_content, job_description, with_job_description, temperature, max_tokens],
outputs=[output]
)
rephrase_btn.click(
rephrase_text,
inputs=[text_to_rephrase, temperature, max_tokens],
outputs=[rephrased_output]
)
generate_cl_btn.click(
generate_cover_letter,
inputs=[resume_content, job_description, temperature, max_tokens],
outputs=[cover_letter_output]
)
generate_iq_btn.click(
generate_interview_questions,
inputs=[interview_job_description, temperature, max_tokens],
outputs=[interview_questions_output]
)
gr.HTML(FOOTER_TEXT)
if __name__ == "__main__":
demo.launch() |